capistrano-autoscale-deploy 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,18 @@
1
+ .DS_Store
2
+ *.gem
3
+ *.rbc
4
+ .bundle
5
+ .config
6
+ .yardoc
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'http://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in capistrano-ec2tag.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Ami Mahloof
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 AutoScale Deploy
2
+
3
+ Capistrano plugin that enable discovery of instances in ec2 AutoScale groups into capistrano deployment script.
4
+
5
+ ## Requirements
6
+
7
+ * aws-sdk
8
+ * capistrano ~> 2.15.5
9
+
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ gem 'capistrano-autoscale-deploy'
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install capistrano-autoscale-deploy
24
+
25
+ Add this line to your application's Capfile:
26
+
27
+ ```ruby
28
+ require 'capistrano/autoscale_deploy'
29
+ ```
30
+
31
+ And set credentials with AmazonEC2ReadOnlyAccess permission in config/deploy.rb as:
32
+
33
+ ```ruby
34
+ set :access_key_id, "YOUR ACCESS KEY ID"
35
+ set :secret_access_key, "YOUR SECRET ACCESS KEY"
36
+ set :region, "eu-west-1"
37
+ ```
38
+
39
+ ## Usage
40
+
41
+ In the capistrano deploy script / stage files add the following line
42
+
43
+ ```ruby
44
+ autoscale :AutoScaleGroup => 'name of your autoscale group (by Name tag)', :deploy_roles => [:app, :web, :db, :primary => true]
45
+ ```
46
+
47
+ you can add more autoscale configs to deploy to multiple autoscale groups like a cluster
48
+
49
+ ## How this works
50
+
51
+ This gem will fetch only running instances that have an autoscale tag name you specified
52
+ it will then reject the role of :db and the primary => true for all servers found but the first one
53
+ this is to make sure a single working task does not run in parallel
54
+
55
+ you end up as if you defined the servers yourself like so:
56
+
57
+ ````ruby
58
+ server ip_address1, :app :db, :web, :primary => true
59
+ server ip_address2, :app, :web
60
+ server ip_address3, :app, :web
61
+ ````
62
+
63
+ ## Contributing
64
+
65
+ 1. Fork it ( http://github.com/<my-github-username>/capistrano-ec2_tagged/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/autoscale_deploy/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "capistrano-autoscale-deploy"
8
+ spec.version = Capistrano::AutoScaleDeploy::VERSION
9
+ spec.authors = ["Ami Mahloof"]
10
+ spec.email = ["ami.mahloof@gmail.com"]
11
+ spec.summary = %q{Get all instances in AutoScale group by AutoScale ec2 tag.}
12
+ spec.description = %q{Get all instances in AutoScale group by AutoScale ec2 tag.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
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_dependency "aws-sdk"
22
+ spec.add_dependency "capistrano", "~> 2.15.5"
23
+ spec.add_development_dependency "bundler", "~> 1.5"
24
+ spec.add_development_dependency "rake"
25
+ end
@@ -0,0 +1 @@
1
+ require "capistrano/autoscale_deploy"
@@ -0,0 +1,5 @@
1
+ module Capistrano
2
+ module AutoScaleDeploy
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
@@ -0,0 +1,64 @@
1
+ require "capistrano"
2
+ require "aws-sdk"
3
+
4
+ module Capistrano
5
+ module AutoScaleDeploy
6
+ def self.extend(configuration)
7
+ configuration.load do
8
+ Capistrano::Configuration.instance.load do
9
+ _cset(:instances, {})
10
+
11
+ def connect_ec2
12
+ @ec2 ||= AWS::EC2.new({
13
+ access_key_id: fetch(:aws_access_key_id),
14
+ secret_access_key: fetch(:aws_secret_access_key),
15
+ region: fetch(:aws_default_region)
16
+ })
17
+ end
18
+
19
+ def sanitize_roles(roles)
20
+ # remove :db (for migrations), remove :primary => :true (for assets precompile)
21
+ roles.inject([]){|acc, role|
22
+ if !role.is_a?(Hash)
23
+ acc << role if role != :db
24
+ else
25
+ acc << role.reject{|k,v| k == :primary}
26
+ end
27
+ acc
28
+ }
29
+ end
30
+
31
+ def autoscale(options = {})
32
+ begin
33
+ connect_ec2
34
+ rescue Exception => e
35
+ logger.info("unable to connect to ec2: #{e}")
36
+ end
37
+
38
+ logger.info("found #{@ec2.instances.filter('tag-key', 'AutoScaleGroup').filter('tag-value', options[:AutoScaleGroup]).filter('instance-state-code', '16').count} servers for AutoScaleGroup: #{options[:AutoScaleGroup]} ")
39
+
40
+ # => filter('instance-state-code', '16') only running instances
41
+ @ec2.instances.filter('tag-key', 'AutoScaleGroup').filter('tag-value', options[:AutoScaleGroup]).filter('instance-state-code', '16').inject(instances){|acc, instance|
42
+ acc[instance.ip_address] = options[:deploy_roles]
43
+ acc
44
+ }
45
+
46
+ instances.each {|instance, roles|
47
+ if instances.first[0] == instance
48
+ server instance, *roles
49
+ logger.info("First Server: #{instance} - #{roles}")
50
+ else
51
+ logger.info("Server: #{instance} - #{sanitize_roles(roles)}")
52
+ server instance, *sanitize_roles(roles)
53
+ end
54
+ }
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
61
+
62
+ if Capistrano::Configuration.instance
63
+ Capistrano::AutoScaleDeploy.extend(Capistrano::Configuration.instance)
64
+ end
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-autoscale-deploy
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Ami Mahloof
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-02-26 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: aws-sdk
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '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: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: capistrano
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 2.15.5
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: 2.15.5
46
+ - !ruby/object:Gem::Dependency
47
+ name: bundler
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '1.5'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '1.5'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rake
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ description: Get all instances in AutoScale group by AutoScale ec2 tag.
79
+ email:
80
+ - ami.mahloof@gmail.com
81
+ executables: []
82
+ extensions: []
83
+ extra_rdoc_files: []
84
+ files:
85
+ - .gitignore
86
+ - Gemfile
87
+ - LICENSE
88
+ - README.md
89
+ - Rakefile
90
+ - capistrano-autoscale-deploy.gemspec
91
+ - lib/autoscale_deploy.rb
92
+ - lib/capistrano/autoscale_deploy.rb
93
+ - lib/capistrano/autoscale_deploy/version.rb
94
+ homepage: ''
95
+ licenses:
96
+ - MIT
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ none: false
103
+ requirements:
104
+ - - ! '>='
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ none: false
109
+ requirements:
110
+ - - ! '>='
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ requirements: []
114
+ rubyforge_project:
115
+ rubygems_version: 1.8.25
116
+ signing_key:
117
+ specification_version: 3
118
+ summary: Get all instances in AutoScale group by AutoScale ec2 tag.
119
+ test_files: []
120
+ has_rdoc: