capify-ec2 1.4.1.pre3 → 1.4.2.pre4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Changelog.md CHANGED
@@ -1,3 +1,15 @@
1
+ ## 1.4.2.pre4 (Mar 28, 2013)
2
+
3
+ Features:
4
+
5
+ - Added the ability to run multiple healthchecks per role by specifying an array of them when defining the role.
6
+ - Improved readability of output from rolling deployments.
7
+
8
+ Bugfixes:
9
+
10
+ - Error handling improved when working with the 'ec2:ssh' command.
11
+
12
+
1
13
  ## 1.4.1.pre3 (Mar 1, 2013)
2
14
 
3
15
  Features:
data/capify-ec2.gemspec CHANGED
@@ -6,7 +6,7 @@ Gem::Specification.new do |s|
6
6
  s.name = "capify-ec2"
7
7
  s.version = Capify::Ec2::VERSION
8
8
  s.platform = Gem::Platform::RUBY
9
- s.authors = ["Noah Cantor", "Siddharth Dawara"]
9
+ s.authors = ["Noah Cantor", "Siddharth Dawara", "Jon Spalding", "Ryan Conway"]
10
10
  s.email = ["capify-ec2@forwardtechnology.co.uk"]
11
11
  s.homepage = "http://github.com/forward/capify-ec2"
12
12
  s.summary = %q{Capify-EC2 is used to generate Capistrano namespaces and tasks from Amazon EC2 instance tags, dynamically building the list of servers to be deployed to.}
data/lib/capify-ec2.rb CHANGED
@@ -45,6 +45,11 @@ class CapifyEc2
45
45
  end
46
46
 
47
47
  def display_instances
48
+ unless desired_instances and desired_instances.any?
49
+ puts "[Capify-EC2] No instances were found using your 'ec2.yml' configuration.".red.bold
50
+ return
51
+ end
52
+
48
53
  # Set minimum widths for the variable length instance attributes.
49
54
  column_widths = { :name_min => 4, :type_min => 4, :dns_min => 5, :roles_min => 5, :options_min => 6 }
50
55
 
@@ -216,8 +221,10 @@ class CapifyEc2
216
221
  def instance_health_by_url(dns, port, path, expected_response, options = {})
217
222
  protocol = options[:https] ? 'https://' : 'http://'
218
223
  uri = URI("#{protocol}#{dns}:#{port}#{path}")
219
- http = Net::HTTP.new(uri.host, uri.port)
220
224
 
225
+ puts "[Capify-EC2] Checking '#{uri}' for the content '#{expected_response}'..."
226
+
227
+ http = Net::HTTP.new(uri.host, uri.port)
221
228
  result = nil
222
229
 
223
230
  begin
@@ -39,13 +39,19 @@ Capistrano::Configuration.instance(:must_exist).load do
39
39
  desc "Allows ssh to instance by id. cap ssh <INSTANCE NAME>"
40
40
  task :ssh do
41
41
  server = variables[:logger].instance_variable_get("@options")[:actions][1]
42
- instance = numeric?(server) ? capify_ec2.desired_instances[server.to_i] : capify_ec2.get_instance_by_name(server)
43
-
44
- if instance and instance.contact_point then
45
- port = ssh_options[:port] || 22
46
- command = "ssh -p #{port} #{user}@#{instance.contact_point}"
47
- puts "Running `#{command}`"
48
- exec(command)
42
+
43
+ if server
44
+ instance = numeric?(server) ? capify_ec2.desired_instances[server.to_i] : capify_ec2.get_instance_by_name(server)
45
+
46
+ if instance and instance.contact_point then
47
+ port = ssh_options[:port] || 22
48
+ command = "ssh -p #{port} #{user}@#{instance.contact_point}"
49
+ puts "Running `#{command}`"
50
+ exec(command)
51
+ else
52
+ puts "[Capify-EC2] Error: No instances were found with instance number '#{server}'.".bold.red
53
+ exit 1
54
+ end
49
55
  else
50
56
  puts "[Capify-EC2] Error: You did not specify the instance number, which can be found via the 'ec2:status' command as follows:".bold.red
51
57
  top.ec2.status
@@ -99,26 +105,32 @@ Capistrano::Configuration.instance(:must_exist).load do
99
105
  load_balancer_to_reregister = capify_ec2.deregister_instance_from_elb_by_dns(server_dns) if is_load_balanced
100
106
 
101
107
  # Call the standard 'cap deploy' task with our redefined role containing a single server.
102
- top.deploy.default
108
+ # top.deploy.default
103
109
 
104
110
  server_roles.each do |a_role|
105
111
 
106
- # If a healthcheck is defined for this role, run it.
112
+ # If healthcheck(s) are defined for this role, run them.
107
113
  if all_roles[a_role][:options][:healthcheck]
108
- options = {}
109
- options[:https] = all_roles[a_role][:options][:healthcheck][:https] ||= false
110
- options[:timeout] = all_roles[a_role][:options][:healthcheck][:timeout] ||= 60
111
- puts "[Capify-EC2] Starting healthcheck for role '#{a_role}'..."
112
- healthcheck = capify_ec2.instance_health_by_url( server_dns,
113
- all_roles[a_role][:options][:healthcheck][:port],
114
- all_roles[a_role][:options][:healthcheck][:path],
115
- all_roles[a_role][:options][:healthcheck][:result],
116
- options )
117
- if healthcheck
118
- puts "[Capify-EC2] Healthcheck for role '#{a_role}' successful.".green.bold
119
- else
120
- puts "[Capify-EC2] Healthcheck for role '#{a_role}' failed!".red.bold
121
- raise CapifyEC2RollingDeployError.new("Healthcheck timeout exceeded", server_dns)
114
+ healthchecks_for_role = [ all_roles[a_role][:options][:healthcheck] ].flatten
115
+
116
+ puts "[Capify-EC2] Starting #{pluralise(healthchecks_for_role.size, 'healthcheck')} for role '#{a_role}'..."
117
+
118
+ healthchecks_for_role.each_with_index do |healthcheck_for_role, i|
119
+ options = {}
120
+ options[:https] = healthcheck_for_role[:https] ||= false
121
+ options[:timeout] = healthcheck_for_role[:timeout] ||= 60
122
+
123
+ healthcheck = capify_ec2.instance_health_by_url( server_dns,
124
+ healthcheck_for_role[:port],
125
+ healthcheck_for_role[:path],
126
+ healthcheck_for_role[:result],
127
+ options )
128
+ if healthcheck
129
+ puts "[Capify-EC2] Healthcheck #{i+1} of #{healthchecks_for_role.size} for role '#{a_role}' successful.".green.bold
130
+ else
131
+ puts "[Capify-EC2] Healthcheck #{i+1} of #{healthchecks_for_role.size} for role '#{a_role}' failed!".red.bold
132
+ raise CapifyEC2RollingDeployError.new("Healthcheck timeout exceeded", server_dns)
133
+ end
122
134
  end
123
135
  end
124
136
 
@@ -142,11 +154,13 @@ Capistrano::Configuration.instance(:must_exist).load do
142
154
  failed_deploys << e.dns
143
155
  puts "[Capify-EC2]"
144
156
  puts "[Capify-EC2] Deployment aborted due to error: #{e}!".red.bold
157
+ puts "[Capify-EC2]" if load_balancer_to_reregister
145
158
  puts "[Capify-EC2] Note: Instance '#{instance_dns_with_name_tag(e.dns)}' was removed from the ELB '#{load_balancer_to_reregister.id}' and should be manually checked and reregistered.".red.bold if load_balancer_to_reregister
146
159
  rescue => e
147
160
  failed_deploys << roles.values.first.servers.first.host
148
161
  puts "[Capify-EC2]"
149
162
  puts "[Capify-EC2] Deployment aborted due to error: #{e}!".red.bold
163
+ puts "[Capify-EC2]" if load_balancer_to_reregister
150
164
  puts "[Capify-EC2] Note: Instance '#{instance_dns_with_name_tag(roles.values.first.servers.first.host)}' was removed from the ELB '#{load_balancer_to_reregister.id}' and should be manually checked and reregistered.".red.bold if load_balancer_to_reregister
151
165
  else
152
166
  puts "[Capify-EC2]"
@@ -265,6 +279,16 @@ Capistrano::Configuration.instance(:must_exist).load do
265
279
  def numeric?(object)
266
280
  true if Float(object) rescue false
267
281
  end
282
+
283
+ def pluralise(n, singular, plural=nil)
284
+ if n == 1
285
+ "#{singular}"
286
+ elsif plural
287
+ "#{plural}"
288
+ else
289
+ "#{singular}s"
290
+ end
291
+ end
268
292
 
269
293
  def remove_default_roles
270
294
  roles.reject! { true }
@@ -1,6 +1,6 @@
1
1
  module Capify
2
2
  module Ec2
3
- VERSION = "1.4.1.pre3"
3
+ VERSION = "1.4.2.pre4"
4
4
  end
5
5
  end
6
6
 
data/readme.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  Capify-EC2 is used to generate Capistrano namespaces and tasks from Amazon EC2 instance tags, dynamically building the list of servers to be deployed to.
4
4
 
5
+ ### Pre-release
6
+
7
+ This pre-release version of Capify-EC2 is currently in public testing, please open a Github issue if you are experiencing difficulties.
8
+
5
9
 
6
10
  ### Installation
7
11
 
@@ -356,6 +360,23 @@ ec2_roles :name => "web",
356
360
 
357
361
  Sets a 10 second timeout, and performs the health check over HTTPS.
358
362
 
363
+ You can run multiple different healthchecks for a role by specifying the healthcheck as an array instead:
364
+
365
+ ```ruby
366
+ ec2_roles :name => "web",
367
+ :variables => {
368
+ :healthcheck => [{
369
+ :path => '/status',
370
+ :port => 80,
371
+ :result => 'OK'
372
+ }, {
373
+ :path => '/other_status',
374
+ :port => 81,
375
+ :result => 'OK'
376
+ }]
377
+ }
378
+ ```
379
+
359
380
  ##### Usage with Elastic Load Balancers
360
381
 
361
382
  You can have Capify-EC2 automatically deregister and reregister an instance from whichever ELB it is associated with, before and after the deployment, by setting ':load_balanced' to 'true' in the role definition, for example:
metadata CHANGED
@@ -1,24 +1,26 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capify-ec2
3
3
  version: !ruby/object:Gem::Version
4
- hash: 382858687
4
+ hash: 967365859
5
5
  prerelease: 6
6
6
  segments:
7
7
  - 1
8
8
  - 4
9
- - 1
9
+ - 2
10
10
  - pre
11
- - 3
12
- version: 1.4.1.pre3
11
+ - 4
12
+ version: 1.4.2.pre4
13
13
  platform: ruby
14
14
  authors:
15
15
  - Noah Cantor
16
16
  - Siddharth Dawara
17
+ - Jon Spalding
18
+ - Ryan Conway
17
19
  autorequire:
18
20
  bindir: bin
19
21
  cert_chain: []
20
22
 
21
- date: 2013-03-01 00:00:00 Z
23
+ date: 2013-03-28 00:00:00 Z
22
24
  dependencies:
23
25
  - !ruby/object:Gem::Dependency
24
26
  name: fog