conjure 0.1.7 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 58a9a73a25cd4300e2bd4bdf5184a43c824ac548
4
- data.tar.gz: 24a8eed9346681d7010d459d3e5de5a9bb106feb
3
+ metadata.gz: f83195bdf15bdf55eaa8d3ce3bb10ac1dae0caad
4
+ data.tar.gz: 37098f28d23149e7aebb192adf286884e81b77e7
5
5
  SHA512:
6
- metadata.gz: e0e0dadb4bab906cb2ef594d8827ba57f4c553daa09068646945952882dac1a03cdec41feb411a90d62ccef5504f6d7a358ebcd64176b283c646796ec015a670
7
- data.tar.gz: 70e583f8ef4c570da0054ef44038c4028c372226bb962713d09cb14fafb0072344a9db066022bd7d2f061ffc6c038b8fe168e6d389456e1064809fc787c0e522
6
+ metadata.gz: 5200a75af33b8dc94bb5046cbfbd5bcdcb37b3d528006df08728561a2970bc405289b403df10431c71621223a71e5ad1f8bf5bbed4c298416384bf91b7b0e5ab
7
+ data.tar.gz: 792f7d9702ffb3215e078126b5992bacc01799b455e491fa17ce47ba7a31fc9fd7d5ca18ea3ba87a819cd0b448ae6a44d53f18a1b8237582fef0d69b99f8d311
data/History.md CHANGED
@@ -1,3 +1,9 @@
1
+ ### Version 0.1.8
2
+ 2014-1-24
3
+
4
+ * Add `show` command to list deployed instances
5
+ * Fix dockerfile error caused by unset environment variables
6
+
1
7
  ### Version 0.1.7
2
8
  2014-1-14
3
9
 
data/README.md CHANGED
@@ -116,3 +116,9 @@ Open a console on the deployed application.
116
116
  Run a rake task on the deployed application and show the output.
117
117
 
118
118
  conjure rake [ARGUMENTS...]
119
+
120
+ #### Show
121
+
122
+ List the current status of all deployed instances of your command.
123
+
124
+ conjure show
@@ -1,28 +1,31 @@
1
1
  module Conjure
2
2
  class Application
3
- attr_reader :origin_url, :name
3
+ attr_reader :origin
4
4
 
5
- def initialize(options = {})
6
- @origin_url = options[:origin_url] || find_origin_url(options[:path])
7
- @name = find_name(@origin_url) if @origin_url
5
+ def self.find(options = {})
6
+ new(options)
8
7
  end
9
8
 
10
9
  def instances
11
- Instance.find(:application => self)
10
+ Instance.where(:application => self)
12
11
  end
13
12
 
14
13
  def data_sets
15
14
  DataSet.find(:application => self)
16
15
  end
17
16
 
17
+ def name
18
+ match = @origin.match(/\/([^.]+)\.git$/) if @origin
19
+ match[1] if match
20
+ end
21
+
18
22
  private
19
23
 
20
- def find_name(origin_url)
21
- match = origin_url.match(/\/([^.]+)\.git$/)
22
- match[1] if match
24
+ def initialize(options = {})
25
+ @origin = options[:origin] || origin_from_path(options[:path])
23
26
  end
24
27
 
25
- def find_origin_url(path)
28
+ def origin_from_path(path)
26
29
  return unless path
27
30
  remote_info = `cd #{path}; git remote -v |grep origin`
28
31
  match = remote_info.match(/(git@github.com[^ ]+)/)
@@ -50,18 +50,23 @@ module Conjure
50
50
  end
51
51
  end
52
52
 
53
+ desc "show", "Show info on deployed instances"
54
+ def show
55
+ puts View::ApplicationView.new(application).render
56
+ end
57
+
53
58
  default_task :help
54
59
 
55
60
  private
56
61
 
57
62
  def application
58
- @application ||= Application.new(:path => Dir.pwd, :origin_url => options[:origin])
63
+ @application ||= Application.find(:path => Dir.pwd, :origin => options[:origin])
59
64
  end
60
65
 
61
66
  def deployment
62
67
  @deployment ||= Service::RailsDeployment.new({
63
68
  :branch => options[:branch],
64
- :origin => application.origin_url,
69
+ :origin => application.origin,
65
70
  :target => target,
66
71
  :test => options[:test],
67
72
  })
@@ -3,8 +3,12 @@ module Conjure
3
3
  def self.load(root_path)
4
4
  require "ostruct"
5
5
  config_path = File.join root_path, "config", "conjure.yml"
6
- data = YAML.load_file config_path
7
- data["config_path"] = File.dirname config_path
6
+ if File.exists? config_path
7
+ data = YAML.load_file config_path
8
+ data["config_path"] = File.dirname config_path
9
+ else
10
+ data = {}
11
+ end
8
12
  new data
9
13
  end
10
14
 
@@ -1,7 +1,41 @@
1
1
  module Conjure
2
2
  class Instance
3
- def self.find(options = {})
4
- []
3
+ attr_reader :application, :ip_address, :rails_environment
4
+
5
+ def initialize(options)
6
+ @application = options[:application]
7
+ @ip_address = options[:ip_address]
8
+ @rails_environment = options[:rails_environment]
9
+ end
10
+
11
+ def self.where(options = {})
12
+ Collection.new(options)
13
+ end
14
+
15
+ def status
16
+ "running"
17
+ end
18
+
19
+ class Collection
20
+ include Enumerable
21
+
22
+ def initialize(options)
23
+ @application = options[:application]
24
+ end
25
+
26
+ def server
27
+ @server ||= Service::CloudServer.new("#{@application.name}-production") if @application
28
+ end
29
+
30
+ def each(&block)
31
+ if server and server.existing_server
32
+ yield Instance.new(
33
+ :application => @application,
34
+ :rails_environment => "production",
35
+ :ip_address => server.ip_address
36
+ )
37
+ end
38
+ end
5
39
  end
6
40
  end
7
41
  end
data/lib/conjure/log.rb CHANGED
@@ -2,14 +2,25 @@ module Conjure
2
2
  class Log
3
3
  class << self
4
4
  attr_accessor :level
5
+ attr_accessor :capture
6
+ attr_reader :history
5
7
  end
6
8
 
7
9
  def self.info(message)
8
- puts message
10
+ if @capture
11
+ @history ||= ""
12
+ @history << "#{message}\n"
13
+ else
14
+ puts message
15
+ end
9
16
  end
10
17
 
11
18
  def self.debug(message)
12
- puts message if @level == :debug
19
+ info message if @level == :debug
20
+ end
21
+
22
+ def self.clear
23
+ @history = ""
13
24
  end
14
25
  end
15
26
  end
@@ -1,4 +1,10 @@
1
- Application.deploy should become Deployment.create
1
+ TASKS:
2
+ Remove "label" from prepared shell creation
3
+ Alternate way to show per-service progress output
4
+ Log creation and status from each service
5
+ Log name and IP from docker container creation in verbose mode only
6
+ Separate resources vs services
7
+ Deployment.deploy should become Deployment.create
2
8
 
3
9
  Instead of passing DockerHost objects around, pass something that
4
10
  knows how to provision OS shells (possibly from multiple sources).
@@ -56,3 +62,46 @@ stderr) streams ("Console"?). This is what's returned by a rake task
56
62
  or rails console instantiation, to connect it to the user's console,
57
63
  and it can also be returned from a CommandShell to give the user
58
64
  direct access to that as well.
65
+
66
+ "Show" output prototype:
67
+
68
+ # Showing application status (Conjure v1.2.23)
69
+ # Origin git@github.com/brianauton/conjure
70
+ # Authorization OK (using public key)
71
+ #
72
+ # Deployed Instances:
73
+ # Address Environment Branch Revision
74
+ # 192.168.0.1 production master 3FA4D099 (up to date)
75
+ #
76
+ # Data Sets:
77
+ # Name Status Size
78
+ # production-2 active 2GB
79
+ # production-1 archived 2MB
80
+
81
+ # Showing instance status (Conjure v1.2.23)
82
+ # Address 192.168.0.1
83
+ # Environment production
84
+ # Branch master
85
+ # Revision 3FA4D099 (behind by 2 commits)
86
+ # Uptime 2 days, 3 hours, 17 minutes
87
+
88
+ Could have "named" instances ("production-2", user-specified names,
89
+ etc) but "address" is enough to identify instances for now. Should
90
+ guess the specified instance by either ip address, subdomain (when
91
+ supported), or rails_env. Need "deploy" to be a shorthand for either
92
+ "create" or "update" since "deploy staging" is ambiguous if there's
93
+ already a staging instance. Maybe "deploy" should be deprecated?
94
+
95
+ Needs:
96
+ Route all current commands through instances
97
+ Separate commands to "create" and "update" instances
98
+ Support specific env/branch when creating
99
+ Preserve existing env/branch when updating
100
+ Support changing env/branch when updating
101
+ Support default instance params based on addr/env/other info given
102
+ Destroy instances
103
+ Introduce "platforms"
104
+ Deploy to local docker
105
+ Deploy to vagrant (?)
106
+ Progress display
107
+ Used stored docker images for faster deployment
@@ -25,13 +25,11 @@ module Conjure
25
25
  end
26
26
 
27
27
  def ip_address
28
- @server.public_ip_address
28
+ server.public_ip_address
29
29
  end
30
30
 
31
31
  def existing_server
32
- server = connection.servers.find{|s| s.name == @name }
33
- Log.info " [cloud] Using existing server #{@name}" if server
34
- server
32
+ @existing_server ||= connection.servers.find{|s| s.name == @name } if connection
35
33
  end
36
34
 
37
35
  def new_server
@@ -46,7 +44,7 @@ module Conjure
46
44
  end
47
45
 
48
46
  def connection
49
- @connection ||= Fog::Compute.new account.compute_options
47
+ @connection ||= Fog::Compute.new account.compute_options if account
50
48
  end
51
49
 
52
50
  def add_resource_id(options, type)
@@ -141,13 +141,19 @@ module Conjure
141
141
 
142
142
  def dockerfile
143
143
  lines = ["FROM #{base_image_name}"]
144
- lines += @environment.map{|k, v| "ENV #{k} #{v}"} if @environment
144
+ lines += dockerfile_environment_entries
145
145
  lines += @setup_commands.map{|c| "RUN #{c}"}
146
146
  lines << "VOLUME #{@volumes.inspect}" if @volumes.to_a.any?
147
147
  lines << "ENTRYPOINT #{@daemon_command}" if @daemon_command
148
148
  lines.join "\n"
149
149
  end
150
150
 
151
+ def dockerfile_environment_entries
152
+ @environment.to_a.map do |k, v|
153
+ "ENV #{k} #{v}" if v.to_s != ""
154
+ end.compact
155
+ end
156
+
151
157
  def base_image_name
152
158
  @base_image.respond_to?(:installed_image_name) ? @base_image.installed_image_name : @base_image
153
159
  end
@@ -1,3 +1,3 @@
1
1
  module Conjure
2
- VERSION = "0.1.7" unless defined?(VERSION)
2
+ VERSION = "0.1.8" unless defined?(VERSION)
3
3
  end
@@ -0,0 +1,42 @@
1
+ require "conjure"
2
+
3
+ module Conjure
4
+ module View
5
+ class ApplicationView
6
+ def initialize(application)
7
+ @application = application
8
+ @instances = @application.instances
9
+ end
10
+
11
+ def render
12
+ [application_content, instances_content].join "\n\n"
13
+ end
14
+
15
+ private
16
+
17
+ def application_content
18
+ content = ["Showing application status (Conjure v#{Conjure::VERSION})"]
19
+ content << "Origin #{@application.origin}"
20
+ content.join "\n"
21
+ end
22
+
23
+ def instances_content
24
+ content = ["Deployed Instances:"]
25
+ content << instances_table
26
+ content << "(none)" unless @instances.any?
27
+ content.join "\n"
28
+ end
29
+
30
+ def instances_table
31
+ data = @instances.map do |instance|
32
+ {
33
+ "Address" => instance.ip_address,
34
+ "Environment" => instance.rails_environment,
35
+ "Status" => instance.status,
36
+ }
37
+ end
38
+ TableView.new(data).render
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,38 @@
1
+ module Conjure
2
+ module View
3
+ class TableView
4
+ def initialize(data)
5
+ @data = data
6
+ calculate_widths
7
+ end
8
+
9
+ def render
10
+ rows = [@width.map{|col, width| pad_to_width(col, width)}.join(column_separator)]
11
+ rows += @data.map do |row|
12
+ @width.map{|col, width| pad_to_width(row[col], width)}.join(column_separator)
13
+ end
14
+ rows.join("\n")
15
+ end
16
+
17
+ private
18
+
19
+ def column_separator
20
+ " "
21
+ end
22
+
23
+ def pad_to_width(string, width)
24
+ string.to_s + " "*(width - string.to_s.length)
25
+ end
26
+
27
+ def calculate_widths
28
+ @width = {}
29
+ @data.each do |row|
30
+ row.each_pair do |key, value|
31
+ @width[key] ||= key.to_s.length
32
+ @width[key] = [@width[key], value.to_s.length].max
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: conjure
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Auton
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-14 00:00:00.000000000 Z
11
+ date: 2014-01-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fog
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: guard-rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: rspec
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -122,6 +136,8 @@ files:
122
136
  - lib/conjure/service/volume.rb
123
137
  - lib/conjure/target.rb
124
138
  - lib/conjure/version.rb
139
+ - lib/conjure/view/application_view.rb
140
+ - lib/conjure/view/table_view.rb
125
141
  homepage: http://github.com/brianauton/conjure
126
142
  licenses:
127
143
  - MIT