capify-ec2 1.1.13 → 1.1.14.pre.1
Sign up to get free protection for your applications and to get access to all the features.
- data/{Changelog → Changelog.md} +23 -1
- data/LICENSE +20 -0
- data/lib/capify-ec2.rb +4 -4
- data/lib/capify-ec2/capistrano.rb +59 -59
- data/lib/capify-ec2/version.rb +1 -1
- data/readme.md +41 -22
- metadata +15 -10
data/{Changelog → Changelog.md}
RENAMED
@@ -1,3 +1,25 @@
|
|
1
|
+
## 1.1.14 (Aug 24, 2011)
|
2
|
+
|
3
|
+
Bugfixes:
|
4
|
+
|
5
|
+
- Fixed chaining of tasks
|
6
|
+
|
7
|
+
Features:
|
8
|
+
|
9
|
+
- Moved the following to ec2 namespace to make it clearer what's part of the gem
|
10
|
+
- status (formerly ec2_status)
|
11
|
+
- register_instance
|
12
|
+
- deregister_instance
|
13
|
+
- date
|
14
|
+
- server_names
|
15
|
+
|
16
|
+
|
17
|
+
## 1.1.13 (Aug 10, 2011)
|
18
|
+
|
19
|
+
Bugfixes:
|
20
|
+
|
21
|
+
- Obscure bug fixed. Multiple roles where some instances weren't in all roles would throw an error if you tried to tell a task to only fire when particular roles were deployed to. This bug only fired if you performed your action on a single instance (cap server deploy).
|
22
|
+
|
1
23
|
## 1.1.12 (Aug 09, 2011)
|
2
24
|
|
3
25
|
Features:
|
@@ -11,7 +33,7 @@ Features:
|
|
11
33
|
- Fix gem dependencies for cap ec2_status
|
12
34
|
- Allows registering and deregistering of instances with an ELB
|
13
35
|
- Servers can have Role or Roles on ec2
|
14
|
-
|
36
|
+
|
15
37
|
|
16
38
|
Bugfixes:
|
17
39
|
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Forward
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/lib/capify-ec2.rb
CHANGED
@@ -53,8 +53,8 @@ class CapifyEc2
|
|
53
53
|
elb.describe_instance_health(load_balancer.id, instance.id).body['DescribeInstanceHealthResult']['InstanceStates'][0]['State']
|
54
54
|
end
|
55
55
|
|
56
|
-
def self.get_instances_by_role(role
|
57
|
-
filter_instances_by_role(running_instances, role
|
56
|
+
def self.get_instances_by_role(role)
|
57
|
+
filter_instances_by_role(running_instances, role)
|
58
58
|
end
|
59
59
|
|
60
60
|
def self.get_instances_by_region(role, region)
|
@@ -63,13 +63,13 @@ class CapifyEc2
|
|
63
63
|
filter_instances_by_role(region_instances,role)
|
64
64
|
end
|
65
65
|
|
66
|
-
def self.filter_instances_by_role(instances, role
|
66
|
+
def self.filter_instances_by_role(instances, role)
|
67
67
|
selected_instances = instances.select do |instance|
|
68
68
|
server_roles = [instance.case_insensitive_tag("Role")] || []
|
69
69
|
if (roles_tag = instance.case_insensitive_tag("Roles"))
|
70
70
|
server_roles += roles_tag.split(/\s*,\s*/)
|
71
71
|
end
|
72
|
-
|
72
|
+
server_roles.member?(role.to_s)
|
73
73
|
end
|
74
74
|
end
|
75
75
|
|
@@ -2,34 +2,82 @@ require File.join(File.dirname(__FILE__), '../capify-ec2')
|
|
2
2
|
require 'colored'
|
3
3
|
|
4
4
|
Capistrano::Configuration.instance(:must_exist).load do
|
5
|
-
|
6
|
-
|
5
|
+
namespace :ec2 do
|
6
|
+
desc "Prints out all ec2 instances. index, name, instance_id, size, dns_name, region, tags"
|
7
|
+
task :status do
|
8
|
+
CapifyEc2.running_instances.each_with_index do |instance, i|
|
9
|
+
puts sprintf "%-11s: %-40s %-20s %-20s %-62s %-20s (%s)",
|
10
|
+
i.to_s.magenta, instance.case_insensitive_tag("Name"), instance.id.red, instance.flavor_id.cyan,
|
11
|
+
instance.dns_name.blue, instance.availability_zone.green, instance.roles.join(", ").yellow
|
12
|
+
end
|
13
|
+
end
|
14
|
+
desc "Deregisters instance from its ELB"
|
15
|
+
task :deregister_instance do
|
16
|
+
instance_name = variables[:logger].instance_variable_get("@options")[:actions].first
|
17
|
+
CapifyEc2.deregister_instance_from_elb(instance_name)
|
18
|
+
end
|
19
|
+
|
20
|
+
desc "Registers an instance with an ELB."
|
21
|
+
task :register_instance do
|
22
|
+
instance_name = variables[:logger].instance_variable_get("@options")[:actions].first
|
23
|
+
load_balancer_name = variables[:logger].instance_variable_get("@options")[:vars][:loadbalancer]
|
24
|
+
CapifyEc2.register_instance_in_elb(instance_name, load_balancer_name)
|
25
|
+
end
|
26
|
+
|
27
|
+
task :date do
|
28
|
+
run "date"
|
29
|
+
end
|
30
|
+
|
31
|
+
desc "Prints list of ec2 server names"
|
32
|
+
task :server_names do
|
33
|
+
puts CapifyEc2.server_names.sort
|
34
|
+
end
|
7
35
|
|
8
|
-
|
36
|
+
desc "Allows ssh to instance by id. cap ssh <INSTANCE NAME>"
|
37
|
+
task :ssh do
|
38
|
+
server = variables[:logger].instance_variable_get("@options")[:actions][1]
|
39
|
+
instance = numeric?(server) ? CapifyEc2.running_instances[server.to_i] : CapifyEc2.get_instance_by_name(server)
|
40
|
+
port = ssh_options[:port] || 22
|
41
|
+
command = "ssh -p #{port} #{user}@#{instance.dns_name}"
|
42
|
+
puts "Running `#{command}`"
|
43
|
+
system(command)
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
namespace :deploy do
|
49
|
+
before "deploy", "ec2:deregister_instance"
|
50
|
+
after "deploy", "ec2:register_instance"
|
51
|
+
after "deploy:rollback", "ec2:register_instance"
|
52
|
+
end
|
53
|
+
|
54
|
+
def ec2_roles(*roles)
|
55
|
+
server_name = variables[:logger].instance_variable_get("@options")[:actions].first unless variables[:logger].instance_variable_get("@options")[:actions][1].nil?
|
56
|
+
named_instance = CapifyEc2.get_instance_by_name(server_name)
|
9
57
|
task named_instance.name.to_sym do
|
10
58
|
named_instance.roles.each do |role|
|
11
59
|
define_role({:name => role, :options => {}}, named_instance)
|
12
60
|
end
|
13
61
|
end unless named_instance.nil?
|
14
|
-
roles.each {|role| ec2_role(role
|
62
|
+
roles.each {|role| ec2_role(role)}
|
15
63
|
end
|
16
64
|
|
17
|
-
def ec2_role(role_name_or_hash
|
65
|
+
def ec2_role(role_name_or_hash)
|
18
66
|
role = role_name_or_hash.is_a?(Hash) ? role_name_or_hash : {:name => role_name_or_hash,:options => {}}
|
19
|
-
instances = CapifyEc2.get_instances_by_role(role[:name]
|
67
|
+
instances = CapifyEc2.get_instances_by_role(role[:name])
|
20
68
|
if role[:options].delete(:default)
|
21
69
|
instances.each do |instance|
|
22
70
|
define_role(role, instance)
|
23
71
|
end
|
24
|
-
end
|
25
|
-
|
72
|
+
end
|
73
|
+
define_role_roles(role, instances)
|
74
|
+
|
26
75
|
regions = CapifyEc2.ec2_config[:aws_params][:regions] || [CapifyEc2.ec2_config[:aws_params][:region]]
|
27
76
|
regions.each do |region|
|
28
77
|
define_regions(region, role)
|
29
78
|
end unless regions.nil?
|
30
|
-
|
79
|
+
|
31
80
|
define_instance_roles(role, instances)
|
32
|
-
define_role_roles(role, instances)
|
33
81
|
end
|
34
82
|
|
35
83
|
def define_regions(region, role)
|
@@ -68,56 +116,8 @@ Capistrano::Configuration.instance(:must_exist).load do
|
|
68
116
|
role role[:name].to_sym, instance.dns_name
|
69
117
|
end
|
70
118
|
end
|
71
|
-
|
119
|
+
|
72
120
|
def numeric?(object)
|
73
121
|
true if Float(object) rescue false
|
74
122
|
end
|
75
|
-
|
76
|
-
desc "Deregisters instance from its ELB"
|
77
|
-
task :deregister_instance do
|
78
|
-
servers = variables[:logger].instance_variable_get("@options")[:actions].first
|
79
|
-
CapifyEc2.deregister_instance_from_elb(servers)
|
80
|
-
end
|
81
|
-
|
82
|
-
desc "Registers an instance with an ELB."
|
83
|
-
task :register_instance do
|
84
|
-
servers = variables[:logger].instance_variable_get("@options")[:actions].first
|
85
|
-
load_balancer_name = variables[:logger].instance_variable_get("@options")[:vars][:loadbalancer]
|
86
|
-
CapifyEc2.register_instance_in_elb(servers, load_balancer_name)
|
87
|
-
end
|
88
|
-
|
89
|
-
task :date do
|
90
|
-
run "date"
|
91
|
-
end
|
92
|
-
|
93
|
-
desc "Prints list of ec2 server names"
|
94
|
-
task :server_names do
|
95
|
-
puts CapifyEc2.server_names.sort
|
96
|
-
end
|
97
|
-
|
98
|
-
desc "Prints out all ec2 instances. index, name, instance_id, size, dns_name, region, tags"
|
99
|
-
task :ec2_status do
|
100
|
-
CapifyEc2.running_instances.each_with_index do |instance, i|
|
101
|
-
puts sprintf "%-11s: %-40s %-20s %-20s %-62s %-20s (%s)",
|
102
|
-
i.to_s.magenta, instance.case_insensitive_tag("Name"), instance.id.red, instance.flavor_id.cyan,
|
103
|
-
instance.dns_name.blue, instance.availability_zone.green, instance.roles.join(", ").yellow
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
desc "Allows ssh to instance by id. cap ssh <INSTANCE NAME>"
|
108
|
-
task :ssh do
|
109
|
-
server = variables[:logger].instance_variable_get("@options")[:actions][1]
|
110
|
-
instance = numeric?(server) ? CapifyEc2.running_instances[server.to_i] : CapifyEc2.get_instance_by_name(server)
|
111
|
-
port = ssh_options[:port] || 22
|
112
|
-
command = "ssh -p #{port} #{user}@#{instance.dns_name}"
|
113
|
-
puts "Running `#{command}`"
|
114
|
-
system(command)
|
115
|
-
end
|
116
|
-
|
117
|
-
namespace :deploy do
|
118
|
-
before "deploy", "deregister_instance"
|
119
|
-
after "deploy", "register_instance"
|
120
|
-
after "deploy:rollback", "register_instance"
|
121
|
-
end
|
122
|
-
|
123
123
|
end
|
data/lib/capify-ec2/version.rb
CHANGED
data/readme.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Capify Ec2
|
2
2
|
====================================================
|
3
3
|
|
4
|
-
capify-ec2 is used to generate capistrano namespaces using ec2 tags.
|
4
|
+
capify-ec2 is used to generate capistrano namespaces using ec2 tags.
|
5
5
|
|
6
6
|
eg: If you have three servers on amazon's ec2.
|
7
7
|
|
@@ -23,11 +23,11 @@ Will generate
|
|
23
23
|
task :server-1 do
|
24
24
|
role :web, {server-1 public dns fetched from Amazon}
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
27
|
task :server-3 do
|
28
28
|
role :web, {server-1 public dns fetched from Amazon}
|
29
29
|
end
|
30
|
-
|
30
|
+
|
31
31
|
task :web do
|
32
32
|
role :web, {server-1 public dns fetched from Amazon}
|
33
33
|
role :web, {server-3 public dns fetched from Amazon}
|
@@ -51,7 +51,7 @@ Will generate
|
|
51
51
|
task :db do
|
52
52
|
role :db, {server-2 public dns fetched from Amazon}
|
53
53
|
role :db, {server-3 public dns fetched from Amazon}
|
54
|
-
end
|
54
|
+
end
|
55
55
|
|
56
56
|
Running
|
57
57
|
|
@@ -61,27 +61,28 @@ will run the date command on all server's tagged with the web role
|
|
61
61
|
|
62
62
|
Running
|
63
63
|
|
64
|
-
cap server-1 register-instance -s loadbalancer=elb-1
|
64
|
+
cap server-1 ec2:register-instance -s loadbalancer=elb-1
|
65
65
|
|
66
66
|
will register server-1 to be used by elb-1
|
67
67
|
|
68
68
|
Running
|
69
|
-
|
70
|
-
cap server-1 deregister-instance
|
69
|
+
|
70
|
+
cap server-1 ec2:deregister-instance
|
71
71
|
|
72
72
|
will remove server-1 from whatever instance it is currently
|
73
73
|
registered against.
|
74
74
|
|
75
75
|
Running
|
76
76
|
|
77
|
-
cap
|
77
|
+
cap ec2:status
|
78
|
+
|
78
79
|
|
79
|
-
will list the currently running servers and their associated details
|
80
|
+
will list the currently running servers and their associated details
|
80
81
|
(public dns, instance id, roles etc)
|
81
82
|
|
82
83
|
Running
|
83
|
-
|
84
|
-
cap ssh -s i=1
|
84
|
+
|
85
|
+
cap ec2:ssh -s i=1
|
85
86
|
|
86
87
|
will launch ssh using the user and port specified in your configuration.
|
87
88
|
The 'i' argument is the index of the server to ssh into. Use the 'ec2_status'
|
@@ -92,7 +93,7 @@ More options
|
|
92
93
|
====================================================
|
93
94
|
|
94
95
|
ec2_roles {:name=>"web", :options=>{:cron=>"server-1"}}
|
95
|
-
|
96
|
+
|
96
97
|
Will generate
|
97
98
|
|
98
99
|
task :server-1 do
|
@@ -117,8 +118,8 @@ Which is cool if you want a task like this in deploy.rb
|
|
117
118
|
|
118
119
|
ec2_roles :name=>:web, :options=>{ :default => true }
|
119
120
|
|
120
|
-
Will make :web the default role so you can just type 'cap deploy'.
|
121
|
-
Multiple roles can be defaults so:
|
121
|
+
Will make :web the default role so you can just type 'cap deploy'.
|
122
|
+
Multiple roles can be defaults so:
|
122
123
|
|
123
124
|
ec2_roles :name=>:web, :options=>{ :default => true }
|
124
125
|
ec2_roles :name=>:app, :options=>{ :default => true }
|
@@ -131,12 +132,12 @@ Ec2 config
|
|
131
132
|
This gem requires 'config/ec2.yml' in your project.
|
132
133
|
The yml file needs to look something like this:
|
133
134
|
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
135
|
+
:aws_access_key_id: "YOUR ACCESS KEY"
|
136
|
+
:aws_secret_access_key: "YOUR SECRET"
|
137
|
+
:aws_params:
|
138
|
+
:region: 'eu-west-1'
|
139
|
+
:load_balanced: true
|
140
|
+
:project_tag: "YOUR APP NAME"
|
140
141
|
|
141
142
|
The :aws_params are optional.
|
142
143
|
If :load_balanced is set to true, the gem uses pre and post-deploy
|
@@ -144,7 +145,25 @@ hooks to deregister the instance, reregister it, and validate its
|
|
144
145
|
health.
|
145
146
|
:load_balanced only works for individual instances, not for roles.
|
146
147
|
|
147
|
-
The :project_tag parameter is optional. It will limit any commands to
|
148
|
-
running against those instances with a "Project" tag set to the value
|
148
|
+
The :project_tag parameter is optional. It will limit any commands to
|
149
|
+
running against those instances with a "Project" tag set to the value
|
149
150
|
"YOUR APP NAME".
|
150
151
|
|
152
|
+
## Development
|
153
|
+
|
154
|
+
Source hosted at [GitHub](http://github.com/forward/capify-ec2).
|
155
|
+
Report Issues/Feature requests on [GitHub Issues](http://github.com/forward/capify-ec2/issues).
|
156
|
+
|
157
|
+
### Note on Patches/Pull Requests
|
158
|
+
|
159
|
+
* Fork the project.
|
160
|
+
* Make your feature addition or bug fix.
|
161
|
+
* Add tests for it. This is important so I don't break it in a
|
162
|
+
future version unintentionally.
|
163
|
+
* Commit, do not mess with rakefile, version, or history.
|
164
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
165
|
+
* Send me a pull request. Bonus points for topic branches.
|
166
|
+
|
167
|
+
## Copyright
|
168
|
+
|
169
|
+
Copyright (c) 2011 Forward. See [LICENSE](https://github.com/forward/capify-ec2/blob/master/LICENSE) for details.
|
metadata
CHANGED
@@ -1,13 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capify-ec2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 1923832043
|
5
|
+
prerelease: true
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
|
9
|
+
- 14
|
10
|
+
- pre
|
11
|
+
- 1
|
12
|
+
version: 1.1.14.pre.1
|
11
13
|
platform: ruby
|
12
14
|
authors:
|
13
15
|
- Noah Cantor
|
@@ -16,7 +18,7 @@ autorequire:
|
|
16
18
|
bindir: bin
|
17
19
|
cert_chain: []
|
18
20
|
|
19
|
-
date: 2011-08-
|
21
|
+
date: 2011-08-25 00:00:00 +01:00
|
20
22
|
default_executable:
|
21
23
|
dependencies:
|
22
24
|
- !ruby/object:Gem::Dependency
|
@@ -78,8 +80,9 @@ extra_rdoc_files: []
|
|
78
80
|
|
79
81
|
files:
|
80
82
|
- .gitignore
|
81
|
-
- Changelog
|
83
|
+
- Changelog.md
|
82
84
|
- Gemfile
|
85
|
+
- LICENSE
|
83
86
|
- Rakefile
|
84
87
|
- capify-ec2.gemspec
|
85
88
|
- lib/capify-ec2.rb
|
@@ -107,12 +110,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
107
110
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
111
|
none: false
|
109
112
|
requirements:
|
110
|
-
- - "
|
113
|
+
- - ">"
|
111
114
|
- !ruby/object:Gem::Version
|
112
|
-
hash:
|
115
|
+
hash: 25
|
113
116
|
segments:
|
114
|
-
-
|
115
|
-
|
117
|
+
- 1
|
118
|
+
- 3
|
119
|
+
- 1
|
120
|
+
version: 1.3.1
|
116
121
|
requirements: []
|
117
122
|
|
118
123
|
rubyforge_project: capify-ec2
|