capistrano-getservers 1.0.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 ADDED
@@ -0,0 +1,21 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ Gemfile.lock
6
+ InstalledFiles
7
+ coverage
8
+
9
+ InstalledFiles
10
+ lib/bundler/man
11
+ pkg
12
+ rdoc
13
+ spec/reports
14
+ test/tmp
15
+ test/version_tmp
16
+ tmp
17
+
18
+ # YARD artifacts
19
+ .yardoc
20
+ _yardoc
21
+ doc/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in capistrano-getservers.gemspec
4
+ gemspec
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,62 @@
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
+ ## Usage
24
+
25
+ ### Server Roles
26
+
27
+ All instances are assigned the 'web' role by default, unless you assign
28
+ an 'app' variable to the particular role you want to add servers to.
29
+
30
+ You can change the roles of the servers before they're added by doing
31
+ something like:
32
+
33
+ `set :app, 'database'`
34
+
35
+ ### Retrieving instances within Capistrano
36
+
37
+ In your capistrano script:
38
+ ```ruby
39
+ get_servers({'app' => 'app_name', 'cluster' => 'cluster', 'environment' => 'environment' ... })
40
+ ```
41
+
42
+ ### Retrieving instances from your CLI
43
+
44
+ In your capistrano script:
45
+ ```ruby
46
+ set :tags, ENV['TAGS'] || {}
47
+ cli_tags = parse(tags)
48
+ get_servers(cli_tags)
49
+ ```
50
+
51
+ Then, via the command line:
52
+
53
+ `$ cap staging deploy TAGS=key1:value1,key2:value2,key3:value3...`
54
+
55
+
56
+ ## Contributing
57
+
58
+ 1. Fork it
59
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
60
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
61
+ 4. Push to the branch (`git push origin my-new-feature`)
62
+ 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"
8
+ gem.version = '1.0.0'
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,58 @@
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 cli_tags
25
+
26
+ ec2 = Fog::Compute::AWS.new(
27
+ aws_secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'],
28
+ aws_access_key_id: ENV['AWS_ACCESS_KEY_ID']
29
+ )
30
+
31
+ ec2.servers.all.each do |instance|
32
+ begin
33
+ instance_tags = instance.tags.reject { |k,v| cli_tags[k] != instance.tags[k] }
34
+ server instance.public_ip_address, app.to_sym || :web if instance_tags.eql? cli_tags
35
+ rescue => error
36
+ end
37
+ end
38
+
39
+ end
40
+
41
+ #############################################################
42
+ # def parse
43
+ #
44
+ # Purpose: Parses a string object and returns a hash.
45
+ #
46
+ # Usage: parse 'k1:v1,k2:v2,k3:v3'
47
+ #
48
+ # Returns: {'k1' => 'v1', 'k2' => 'v2', 'k3' => 'v3'}
49
+ #############################################################
50
+ def parse tags
51
+ return unless tags.class.eql? String
52
+ tags.split(',').each.inject({}) { |hash, pair| hash.merge! Hash[*pair.split(':').flatten] }
53
+ end
54
+
55
+ end
56
+ include GetServers
57
+ end
58
+ end
@@ -0,0 +1 @@
1
+ require "capistrano-getservers/get_servers"
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-getservers
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Alfred Moreno
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-10-11 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.24
83
+ signing_key:
84
+ specification_version: 3
85
+ summary: A capistrano plugin for simplifying EC@ deployment processes
86
+ test_files: []
87
+ has_rdoc: