capify-ec2 1.5.3 → 1.6.0
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/.gitignore +2 -0
- data/Changelog.md +11 -0
- data/lib/capify-ec2.rb +69 -2
- data/lib/capify-ec2/capistrano.rb +5 -0
- data/lib/capify-ec2/version.rb +1 -1
- data/readme.md +32 -5
- metadata +62 -76
data/Changelog.md
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
## 1.6.0 (Aug 26, 2014)
|
2
|
+
|
3
|
+
Features:
|
4
|
+
|
5
|
+
- Added a new 'ec2:elbs' command which allows you to list ELBs and the instances registered to them (thanks to stevewoolley).
|
6
|
+
- Added the ability to perform post deploy healthchecks using POST requests rather than just GET (thanks alangalvino).
|
7
|
+
|
8
|
+
Bugfixes:
|
9
|
+
|
10
|
+
- Fixed load balancer registration / de-registering within EC2 VPC (thanks davie).
|
11
|
+
|
1
12
|
## 1.5.3 (Nov 15, 2013)
|
2
13
|
|
3
14
|
Bugfixes:
|
data/lib/capify-ec2.rb
CHANGED
@@ -40,6 +40,7 @@ class CapifyEc2
|
|
40
40
|
regions = determine_regions()
|
41
41
|
|
42
42
|
@instances = []
|
43
|
+
@elbs = elb.load_balancers
|
43
44
|
|
44
45
|
regions.each do |region|
|
45
46
|
begin
|
@@ -130,6 +131,68 @@ class CapifyEc2
|
|
130
131
|
end
|
131
132
|
end
|
132
133
|
|
134
|
+
def display_elbs
|
135
|
+
unless @elbs.any?
|
136
|
+
puts "[Capify-EC2] No elastic load balancers were found using your 'ec2.yml' configuration.".red.bold
|
137
|
+
return
|
138
|
+
end
|
139
|
+
puts "Elastic Load Balancers".bold
|
140
|
+
puts "#{@ec2_config[:aws_project_tag].bold}: #{@ec2_config[:project_tags].join(', ')}." if @ec2_config[:project_tags].any?
|
141
|
+
|
142
|
+
# Set minimum widths for the variable length lb attributes.
|
143
|
+
column_widths = { :id_min => 4, :dns_min => 4, :zone_min => 5}
|
144
|
+
|
145
|
+
# Find the longest attribute across all instances, to format the columns properly.
|
146
|
+
column_widths[:id] = @elbs.map{|i| i.id.to_s.ljust( column_widths[:id_min] ) || ' ' * column_widths[:id_min]}.max_by(&:length).length
|
147
|
+
column_widths[:dns] = @elbs.map{|i| i.dns_name || ' ' * column_widths[:dns_min]}.max_by(&:length).length
|
148
|
+
column_widths[:zone] = @elbs.map{|i| i.availability_zones.join(",").to_s.ljust( column_widths[:zone_min] ) || ' ' * column_widths[:zone_min]}.max_by(&:length).length
|
149
|
+
|
150
|
+
# Title row.
|
151
|
+
status_output = []
|
152
|
+
status_output << 'ID' .ljust( column_widths[:id] ).bold
|
153
|
+
status_output << 'DNS' .ljust( column_widths[:dns] ).bold
|
154
|
+
status_output << 'Zone' .ljust( column_widths[:zone] ).bold
|
155
|
+
puts status_output.join(" ")
|
156
|
+
|
157
|
+
elbs_found_for_project = false
|
158
|
+
|
159
|
+
@elbs.each_with_index do |lb, i|
|
160
|
+
|
161
|
+
status_output = []
|
162
|
+
sub_output = []
|
163
|
+
lb.instances.each do |instance|
|
164
|
+
first_match = @instances.select {|x| instance.include?(x.id)}.first
|
165
|
+
|
166
|
+
# Skip any instances which don't match the current Project tag, if set.
|
167
|
+
if @ec2_config[:project_tags].any?
|
168
|
+
break unless @ec2_config[:project_tags].include?(first_match.tags[ @ec2_config[:aws_project_tag] ])
|
169
|
+
end
|
170
|
+
|
171
|
+
elbs_found_for_project = true
|
172
|
+
|
173
|
+
instance_row = []
|
174
|
+
instance_row << " ".ljust( column_widths[:id] ) # indent the length of the id column
|
175
|
+
instance_row << "+"
|
176
|
+
instance_row << (instance || '') .ljust( 10 ).red
|
177
|
+
instance_row << instance_health(lb, first_match) .yellow
|
178
|
+
instance_row << (first_match.name || '' ) .cyan
|
179
|
+
sub_output << instance_row.join(" ")
|
180
|
+
end
|
181
|
+
|
182
|
+
# Only display the ELB if instances matching the current Project tag were found.
|
183
|
+
if sub_output.any?
|
184
|
+
status_output << (lb.id || '') .ljust( column_widths[:id] ).green
|
185
|
+
status_output << lb.dns_name .ljust( column_widths[:dns] ).blue.bold
|
186
|
+
status_output << lb.availability_zones.join(",") .ljust( column_widths[:zone] ).magenta
|
187
|
+
|
188
|
+
puts status_output.join(" ")
|
189
|
+
puts sub_output.join("\n")
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
puts "Capify-EC2] No elastic load balancers were found containing instances tagged with this project.".red.bold unless elbs_found_for_project
|
194
|
+
end
|
195
|
+
|
133
196
|
def server_names
|
134
197
|
desired_instances.map {|instance| instance.name}
|
135
198
|
end
|
@@ -161,7 +224,7 @@ class CapifyEc2
|
|
161
224
|
end
|
162
225
|
|
163
226
|
def get_instance_by_dns(dns)
|
164
|
-
desired_instances.select {|instance| instance.
|
227
|
+
desired_instances.select {|instance| instance.contact_point == dns}.first
|
165
228
|
end
|
166
229
|
|
167
230
|
def instance_health(load_balancer, instance)
|
@@ -297,7 +360,11 @@ class CapifyEc2
|
|
297
360
|
begin
|
298
361
|
Timeout::timeout(options[:timeout]) do
|
299
362
|
begin
|
300
|
-
|
363
|
+
if(options[:via].to_s.downcase == "post")
|
364
|
+
result = http.post(uri.path, options[:data])
|
365
|
+
else
|
366
|
+
result = http.get(uri.path)
|
367
|
+
end
|
301
368
|
raise "Server responded with '#{result.code}: #{result.body}', expected '#{expected_response}'" unless response_matches_expected?(result.body, expected_response)
|
302
369
|
rescue => e
|
303
370
|
puts "[Capify-EC2] Unexpected response: #{e}..."
|
@@ -14,6 +14,11 @@ Capistrano::Configuration.instance(:must_exist).load do
|
|
14
14
|
capify_ec2.display_instances
|
15
15
|
end
|
16
16
|
|
17
|
+
desc "Prints out all ec2 load balancers"
|
18
|
+
task :elbs do
|
19
|
+
capify_ec2.display_elbs
|
20
|
+
end
|
21
|
+
|
17
22
|
desc "Deregisters instance from its ELB"
|
18
23
|
task :deregister_instance do
|
19
24
|
instance_name = variables[:logger].instance_variable_get("@options")[:actions].first
|
data/lib/capify-ec2/version.rb
CHANGED
data/readme.md
CHANGED
@@ -2,7 +2,7 @@
|
|
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
|
-
__Note__: Capistrano 3 is completely incompatible with Capistrano 2, and therefore Capify-EC2 will not function with Capistrano 3.
|
5
|
+
__Note__: Capistrano 3 is completely incompatible with Capistrano 2, and therefore Capify-EC2 will not function with Capistrano 3. If you are using Capistrano 3, you can use [Cap-EC2](https://github.com/forward3d/cap-ec2), however note that the configuration (`config/ec2.yml`) is not compatible between Capify-EC2 and Cap-EC2.
|
6
6
|
|
7
7
|
|
8
8
|
|
@@ -149,7 +149,7 @@ In our examples, imagine that you have three servers on EC2 named and tagged as
|
|
149
149
|
You need to add a call to `ec2_roles` in your `deploy.rb`, like so:
|
150
150
|
|
151
151
|
```ruby
|
152
|
-
ec2_roles
|
152
|
+
ec2_roles :name => :web
|
153
153
|
```
|
154
154
|
|
155
155
|
This will generate the following tasks:
|
@@ -172,7 +172,7 @@ end
|
|
172
172
|
Note that there are no tasks created for 'server-2', as it does not have the role 'web'. If we were to change the `ec2_roles` definition in your `deploy.rb` to the following:
|
173
173
|
|
174
174
|
```ruby
|
175
|
-
ec2_roles
|
175
|
+
ec2_roles :name => :db
|
176
176
|
```
|
177
177
|
|
178
178
|
Then we will instead see the following tasks generated:
|
@@ -237,7 +237,7 @@ end
|
|
237
237
|
You can define custom variables which will be set as standard Capistrano variables within the scope of the role you define them one, for example:
|
238
238
|
|
239
239
|
```ruby
|
240
|
-
ec2_roles
|
240
|
+
ec2_roles :name=>"web", :variables => {:rails_env => 'staging'}
|
241
241
|
```
|
242
242
|
|
243
243
|
In this case, instances that that are tagged with the 'web' role will have the custom variable 'rails_env' available to them in any tasks they use. The following tasks would be generated:
|
@@ -317,7 +317,7 @@ end
|
|
317
317
|
As well as defining Options at an instance level via EC2 tags, you can define an Option in your `deploy.rb` at the same time as defining the role, as follows:
|
318
318
|
|
319
319
|
```ruby
|
320
|
-
ec2_roles
|
320
|
+
ec2_roles :name=>"web", :options=>{:worker=>"server-C"}
|
321
321
|
```
|
322
322
|
|
323
323
|
In this case, you set the value of `:worker` equal to the instance name you want to be a worker. The task definition remains the same:
|
@@ -490,6 +490,23 @@ ec2_roles :name => "web",
|
|
490
490
|
}
|
491
491
|
```
|
492
492
|
|
493
|
+
By default, healthchecks are made using GET requests, but you make can use POST instead by specifying `:via` as either `:post` or `'POST'` and adding ':data' attributes, as follows:
|
494
|
+
|
495
|
+
```ruby
|
496
|
+
ec2_roles :name => "web",
|
497
|
+
:variables => {
|
498
|
+
:healthcheck => {
|
499
|
+
:path => '/status',
|
500
|
+
:port => 80,
|
501
|
+
:result => '{ json_response: as_string }'
|
502
|
+
:https => true,
|
503
|
+
:timeout => 10,
|
504
|
+
:via => :post,
|
505
|
+
:data => '{ json_request: as_string }'
|
506
|
+
}
|
507
|
+
}
|
508
|
+
```
|
509
|
+
|
493
510
|
##### Usage with Elastic Load Balancers
|
494
511
|
|
495
512
|
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:
|
@@ -534,6 +551,16 @@ cap ec2:status
|
|
534
551
|
```
|
535
552
|
|
536
553
|
|
554
|
+
#### Viewing ELBs
|
555
|
+
|
556
|
+
The following command will generate a listing of all ELBs with instances that match your configuration (projects):
|
557
|
+
|
558
|
+
```ruby
|
559
|
+
cap ec2:elbs
|
560
|
+
```
|
561
|
+
|
562
|
+
Note: if no `project` tag is specified in your `ec2.yml` configuration, then all ELBs and their associated instances are shown when using this command.
|
563
|
+
|
537
564
|
|
538
565
|
#### Managing Load Balancers
|
539
566
|
|
metadata
CHANGED
@@ -1,15 +1,10 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: capify-ec2
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.6.0
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 1
|
8
|
-
- 5
|
9
|
-
- 3
|
10
|
-
version: 1.5.3
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Noah Cantor
|
14
9
|
- Siddharth Dawara
|
15
10
|
- Jon Spalding
|
@@ -17,65 +12,64 @@ authors:
|
|
17
12
|
autorequire:
|
18
13
|
bindir: bin
|
19
14
|
cert_chain: []
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
- !ruby/object:Gem::Dependency
|
15
|
+
date: 2014-08-26 00:00:00.000000000 Z
|
16
|
+
dependencies:
|
17
|
+
- !ruby/object:Gem::Dependency
|
24
18
|
name: fog
|
25
|
-
|
26
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
+
requirement: !ruby/object:Gem::Requirement
|
27
20
|
none: false
|
28
|
-
requirements:
|
29
|
-
- -
|
30
|
-
- !ruby/object:Gem::Version
|
31
|
-
hash: 39
|
32
|
-
segments:
|
33
|
-
- 1
|
34
|
-
- 12
|
35
|
-
- 0
|
21
|
+
requirements:
|
22
|
+
- - ! '>='
|
23
|
+
- !ruby/object:Gem::Version
|
36
24
|
version: 1.12.0
|
37
25
|
type: :runtime
|
38
|
-
version_requirements: *id001
|
39
|
-
- !ruby/object:Gem::Dependency
|
40
|
-
name: colored
|
41
26
|
prerelease: false
|
42
|
-
|
27
|
+
version_requirements: !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 1.12.0
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: colored
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
43
36
|
none: false
|
44
|
-
requirements:
|
45
|
-
- -
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
|
48
|
-
segments:
|
49
|
-
- 1
|
50
|
-
- 2
|
51
|
-
version: "1.2"
|
37
|
+
requirements:
|
38
|
+
- - '='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.2'
|
52
41
|
type: :runtime
|
53
|
-
version_requirements: *id002
|
54
|
-
- !ruby/object:Gem::Dependency
|
55
|
-
name: capistrano
|
56
42
|
prerelease: false
|
57
|
-
|
43
|
+
version_requirements: !ruby/object:Gem::Requirement
|
58
44
|
none: false
|
59
|
-
requirements:
|
45
|
+
requirements:
|
46
|
+
- - '='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '1.2'
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: capistrano
|
51
|
+
requirement: !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
60
54
|
- - ~>
|
61
|
-
- !ruby/object:Gem::Version
|
62
|
-
|
63
|
-
segments:
|
64
|
-
- 2
|
65
|
-
- 14
|
66
|
-
version: "2.14"
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '2.14'
|
67
57
|
type: :runtime
|
68
|
-
|
69
|
-
|
70
|
-
|
58
|
+
prerelease: false
|
59
|
+
version_requirements: !ruby/object:Gem::Requirement
|
60
|
+
none: false
|
61
|
+
requirements:
|
62
|
+
- - ~>
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '2.14'
|
65
|
+
description: Capify-EC2 is used to generate Capistrano namespaces and tasks from Amazon
|
66
|
+
EC2 instance tags, dynamically building the list of servers to be deployed to.
|
67
|
+
email:
|
71
68
|
- capify-ec2@forwardtechnology.co.uk
|
72
69
|
executables: []
|
73
|
-
|
74
70
|
extensions: []
|
75
|
-
|
76
71
|
extra_rdoc_files: []
|
77
|
-
|
78
|
-
files:
|
72
|
+
files:
|
79
73
|
- .gitignore
|
80
74
|
- Changelog.md
|
81
75
|
- Gemfile
|
@@ -88,37 +82,29 @@ files:
|
|
88
82
|
- lib/capify-ec2/version.rb
|
89
83
|
- readme.md
|
90
84
|
homepage: http://github.com/forward/capify-ec2
|
91
|
-
licenses:
|
85
|
+
licenses:
|
92
86
|
- MIT
|
93
87
|
post_install_message:
|
94
88
|
rdoc_options: []
|
95
|
-
|
96
|
-
require_paths:
|
89
|
+
require_paths:
|
97
90
|
- lib
|
98
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
91
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
99
92
|
none: false
|
100
|
-
requirements:
|
101
|
-
- -
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
|
104
|
-
|
105
|
-
- 0
|
106
|
-
version: "0"
|
107
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ! '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
98
|
none: false
|
109
|
-
requirements:
|
110
|
-
- -
|
111
|
-
- !ruby/object:Gem::Version
|
112
|
-
|
113
|
-
segments:
|
114
|
-
- 0
|
115
|
-
version: "0"
|
99
|
+
requirements:
|
100
|
+
- - ! '>='
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
116
103
|
requirements: []
|
117
|
-
|
118
104
|
rubyforge_project: capify-ec2
|
119
|
-
rubygems_version: 1.8.
|
105
|
+
rubygems_version: 1.8.23
|
120
106
|
signing_key:
|
121
107
|
specification_version: 3
|
122
|
-
summary: Capify-EC2 is used to generate Capistrano namespaces and tasks from Amazon
|
108
|
+
summary: Capify-EC2 is used to generate Capistrano namespaces and tasks from Amazon
|
109
|
+
EC2 instance tags, dynamically building the list of servers to be deployed to.
|
123
110
|
test_files: []
|
124
|
-
|