capistrano-getservers-alt 1.0.2
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 +21 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +77 -0
- data/Rakefile +1 -0
- data/capistrano-getservers.gemspec +22 -0
- data/lib/.gitignore +1 -0
- data/lib/capistrano-getservers.rb +1 -0
- data/lib/capistrano-getservers/get_servers.rb +59 -0
- metadata +86 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Alfred Moreno
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
# Capistrano::Getservers
|
2
|
+
|
3
|
+
capistrano-getservers makes it easier for you to deploy to your EC2
|
4
|
+
instances. By supplying a Hash to the `get_servers` method,
|
5
|
+
capistrano-getservers connects to EC2 and retrieves all instances with
|
6
|
+
matching tags.
|
7
|
+
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
gem 'capistrano-getservers'
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install capistrano-getservers
|
22
|
+
|
23
|
+
## Requirements
|
24
|
+
Ruby Gems
|
25
|
+
* `gem 'capistrano'`
|
26
|
+
* `gem 'fog'`
|
27
|
+
|
28
|
+
Environment variables
|
29
|
+
* `export AWS_SECRET_ACCESS_KEY=''`
|
30
|
+
* `export AWS_ACCESS_KEY_ID=''`
|
31
|
+
|
32
|
+
## Usage
|
33
|
+
|
34
|
+
### Retrieving instances within Capistrano
|
35
|
+
|
36
|
+
In your capistrano script:
|
37
|
+
```ruby
|
38
|
+
get_servers(:db, 'us-east-1', {'app' => 'app_name', 'cluster' => 'cluster', 'environment' => 'environment' ... })
|
39
|
+
```
|
40
|
+
|
41
|
+
### Retrieving instances from your CLI
|
42
|
+
|
43
|
+
In your capistrano script:
|
44
|
+
```ruby
|
45
|
+
set :tags, ENV['TAGS'] || {}
|
46
|
+
cli_tags = parse(tags)
|
47
|
+
get_servers(:role, region, cli_tags)
|
48
|
+
```
|
49
|
+
|
50
|
+
Then, via the command line:
|
51
|
+
|
52
|
+
`$ cap staging deploy TAGS=key1:value1,key2:value2,key3:value3...`
|
53
|
+
|
54
|
+
|
55
|
+
### Notes
|
56
|
+
|
57
|
+
You can pass `nil` as the second parameter to have capistrano-getservers
|
58
|
+
default to the `us-east-1` region.
|
59
|
+
|
60
|
+
All servers will receive the role 'web' unless you specify a different
|
61
|
+
role using the `get_servers` method.
|
62
|
+
|
63
|
+
Example: `get_servers(:role, 'us-east-1', {'deploy' => 'some value', 'app' => 'some_value'})`
|
64
|
+
|
65
|
+
## Changelog
|
66
|
+
|
67
|
+
Version 1.0.2:
|
68
|
+
* Added region support for Getservers. Had to change the function
|
69
|
+
get_servers for this, so it's now: get_servers(:role,'region',tags)
|
70
|
+
|
71
|
+
## Contributing
|
72
|
+
|
73
|
+
1. Fork it
|
74
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
75
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
76
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
77
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'capistrano-getservers/get_servers'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "capistrano-getservers-alt"
|
8
|
+
gem.version = '1.0.2'
|
9
|
+
gem.authors = ["Alfred Moreno"]
|
10
|
+
gem.email = ["alfred.moreno@zumba.com"]
|
11
|
+
gem.description = %q{A capistrano plugin for simplifying EC2 deployment processes}
|
12
|
+
gem.summary = %q{A capistrano plugin for simplifying EC@ deployment processes}
|
13
|
+
gem.homepage = ""
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_dependency 'capistrano', '>=2.1.0'
|
21
|
+
gem.add_dependency 'fog', '>=1.5.0'
|
22
|
+
end
|
data/lib/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
.DS_Store
|
@@ -0,0 +1 @@
|
|
1
|
+
require "capistrano-getservers/get_servers"
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'fog'
|
2
|
+
require 'capistrano'
|
3
|
+
|
4
|
+
unless Capistrano::Configuration.respond_to?(:instance)
|
5
|
+
abort 'capistrano-getservers requires Capistrano >= 2'
|
6
|
+
end
|
7
|
+
|
8
|
+
module Capistrano
|
9
|
+
class Configuration
|
10
|
+
module GetServers
|
11
|
+
#############################################################
|
12
|
+
# def get_servers
|
13
|
+
#
|
14
|
+
# Purpose: Retrieves a list of EC2 instances containing a tag
|
15
|
+
# list which matches a supplied hash.
|
16
|
+
#
|
17
|
+
# Matching instances are applied to the Cap server
|
18
|
+
# list.
|
19
|
+
#
|
20
|
+
# Usage: get_servers {'app' => 'zumba', 'stack' => 'web'}
|
21
|
+
#
|
22
|
+
# Returns: Nothing
|
23
|
+
#############################################################
|
24
|
+
def get_servers(role=nil, region=nil, cli_tags, aws_access_key, aws_secret_key)
|
25
|
+
|
26
|
+
ec2 = Fog::Compute::AWS.new(
|
27
|
+
aws_secret_access_key: aws_secret_key,
|
28
|
+
aws_access_key_id: aws_access_key,
|
29
|
+
region: region
|
30
|
+
)
|
31
|
+
|
32
|
+
ec2.servers.all.each do |instance|
|
33
|
+
begin
|
34
|
+
instance_tags = instance.tags.reject { |k,v| cli_tags[k] != instance.tags[k] }
|
35
|
+
server instance.public_ip_address, role || :web if instance_tags.eql? cli_tags
|
36
|
+
rescue => error
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
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] }
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
include GetServers
|
58
|
+
end
|
59
|
+
end
|
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: capistrano-getservers-alt
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.2
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Alfred Moreno
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-01-17 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: capistrano
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 2.1.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 2.1.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: fog
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 1.5.0
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 1.5.0
|
46
|
+
description: A capistrano plugin for simplifying EC2 deployment processes
|
47
|
+
email:
|
48
|
+
- alfred.moreno@zumba.com
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- .gitignore
|
54
|
+
- Gemfile
|
55
|
+
- LICENSE.txt
|
56
|
+
- README.md
|
57
|
+
- Rakefile
|
58
|
+
- capistrano-getservers.gemspec
|
59
|
+
- lib/.gitignore
|
60
|
+
- lib/capistrano-getservers.rb
|
61
|
+
- lib/capistrano-getservers/get_servers.rb
|
62
|
+
homepage: ''
|
63
|
+
licenses: []
|
64
|
+
post_install_message:
|
65
|
+
rdoc_options: []
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
none: false
|
70
|
+
requirements:
|
71
|
+
- - ! '>='
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
+
none: false
|
76
|
+
requirements:
|
77
|
+
- - ! '>='
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
requirements: []
|
81
|
+
rubyforge_project:
|
82
|
+
rubygems_version: 1.8.23
|
83
|
+
signing_key:
|
84
|
+
specification_version: 3
|
85
|
+
summary: A capistrano plugin for simplifying EC@ deployment processes
|
86
|
+
test_files: []
|