capistrano-getservers 1.0.4 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +38 -8
- data/capistrano-getservers.gemspec +3 -3
- data/lib/capistrano-getservers/get_servers.rb +77 -44
- metadata +16 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 98bfb2e0ed4ad96b91d3ffbb6eab02013a10695d
|
4
|
+
data.tar.gz: 28c489544f18837ed68066906f80b98764d50720
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f41dbbad785d11a17c615d8ae7c4d268059cd402e0043e7a548d17fe9e89dbc2f17e5f1bd7756701d1173eeb51a7b1c4efe3b6bb7fd69a70a90723e09620633d
|
7
|
+
data.tar.gz: 5ff7dbe906a66e27cee5520973811c0ead11e6bb49018a5159a93dfb47f6984d4b765001e9d95fe6d493c30ee49a1e5348a055fe10854d2e2a706b16483acdeb
|
data/README.md
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
# Capistrano::Getservers
|
2
2
|
|
3
|
-
capistrano-getservers makes it easier for you to deploy to your EC2
|
4
|
-
instances.
|
5
|
-
capistrano-getservers connects to
|
6
|
-
matching
|
3
|
+
capistrano-getservers makes it easier for you to deploy to your EC2 or
|
4
|
+
Rackspace Cloud instances. By supplying a Hash or Array, respectively, to the `get_servers` method,
|
5
|
+
capistrano-getservers connects to the appropriate service and retrieves all instances with
|
6
|
+
matching criteria.
|
7
7
|
|
8
8
|
|
9
9
|
## Installation
|
@@ -25,21 +25,36 @@ Ruby Gems
|
|
25
25
|
* `gem 'capistrano'`
|
26
26
|
* `gem 'fog'`
|
27
27
|
|
28
|
-
Environment variables
|
28
|
+
Environment variables (AWS EC2)
|
29
29
|
* `export AWS_SECRET_ACCESS_KEY=''`
|
30
30
|
* `export AWS_ACCESS_KEY_ID=''`
|
31
31
|
|
32
|
+
Environment variables (Rackspace)
|
33
|
+
* `export RACKSPACE_API_KEY=''`
|
34
|
+
* `export RACKSPACE_USERNAME=''`
|
35
|
+
|
32
36
|
## Usage
|
33
37
|
|
34
38
|
### Retrieving instances within Capistrano
|
35
39
|
|
40
|
+
#### AWS EC2
|
36
41
|
In your capistrano script:
|
37
42
|
```ruby
|
38
43
|
get_servers(:db, 'us-east-1', {'app' => 'app_name', 'cluster' => 'cluster', 'environment' => 'environment' ... })
|
39
44
|
```
|
40
45
|
|
46
|
+
#### Rackspace Cloud Servers
|
47
|
+
In your capistrano script:
|
48
|
+
```ruby
|
49
|
+
get_servers(:app, :ord, ['server1','server2','server3'])
|
50
|
+
```
|
51
|
+
|
41
52
|
### Retrieving instances from your CLI
|
42
53
|
|
54
|
+
First, add support for CLI arguments. I haven't personally tested using
|
55
|
+
both AWS and Rackspace, but if you need to, it should work just fine, really.
|
56
|
+
|
57
|
+
#### AWS EC2
|
43
58
|
In your capistrano script:
|
44
59
|
```ruby
|
45
60
|
set :tags, ENV['TAGS'] || {}
|
@@ -47,11 +62,21 @@ cli_tags = parse(tags)
|
|
47
62
|
get_servers(:role, region, cli_tags)
|
48
63
|
```
|
49
64
|
|
50
|
-
|
65
|
+
#### Rackspace
|
66
|
+
```ruby
|
67
|
+
set :names, ENV['NAMES'].split(',') || []
|
68
|
+
get_servers(:role, region, names)
|
69
|
+
```
|
70
|
+
|
71
|
+
Then, pass your tags/instance names via the command line:
|
51
72
|
|
73
|
+
##### AWS
|
52
74
|
`$ cap staging deploy TAGS=key1:value1,key2:value2,key3:value3...`
|
53
75
|
|
54
|
-
|
76
|
+
##### Rackspace
|
77
|
+
`$ cap staging deploy NAMES=web001,awesomeserver,blah...`
|
78
|
+
|
79
|
+
### Instances behind Amazon's VPC or that require a proxy
|
55
80
|
If you have instances located in a VPC with no public IP address,
|
56
81
|
capistrano-getservers will return their private ip address. You will
|
57
82
|
then need to use capistrano's gateway support to deploy to these
|
@@ -66,15 +91,20 @@ set :gateway, "gateway_address"
|
|
66
91
|
### Notes
|
67
92
|
|
68
93
|
You can pass `nil` as the second parameter to have capistrano-getservers
|
69
|
-
default to the `us-east-1` region
|
94
|
+
default to the `us-east-1` region for Amazon EC2 or `dfw` for Rackspace
|
95
|
+
Cloud servers.
|
70
96
|
|
71
97
|
All servers will receive the role 'web' unless you specify a different
|
72
98
|
role using the `get_servers` method.
|
73
99
|
|
74
100
|
Example: `get_servers(:role, 'us-east-1', {'deploy' => 'some value', 'app' => 'some_value'})`
|
101
|
+
Example: `get_servers(:role, :ord, ['web001','dbserver'])`
|
75
102
|
|
76
103
|
## Changelog
|
77
104
|
|
105
|
+
Version 2.0.0:
|
106
|
+
* Added support for Rackspace Cloud Servers
|
107
|
+
|
78
108
|
Version 1.0.3:
|
79
109
|
* get_servers now returns private instance ip addresses if no public
|
80
110
|
address is available. See VPC notes above for more info.
|
@@ -5,11 +5,11 @@ require 'capistrano-getservers/get_servers'
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |gem|
|
7
7
|
gem.name = "capistrano-getservers"
|
8
|
-
gem.version = '
|
8
|
+
gem.version = '2.0.0'
|
9
9
|
gem.authors = ["Alfred Moreno"]
|
10
10
|
gem.email = ["alfred.moreno@zumba.com"]
|
11
|
-
gem.description = %q{A capistrano plugin for simplifying
|
12
|
-
gem.summary = %q{A capistrano plugin for simplifying
|
11
|
+
gem.description = %q{A capistrano plugin for simplifying deployment processes to rackspace or amazon ec2}
|
12
|
+
gem.summary = %q{A capistrano plugin for simplifying dynamic deployment processes to rackspace or amazon ec2}
|
13
13
|
gem.homepage = ""
|
14
14
|
|
15
15
|
gem.files = `git ls-files`.split($/)
|
@@ -6,54 +6,87 @@ unless Capistrano::Configuration.respond_to?(:instance)
|
|
6
6
|
end
|
7
7
|
|
8
8
|
module Capistrano
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
9
|
+
module GetServers
|
10
|
+
|
11
|
+
def self.extend(configuration)
|
12
|
+
configuration.load do
|
13
|
+
Capistrano::Configuration.instance.load do
|
14
|
+
|
15
|
+
_cset(:aws_secret_access_key, ENV['AWS_SECRET_ACCESS_KEY'])
|
16
|
+
_cset(:aws_access_key_id, ENV['AWS_ACCESS_KEY_ID'])
|
17
|
+
_cset(:rackspace_api_key, ENV['RACKSPACE_API_KEY'])
|
18
|
+
_cset(:rackspace_username, ENV['RACKSPACE_USERNAME'])
|
19
|
+
_cset(:default_role, :web)
|
20
|
+
|
21
|
+
#############################################################
|
22
|
+
# def get_servers
|
23
|
+
#
|
24
|
+
# Purpose: Retrieves a list of EC2 instances containing a tag
|
25
|
+
# list which matches a supplied hash.
|
26
|
+
#
|
27
|
+
# Matching instances are applied to the Cap server
|
28
|
+
# list.
|
29
|
+
#
|
30
|
+
# Usage: get_servers {'app' => 'zumba', 'stack' => 'web'}
|
31
|
+
#
|
32
|
+
# Returns: Nothing
|
33
|
+
#############################################################
|
34
|
+
def get_servers(role=nil, region=nil, cli_tags)
|
35
|
+
|
36
|
+
# Rackspace regions are a 3 letter code (i.e. 'ord')
|
37
|
+
if region.size == 3
|
38
|
+
rackspace = Fog::Compute.new(
|
39
|
+
provider: 'Rackspace',
|
40
|
+
rackspace_api_key: fetch(:rackspace_api_key),
|
41
|
+
rackspace_username: fetch(:rackspace_username),
|
42
|
+
rackspace_region: region
|
43
|
+
)
|
44
|
+
|
45
|
+
rackspace.servers.select do |rackspace_server|
|
46
|
+
if cli_tags.include?(rackspace_server.name)
|
47
|
+
server (rackspace_server.ipv4_address || rackspace_server.addresses['private']['addr']), (role || :web)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
else
|
52
|
+
ec2 = Fog::Compute::AWS.new(
|
53
|
+
aws_secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'],
|
54
|
+
aws_access_key_id: ENV['AWS_ACCESS_KEY_ID'],
|
55
|
+
region: region
|
56
|
+
)
|
57
|
+
|
58
|
+
ec2.servers.all.each do |instance|
|
59
|
+
begin
|
60
|
+
instance_tags = instance.tags.reject { |k,v| cli_tags[k] != instance.tags[k] }
|
61
|
+
server (instance.public_ip_address || instance.private_ip_address), (role || :web) if instance_tags.eql?(cli_tags)
|
62
|
+
rescue
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
37
67
|
end
|
38
|
-
end
|
39
68
|
|
40
|
-
|
69
|
+
#############################################################
|
70
|
+
# def parse
|
71
|
+
#
|
72
|
+
# Purpose: Parses a string object and returns a hash.
|
73
|
+
#
|
74
|
+
# Usage: parse 'k1:v1,k2:v2,k3:v3'
|
75
|
+
#
|
76
|
+
# Returns: {'k1' => 'v1', 'k2' => 'v2', 'k3' => 'v3'}
|
77
|
+
#############################################################
|
78
|
+
def parse tags
|
79
|
+
return unless tags.class.eql? String
|
80
|
+
tags.split(',').inject({}) { |hash, pair| Hash[*pair.split(':')].merge(hash) }
|
81
|
+
end
|
41
82
|
|
42
|
-
|
43
|
-
# def parse
|
44
|
-
#
|
45
|
-
# Purpose: Parses a string object and returns a hash.
|
46
|
-
#
|
47
|
-
# Usage: parse 'k1:v1,k2:v2,k3:v3'
|
48
|
-
#
|
49
|
-
# Returns: {'k1' => 'v1', 'k2' => 'v2', 'k3' => 'v3'}
|
50
|
-
#############################################################
|
51
|
-
def parse tags
|
52
|
-
return unless tags.class.eql? String
|
53
|
-
tags.split(',').each.inject({}) { |hash, pair| hash.merge! Hash[*pair.split(':').flatten] }
|
83
|
+
end
|
54
84
|
end
|
55
|
-
|
56
85
|
end
|
57
|
-
|
86
|
+
|
58
87
|
end
|
59
88
|
end
|
89
|
+
|
90
|
+
if Capistrano::Configuration.instance
|
91
|
+
Capistrano::GetServers.extend(Capistrano::Configuration.instance)
|
92
|
+
end
|
metadata
CHANGED
@@ -1,65 +1,66 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capistrano-getservers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alfred Moreno
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-11-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: capistrano
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: 2.1.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 2.1.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: fog
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: 1.5.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 1.5.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
-
description: A capistrano plugin for simplifying
|
55
|
+
description: A capistrano plugin for simplifying deployment processes to rackspace
|
56
|
+
or amazon ec2
|
56
57
|
email:
|
57
58
|
- alfred.moreno@zumba.com
|
58
59
|
executables: []
|
59
60
|
extensions: []
|
60
61
|
extra_rdoc_files: []
|
61
62
|
files:
|
62
|
-
- .gitignore
|
63
|
+
- ".gitignore"
|
63
64
|
- Gemfile
|
64
65
|
- LICENSE.txt
|
65
66
|
- README.md
|
@@ -78,12 +79,12 @@ require_paths:
|
|
78
79
|
- lib
|
79
80
|
required_ruby_version: !ruby/object:Gem::Requirement
|
80
81
|
requirements:
|
81
|
-
- -
|
82
|
+
- - ">="
|
82
83
|
- !ruby/object:Gem::Version
|
83
84
|
version: '0'
|
84
85
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
86
|
requirements:
|
86
|
-
- -
|
87
|
+
- - ">="
|
87
88
|
- !ruby/object:Gem::Version
|
88
89
|
version: '0'
|
89
90
|
requirements: []
|
@@ -91,5 +92,7 @@ rubyforge_project:
|
|
91
92
|
rubygems_version: 2.0.2
|
92
93
|
signing_key:
|
93
94
|
specification_version: 4
|
94
|
-
summary: A capistrano plugin for simplifying
|
95
|
+
summary: A capistrano plugin for simplifying dynamic deployment processes to rackspace
|
96
|
+
or amazon ec2
|
95
97
|
test_files: []
|
98
|
+
has_rdoc:
|