capistrano_ec2_role 0.0.1

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,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.swp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in capistrano_ec2_role.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 madeth
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,69 @@
1
+ # capistrano_ec2_role
2
+
3
+ Capistrano plugin for ec2
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'capistrano_ec2_role', require: false
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install capistrano_ec2_role
18
+
19
+ ## Usage
20
+
21
+ need set ec2 tags on AWS
22
+
23
+ ![ec2_tag](https://raw.githubusercontent.com/wiki/madeth/capistrano_ec2_role/images/ec2_tag.png)
24
+
25
+ ### Capistrano3
26
+
27
+ ```
28
+ # Capfile
29
+ require 'capistrano_ec2_role'
30
+ ```
31
+
32
+ ```
33
+ # config/deploy.rb
34
+ set :ec2_deploy_tag_name, 'role' # default is 'role'
35
+ set :aws_access_key_id, '...'
36
+ set :aws_secret_access_key, '...'
37
+ set :aws_region, '...'
38
+ ```
39
+
40
+ ```
41
+ # config/deploy/*.rb
42
+ ec2_role :web, 'web'
43
+ ec2_role :app, 'app'
44
+ ec2_role :db, 'db'
45
+ ```
46
+
47
+ ### Capistrano2
48
+
49
+ ```
50
+ # config/deploy.rb
51
+ require 'capistrano_ec2_role'
52
+
53
+ set :ec2_deploy_tag_name, 'role' # default is 'role'
54
+ set :aws_access_key_id, '...'
55
+ set :aws_secret_access_key, '...'
56
+ set :aws_region, '...'
57
+
58
+ ec2_role :web, 'web'
59
+ ec2_role :app, 'app'
60
+ ec2_role :db, 'db', primary: true
61
+ ```
62
+
63
+ ## Contributing
64
+
65
+ 1. Fork it ( http://github.com/<my-github-username>/capistrano_ec2_role/fork )
66
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
67
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
68
+ 4. Push to the branch (`git push origin my-new-feature`)
69
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'capistrano/ec2_role/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "capistrano_ec2_role"
8
+ spec.version = Capistrano::Ec2Role::VERSION
9
+ spec.authors = ["madeth"]
10
+ spec.email = ["madethg@gmail.com"]
11
+ spec.summary = %q{capistrano_ec2_role builds a target server from a tag of ec2 dynamically}
12
+ spec.description = %q{capistrano_ec2_role builds a target server from a tag of ec2 dynamically}
13
+ spec.homepage = "https://github.com/madeth/capistrano_ec2_role"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.5"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_dependency "aws-sdk", "~> 1.41.0"
24
+ spec.add_dependency "capistrano", ">= 2.13.5"
25
+ end
@@ -0,0 +1,3 @@
1
+ require "capistrano/ec2_role/version"
2
+ require "capistrano/ec2_role/servers"
3
+ require "capistrano/ec2_role/dsl/env"
@@ -0,0 +1,17 @@
1
+ Capistrano::Configuration.instance(:must_exist).load do
2
+
3
+ def ec2_role(role_name, tag_name, options={})
4
+ AWS.memoize do
5
+ instances = Capistrano::Ec2Role::Servers.new(
6
+ fetch(:aws_access_key_id),
7
+ fetch(:aws_secret_access_key),
8
+ fetch(:aws_region)
9
+ ).running.tagged({fetch(:ec2_deploy_tag_name, :role) => tag_name}).to_instances_name
10
+
11
+ instances.each {|instance|
12
+ server instance, role_name, options
13
+ }
14
+ end
15
+ end
16
+
17
+ end
@@ -0,0 +1,21 @@
1
+ module Capistrano
2
+ module Ec2Role
3
+ module DSL
4
+ module Env
5
+
6
+ def ec2_role(role_name, tag_name)
7
+ AWS.memoize do
8
+ instances = Capistrano::Ec2Role::Servers.new(
9
+ fetch(:aws_access_key_id),
10
+ fetch(:aws_secret_access_key),
11
+ fetch(:aws_region)
12
+ ).running.tagged(fetch(:ec2_deploy_tag_name, :role) => tag_name).to_instances_name
13
+
14
+ role role_name.to_sym, instances
15
+ end
16
+ end
17
+
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,58 @@
1
+ require 'aws-sdk'
2
+
3
+ module Capistrano
4
+ module Ec2Role
5
+ class Servers
6
+
7
+ class << self
8
+ attr_accessor :cache_instances
9
+ end
10
+
11
+ attr_accessor :ec2_instances
12
+
13
+ def initialize(access_key_id, secret_access_key, region)
14
+ self.class.cache_instances ||= AWS::EC2.new(
15
+ :access_key_id => access_key_id,
16
+ :secret_access_key => secret_access_key,
17
+ :region => region
18
+ ).instances.to_a
19
+
20
+ self.ec2_instances = self.class.cache_instances.clone
21
+ self
22
+ end
23
+
24
+ def cache_instances
25
+ self.class.cache_instances
26
+ end
27
+
28
+ def tagged(tag)
29
+ tap {
30
+ ec2_instances.delete_if {|instance| untagged?(instance, tag) }
31
+ }
32
+ end
33
+
34
+ def running
35
+ tap {
36
+ ec2_instances.delete_if {|instance| instance.status != :running }
37
+ }
38
+ end
39
+
40
+ def to_instances_name
41
+ ec2_instances.map {|instance| instance.public_dns_name || instance.private_dns_name }
42
+ end
43
+
44
+ private
45
+
46
+ def untagged?(instance, tag)
47
+ return true if tag.empty?
48
+
49
+ required = tag.map {|k, v|
50
+ instance.tags[k.to_s].gsub(/[\s ]/, '').split(',').include?(v) rescue false
51
+ }
52
+
53
+ required.uniq.any? {|r| r == false}
54
+ end
55
+
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,5 @@
1
+ module Capistrano
2
+ module Ec2Role
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,8 @@
1
+ require 'capistrano/version'
2
+ require "capistrano/ec2_role"
3
+
4
+ if defined?(Capistrano::VERSION) && Gem::Version.new(Capistrano::VERSION) >= Gem::Version.new('3.0.0')
5
+ extend Capistrano::Ec2Role::DSL::Env
6
+ else
7
+ require 'capistrano/ec2_role/configuration'
8
+ end
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano_ec2_role
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - madeth
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-06-13 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.5'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.5'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: aws-sdk
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 1.41.0
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 1.41.0
62
+ - !ruby/object:Gem::Dependency
63
+ name: capistrano
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: 2.13.5
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: 2.13.5
78
+ description: capistrano_ec2_role builds a target server from a tag of ec2 dynamically
79
+ email:
80
+ - madethg@gmail.com
81
+ executables: []
82
+ extensions: []
83
+ extra_rdoc_files: []
84
+ files:
85
+ - .gitignore
86
+ - Gemfile
87
+ - LICENSE.txt
88
+ - README.md
89
+ - Rakefile
90
+ - capistrano_ec2_role.gemspec
91
+ - lib/capistrano/ec2_role.rb
92
+ - lib/capistrano/ec2_role/configuration.rb
93
+ - lib/capistrano/ec2_role/dsl/env.rb
94
+ - lib/capistrano/ec2_role/servers.rb
95
+ - lib/capistrano/ec2_role/version.rb
96
+ - lib/capistrano_ec2_role.rb
97
+ homepage: https://github.com/madeth/capistrano_ec2_role
98
+ licenses:
99
+ - MIT
100
+ post_install_message:
101
+ rdoc_options: []
102
+ require_paths:
103
+ - lib
104
+ required_ruby_version: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ none: false
112
+ requirements:
113
+ - - ! '>='
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ requirements: []
117
+ rubyforge_project:
118
+ rubygems_version: 1.8.23
119
+ signing_key:
120
+ specification_version: 3
121
+ summary: capistrano_ec2_role builds a target server from a tag of ec2 dynamically
122
+ test_files: []