capistrano3-autoscaling-deploy 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.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ MjkxZDcwNDI2MTgyYmQwNWE5ZWRmM2M1Y2UwMTcyY2JhMjg5MmI2MA==
5
+ data.tar.gz: !binary |-
6
+ ODg1YjEyZTlhYzhhNWFiNTdhYzRiMWYyYzhjZjg5ZTc5NWE5ZTBjMw==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ OWI5N2I2NWM1ZTVlNDE1MGZmMThmYWUwZjZjYTk1MzQzZDkzY2I1NGM0M2Uy
10
+ MDY5N2E2MGIwNmZhN2I3YmMyNmFhMmU2YTE2MWQ0MzZmMTM1YmI1MDA3OWRl
11
+ MDRkNmY4MDc0ZDkwZTRiMmUyZjFkZWE2ZTExNWM2ODE5OTcyYTM=
12
+ data.tar.gz: !binary |-
13
+ MTBmZGY0N2NiNThjOTA1YjUyNjUyZWZmNDgxZTYwMjJkMjgyMzNlNmM0YmEx
14
+ NTg4NGY3ODFjZWM4NTA2YTI3YzZhOWM5YzAxY2U2ZTMxOWZiOWExOGQ1OGIx
15
+ MzU0M2E4ZmRjMzdkODY2YjdkNzdhMWFkMzdkNTYyNWE2NDZiNDc=
data/.gitignore ADDED
@@ -0,0 +1,53 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ # Used by dotenv library to load environment variables.
14
+ # .env
15
+
16
+ ## Specific to RubyMotion:
17
+ .dat*
18
+ .repl_history
19
+ build/
20
+ *.bridgesupport
21
+ build-iPhoneOS/
22
+ build-iPhoneSimulator/
23
+
24
+ ## Specific to RubyMotion (use of CocoaPods):
25
+ #
26
+ # We recommend against adding the Pods directory to your .gitignore. However
27
+ # you should judge for yourself, the pros and cons are mentioned at:
28
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
29
+ #
30
+ # vendor/Pods/
31
+
32
+ ## Documentation cache and generated files:
33
+ /.yardoc/
34
+ /_yardoc/
35
+ /doc/
36
+ /rdoc/
37
+
38
+ ## Environment normalization:
39
+ /.bundle/
40
+ /vendor/bundle
41
+ /lib/bundler/man/
42
+
43
+ # for a library or gem, you might want to ignore these files since the code is
44
+ # intended to run in multiple environments; otherwise, check them in:
45
+ # Gemfile.lock
46
+ # .ruby-version
47
+ # .ruby-gemset
48
+
49
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
50
+ .rvmrc
51
+
52
+ # RubyMine folder
53
+ .idea
data/.travis.yml ADDED
@@ -0,0 +1,12 @@
1
+ install:
2
+ - time
3
+
4
+ script:
5
+ - time
6
+
7
+ deploy:
8
+ provider: rubygems
9
+ api_key: $RUBYGEMS_API_KEY
10
+ on:
11
+ repo: mchicote/capistrano3-autoscaling-deploy
12
+ branch: master
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/Gemfile.lock ADDED
@@ -0,0 +1,51 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ capistrano3-autoscaling-deploy (0.1)
5
+ aws-sdk (~> 2)
6
+ capistrano (~> 3)
7
+ capistrano-bundler
8
+
9
+ GEM
10
+ remote: http://rubygems.org/
11
+ specs:
12
+ airbrussh (1.0.2)
13
+ sshkit (>= 1.6.1, != 1.7.0)
14
+ aws-sdk (2.3.9)
15
+ aws-sdk-resources (= 2.3.9)
16
+ aws-sdk-core (2.3.9)
17
+ jmespath (~> 1.0)
18
+ aws-sdk-resources (2.3.9)
19
+ aws-sdk-core (= 2.3.9)
20
+ capistrano (3.5.0)
21
+ airbrussh (>= 1.0.0)
22
+ capistrano-harrow
23
+ i18n
24
+ rake (>= 10.0.0)
25
+ sshkit (>= 1.9.0)
26
+ capistrano-bundler (1.1.4)
27
+ capistrano (~> 3.1)
28
+ sshkit (~> 1.2)
29
+ capistrano-harrow (0.5.1)
30
+ i18n (0.7.0)
31
+ jmespath (1.2.4)
32
+ json_pure (>= 1.8.1)
33
+ json_pure (1.8.3)
34
+ net-scp (1.2.1)
35
+ net-ssh (>= 2.6.5)
36
+ net-ssh (3.1.1)
37
+ rake (11.1.2)
38
+ sshkit (1.10.0)
39
+ net-scp (>= 1.1.2)
40
+ net-ssh (>= 2.8.0)
41
+
42
+ PLATFORMS
43
+ ruby
44
+
45
+ DEPENDENCIES
46
+ bundler (~> 1.5)
47
+ capistrano3-autoscaling-deploy!
48
+ rake
49
+
50
+ BUNDLED WITH
51
+ 1.12.5
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2016 Marcos Chicote
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,79 @@
1
+ [![Gem Version](https://badge.fury.io/rb/capistrano3-autoscaling-deploy.png)](http://badge.fury.io/rb/capistrano3-autoscaling-deploy)
2
+ # capistrano3-autoscaling-deploy
3
+ Capistrano 3 plugin for AWS Auto Scaling deploys.
4
+
5
+ A lot of inspiration (and code) for how this gem was built come from https://github.com/gtforge/capistrano-autoscale-deploy
6
+ I've also taken suggestions from the opened PRs against such repo.
7
+
8
+ I'm mainly building this gem as the author for the gem above has dissapeared
9
+ and I need an updated version that uses Capistrano 3 and current version of
10
+ AWS CLI.
11
+
12
+ ## Requirements
13
+
14
+ * aws-sdk ~> 2
15
+ * capistrano ~> 3
16
+
17
+
18
+ ## Installation
19
+
20
+ Add this line to your application's Gemfile:
21
+
22
+ gem 'capistrano3-autoscaling-deploy'
23
+
24
+ And then execute:
25
+
26
+ $ bundle install
27
+
28
+ Or install it yourself as:
29
+
30
+ $ gem install capistrano3-autoscaling-deploy
31
+
32
+ Add this line to your application's Capfile:
33
+
34
+ ```ruby
35
+ require 'capistrano/autoscaling_deploy'
36
+ ```
37
+
38
+ ## Usage
39
+
40
+ Set credentials with AmazonEC2ReadOnlyAccess permission in the capistrano deploy script / stage files add the following lines
41
+
42
+ ```ruby
43
+ set :aws_region, 'us-west-2'
44
+ set :aws_access_key_id, 'YOUR AWS KEY ID'
45
+ set :aws_secret_access_key, 'YOUR AWS SECRET KEY'
46
+ set :aws_autoscaling_group_name, 'YOUR NAME OF AUTO SCALING GROUP NAME'
47
+ set :aws_deploy_roles, [:app, :web, :db]
48
+ ```
49
+
50
+ you can add more auto scaling configs to deploy to multiple auto scaling groups like a cluster
51
+
52
+ ## How this works
53
+
54
+ This gem will fetch only running instances that have an auto scaling tag name you specified
55
+
56
+ It will then reject the roles of :db and the :primary => true for all servers found **but the first one**
57
+
58
+ (from all auto scaling groups you have specified such as using more then once the auto scaling directive in your config - i.e cluster deploy)
59
+
60
+ this is to make sure a single working task does not run in parallel
61
+
62
+ you end up as if you defined the servers yourself like so:
63
+
64
+ ````ruby
65
+ server ip_address1, :app, :db, :web, :primary => true
66
+ server ip_address2, :app, :web
67
+ server ip_address3, :app, :web
68
+ ````
69
+
70
+ ## Contributing
71
+
72
+ 1. Fork it ( http://github.com/<my-github-username>/capistrano3-autoscaling-deploy/fork )
73
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
74
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
75
+ 4. Push to the branch (`git push origin my-new-feature`)
76
+ 5. Create new Pull Request
77
+
78
+ To test while developoing just `bundle console` on the project root directory and execute
79
+ `Capistrano::AutoScalingDeploy::VERSION` for a quick test
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,26 @@
1
+ # encoding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'capistrano/autoscaling_deploy/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'capistrano3-autoscaling-deploy'
8
+ spec.version = Capistrano::AutoScalingDeploy::VERSION
9
+ spec.authors = ['Marcos Chicote']
10
+ spec.email = ['chicotemarcos@gmail.com']
11
+ spec.summary = %q{Get all instances in an AutoScaling group by AutoScaling EC2 Tag and depoy.}
12
+ spec.description = %q{Get all instances in an AutoScaling group by AutoScaling EC2 Tag and depoy.}
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', '~> 2'
22
+ spec.add_dependency 'capistrano', '~> 3'
23
+ spec.add_dependency 'capistrano-bundler'
24
+ spec.add_development_dependency 'bundler', '~> 1.5'
25
+ spec.add_development_dependency 'rake'
26
+ end
@@ -0,0 +1,2 @@
1
+ require 'capistrano/bundler'
2
+ load File.expand_path('tasks/deploy.rake', __FILE__)
@@ -0,0 +1 @@
1
+ load File.expand_path('../../tasks/deploy.rake', __FILE__)
@@ -0,0 +1,5 @@
1
+ module Capistrano
2
+ module AutoScalingDeploy
3
+ VERSION = '0.1'
4
+ end
5
+ end
@@ -0,0 +1,46 @@
1
+ require 'aws-sdk'
2
+
3
+ module AwsHelper
4
+ def get_instances(aws_region, aws_access_key_id, aws_secret_access_key, aws_autoscaling_group_name)
5
+ aws_credentials = Aws::Credentials.new(aws_access_key_id, aws_secret_access_key)
6
+ retrieve_ec2_instances(aws_region, aws_autoscaling_group_name, aws_credentials)
7
+ end
8
+
9
+ private
10
+
11
+ def retrieve_ec2_instances(aws_region, autoscaling_group_name, aws_credentials)
12
+ instances = fetch_autoscaling_group_instances(aws_region, autoscaling_group_name, aws_credentials)
13
+
14
+ if instances.empty?
15
+ autoscaling_dns = []
16
+ else
17
+ instance_ids = instances.map(&:instance_id)
18
+ ec2 = Aws::EC2::Resource.new(region: aws_region, credentials: aws_credentials)
19
+ puts "instances_ids #{instance_ids}"
20
+ autoscaling_dns = instance_ids.map do |instance_id|
21
+ ec2.instance(instance_id).public_dns_name
22
+ end
23
+ end
24
+
25
+ autoscaling_dns
26
+ end
27
+
28
+ def fetch_autoscaling_group_instances(aws_region, autoscaling_group_name, aws_credentials)
29
+ as = Aws::AutoScaling::Client.new(region: aws_region, credentials: aws_credentials)
30
+ as_groups = as.describe_auto_scaling_groups(
31
+ auto_scaling_group_names: [autoscaling_group_name],
32
+ max_records: 1,
33
+ ).auto_scaling_groups
34
+
35
+ puts "as groups: #{as_groups}"
36
+
37
+ as_group = as_groups[0]
38
+
39
+ puts "as group: #{as_group}"
40
+
41
+ puts "as group: #{as_group.instances}"
42
+
43
+ as_group.instances
44
+ end
45
+
46
+ end
@@ -0,0 +1,13 @@
1
+ module CapHelper
2
+ def sanitize_roles(roles)
3
+ # remove :db (for migrations), remove :primary => :true (for assets precompile)
4
+ roles.inject([]){|acc, role|
5
+ if !role.is_a?(Hash)
6
+ acc << role if role != :db
7
+ else
8
+ acc << role.reject{|k,v| k == :primary}
9
+ end
10
+ acc
11
+ }
12
+ end
13
+ end
@@ -0,0 +1,50 @@
1
+ require 'capistrano/helpers/aws_helper'
2
+ require 'capistrano/helpers/cap_helper'
3
+
4
+ namespace :load do
5
+ task :defaults do
6
+ set :aws_autoscaling, true
7
+ set :aws_region, 'us-west-2'
8
+ end
9
+ end
10
+
11
+ # namespace :deploy do
12
+ # before :starting do
13
+ # invoke 'autoscaling_deploy:setup_instances' if fetch(:aws_autoscaling)
14
+ # end
15
+ # end
16
+
17
+ namespace :autoscaling_deploy do
18
+ include AwsHelper
19
+ include CapHelper
20
+
21
+ desc 'Add server from Auto Scaling Group.'
22
+ task :setup_instances do
23
+ ec2_instances = fetch_ec2_instances
24
+ aws_deploy_roles = [:db, :web, :app]#fetch(:aws_deploy_roles)
25
+
26
+ ec2_instances.each {|instance|
27
+ if ec2_instances.first[0] == instance
28
+ server instance, *roles
29
+ logger.info("First Server: #{instance} - #{aws_deploy_roles}")
30
+ else
31
+ server instance, *sanitize_roles(roles)
32
+ logger.info("Server: #{instance} - #{sanitize_roles(aws_deploy_roles)}")
33
+ end
34
+ }
35
+
36
+ end
37
+
38
+ def fetch_ec2_instances
39
+ region = fetch(:aws_region)
40
+ key = fetch(:aws_access_key_id)
41
+ secret = fetch(:aws_secret_access_key)
42
+ group_name = fetch(:aws_autoscaling_group_name)
43
+
44
+ instances = get_instances(region, key, secret, group_name)
45
+
46
+ puts("Found #{instances.count} servers for Auto Scaling Group: #{group_name} ")
47
+
48
+ instances
49
+ end
50
+ end
File without changes
@@ -0,0 +1,18 @@
1
+ require File.expand_path('../lib/localytics', File.dirname(__FILE__))
2
+ require File.expand_path('test_helper', File.dirname(__FILE__))
3
+
4
+ require 'cutest'
5
+ require 'mocha/api'
6
+ include Mocha::API
7
+
8
+ prepare do
9
+ # Prepare Test
10
+ end
11
+
12
+ setup do
13
+ # Setup test
14
+ end
15
+
16
+ test 'autoscale' do |mock|
17
+ # Do Test
18
+ end
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano3-autoscaling-deploy
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - Marcos Chicote
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-09-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: aws-sdk
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: capistrano
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '3'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: capistrano-bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '1.5'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '1.5'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Get all instances in an AutoScaling group by AutoScaling EC2 Tag and
84
+ depoy.
85
+ email:
86
+ - chicotemarcos@gmail.com
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - .gitignore
92
+ - .travis.yml
93
+ - Gemfile
94
+ - Gemfile.lock
95
+ - LICENSE
96
+ - README.md
97
+ - Rakefile
98
+ - capistrano3-autoscaling-deploy.gemspec
99
+ - lib/capistrano/autoscaling_deploy.rb
100
+ - lib/capistrano/autoscaling_deploy/autoscaling_deploy.rb
101
+ - lib/capistrano/autoscaling_deploy/version.rb
102
+ - lib/capistrano/helpers/aws_helper.rb
103
+ - lib/capistrano/helpers/cap_helper.rb
104
+ - lib/capistrano/tasks/deploy.rake
105
+ - lib/capistrano3-autoscaling-deploy.rb
106
+ - test/autoscaling_test.rb
107
+ homepage: ''
108
+ licenses:
109
+ - MIT
110
+ metadata: {}
111
+ post_install_message:
112
+ rdoc_options: []
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ! '>='
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ! '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ requirements: []
126
+ rubyforge_project:
127
+ rubygems_version: 2.4.5
128
+ signing_key:
129
+ specification_version: 4
130
+ summary: Get all instances in an AutoScaling group by AutoScaling EC2 Tag and depoy.
131
+ test_files:
132
+ - test/autoscaling_test.rb