capistrano3-asg-deploy 1.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,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 54f28b1a906731edf7172bbdaa9710be0b6864f4c4cacfe4c2e95d70ae692230
4
+ data.tar.gz: 16cc06f26d5bc61bc55747b2011ba96a71689d829bd1e42db65fdd52c7ae93c1
5
+ SHA512:
6
+ metadata.gz: 40a6bb1e9e47131bb7f161f30fc6b37201539838a99e663cb0225f3c55711683255b07835a9bfdb5e2dc1df4bc899d1bf5afd584913bb25612bfe72f3484ce7c
7
+ data.tar.gz: effb9fa5eb9822cccef6dd736eca7486c2f48a2e77d60677a9bacede5328c2e081eb397b0385701888c8c1679d6c13962b294b81beef15ca45c40d16a899ad6c
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/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,53 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ capistrano3-autoscaling-deploy (1.3)
5
+ aws-sdk (~> 2)
6
+ capistrano (~> 3)
7
+ capistrano-bundler (~> 1.2.0)
8
+
9
+ GEM
10
+ remote: http://rubygems.org/
11
+ specs:
12
+ airbrussh (1.4.0)
13
+ sshkit (>= 1.6.1, != 1.7.0)
14
+ aws-eventstream (1.1.0)
15
+ aws-sdk (2.11.608)
16
+ aws-sdk-resources (= 2.11.608)
17
+ aws-sdk-core (2.11.608)
18
+ aws-sigv4 (~> 1.0)
19
+ jmespath (~> 1.0)
20
+ aws-sdk-resources (2.11.608)
21
+ aws-sdk-core (= 2.11.608)
22
+ aws-sigv4 (1.2.2)
23
+ aws-eventstream (~> 1, >= 1.0.2)
24
+ capistrano (3.14.1)
25
+ airbrussh (>= 1.0.0)
26
+ i18n
27
+ rake (>= 10.0.0)
28
+ sshkit (>= 1.9.0)
29
+ capistrano-bundler (1.2.0)
30
+ capistrano (~> 3.1)
31
+ sshkit (~> 1.2)
32
+ concurrent-ruby (1.1.7)
33
+ i18n (1.8.5)
34
+ concurrent-ruby (~> 1.0)
35
+ jmespath (1.4.0)
36
+ net-scp (3.0.0)
37
+ net-ssh (>= 2.6.5, < 7.0.0)
38
+ net-ssh (6.1.0)
39
+ rake (13.0.1)
40
+ sshkit (1.21.0)
41
+ net-scp (>= 1.1.2)
42
+ net-ssh (>= 2.8.0)
43
+
44
+ PLATFORMS
45
+ ruby
46
+
47
+ DEPENDENCIES
48
+ bundler (~> 1.5)
49
+ capistrano3-autoscaling-deploy!
50
+ rake
51
+
52
+ BUNDLED WITH
53
+ 1.12.5
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 Aftab Akram
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
+ # capistrano3-asg-deploy
2
+ Capistrano 3 plugin for AWS Auto Scaling deploys.
3
+
4
+ This is a fork of [marcoschicote/capistrano3-autoscaling-deploy](https://github.com/marcoschicote/capistrano3-autoscaling-deploy), updated with new features and Capistrano 3 conventions.
5
+
6
+ I'm mainly building this gem as the author for the above gem hasen't update the code with aws-sdk-3 changes
7
+
8
+ ## Requirements
9
+
10
+ * aws-sdk-ec2 ~> 1
11
+ * aws-sdk-autoscaling ~> 1
12
+ * capistrano ~> 3
13
+
14
+
15
+ ## Installation
16
+
17
+ Add this line to your application's Gemfile:
18
+
19
+ gem 'capistrano3-asg-deploy'
20
+
21
+ And then execute:
22
+
23
+ $ bundle install
24
+
25
+ Or install it yourself as:
26
+
27
+ $ gem install capistrano3-asg-deploy
28
+
29
+ Add this line to your application's Capfile:
30
+
31
+ ```ruby
32
+ require 'capistrano/autoscaling_deploy'
33
+ ```
34
+
35
+ ## Usage
36
+
37
+ Set credentials with AmazonEC2FullAccess permission in the capistrano deploy script / stage files add the following lines
38
+
39
+ ```ruby
40
+ set :aws_region, 'ap-northeast-1'
41
+ set :aws_access_key_id, 'YOUR AWS KEY ID'
42
+ set :aws_secret_access_key, 'YOUR AWS SECRET KEY'
43
+ set :aws_autoscaling_group_name, 'YOUR NAME OF AUTO SCALING GROUP NAME'
44
+ set :aws_deploy_roles, [:app, :web, :db]
45
+ set :aws_deploy_user, 'USER FOR SSH CONNECTION'
46
+
47
+ invoke 'autoscaling_deploy:setup_instances'
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 group 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 ( https://github.com/Aftab-Akram/capistrano3-asg-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,29 @@
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-asg-deploy'
8
+ spec.version = Capistrano::AutoScalingDeploy::VERSION
9
+ spec.authors = ['Aftab Akram']
10
+ spec.email = ['aftabakram04@gmail.com']
11
+ spec.summary = %q{Deploy to AWS Auto Scaling group.}
12
+ spec.description = %q{Get all instances in an AutoScaling group by AutoScaling group name.}
13
+ spec.homepage = 'https://github.com/Aftab-Akram/capistrano3-asg-deploy'
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_development_dependency 'bundler', '~> 1.3'
22
+ spec.add_development_dependency 'rake'
23
+
24
+ spec.add_dependency 'aws-sdk-ec2', '~> 1'
25
+ spec.add_dependency 'aws-sdk-autoscaling', '~> 1'
26
+ spec.add_dependency 'capistrano', '> 3.0.0'
27
+ spec.add_dependency 'activesupport', '>= 4.0.0'
28
+ spec.add_dependency 'capistrano-bundler', '~> 2'
29
+ end
@@ -0,0 +1 @@
1
+ load File.expand_path('../../tasks/autoscaling.rake', __FILE__)
@@ -0,0 +1,5 @@
1
+ module Capistrano
2
+ module AutoScalingDeploy
3
+ VERSION = '1.0.1'
4
+ end
5
+ end
@@ -0,0 +1,2 @@
1
+ require 'capistrano/bundler'
2
+ load File.expand_path('../tasks/autoscaling.rake', __FILE__)
@@ -0,0 +1,97 @@
1
+ require 'active_support'
2
+ require 'active_support/time'
3
+
4
+ require 'aws-sdk-ec2'
5
+ require 'aws-sdk-autoscaling'
6
+
7
+ namespace :load do
8
+ task :defaults do
9
+ set :aws_autoscaling, true
10
+ set :aws_region, 'ap-northeast-1'
11
+ set :aws_deploy_roles, [:app, :web, :db]
12
+ set :aws_autoscale_ami_prefix, ''
13
+ end
14
+ end
15
+
16
+ namespace :deploy do
17
+ before :starting, :check_autoscaling_hooks do
18
+ invoke 'autoscaling_deploy:setup_instances' if fetch(:aws_autoscaling)
19
+ end
20
+ end
21
+
22
+ namespace :autoscaling_deploy do
23
+ desc 'Add server from Auto Scaling Group.'
24
+ task :setup_instances do
25
+ ec2_instances = fetch_ec2_instances
26
+ aws_deploy_roles = fetch(:aws_deploy_roles)
27
+ aws_deploy_user = fetch(:aws_deploy_user)
28
+
29
+ ec2_instances.each { |instance|
30
+ if ec2_instances.first == instance
31
+ server instance, user: aws_deploy_user, roles: aws_deploy_roles, primary: true
32
+ puts("First Server: #{instance} - #{aws_deploy_roles}")
33
+ else
34
+ server instance, user: aws_deploy_user, roles: sanitize_roles(aws_deploy_roles)
35
+ puts("Server: #{instance} - #{sanitize_roles(aws_deploy_roles)}")
36
+ end
37
+ }
38
+ end
39
+
40
+ def fetch_ec2_instances
41
+ region = fetch(:aws_region)
42
+ key = fetch(:aws_access_key_id)
43
+ secret = fetch(:aws_secret_access_key)
44
+ group_name = fetch(:aws_autoscaling_group_name)
45
+ puts("Fetching servers for Auto Scaling Group: #{group_name}")
46
+
47
+ instances = get_instances_ip(region, key, secret, group_name)
48
+
49
+ puts("Found #{instances.count} servers (#{instances.join(' , ')}) for Auto Scaling Group: #{group_name} ")
50
+
51
+ instances
52
+ end
53
+
54
+ # Get Autoscale Group Healthy Instance Public IP's
55
+ def get_instances_ip(region, key, secret, group_name)
56
+ credentials = {
57
+ region: region,
58
+ credentials: Aws::Credentials.new(key, secret)
59
+ }
60
+ instances_of_as = get_instances(credentials, group_name)
61
+ autoscaling_dns = []
62
+ ec2 = Aws::EC2::Resource.new(credentials)
63
+
64
+ instances_of_as.each do |instance|
65
+ if instance.health_status != 'Healthy'
66
+ puts "Autoscaling: Skipping unhealthy instance #{instance.instance_id}"
67
+ else
68
+ autoscaling_dns << ec2.instance(instance.instance_id).public_ip_address
69
+ end
70
+ end
71
+
72
+ autoscaling_dns
73
+ end
74
+
75
+ # Get Autoscale Group Instance Info
76
+ def get_instances(credentials, group_name)
77
+ as = Aws::AutoScaling::Client.new(credentials)
78
+ instances_of_as = as.describe_auto_scaling_groups(
79
+ auto_scaling_group_names: [group_name],
80
+ max_records: 1,
81
+ ).auto_scaling_groups[0].instances
82
+
83
+ instances_of_as
84
+ end
85
+
86
+ # remove :db (for migrations), remove :primary => :true (for assets precompile) for primary server
87
+ def sanitize_roles(roles)
88
+ roles.inject([]) { |acc, role|
89
+ if !role.is_a?(Hash)
90
+ acc << role if role != :db
91
+ else
92
+ acc << role.reject { |k, v| k == :primary }
93
+ end
94
+ acc
95
+ }
96
+ end
97
+ 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,155 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano3-asg-deploy
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Aftab Akram
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-09-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: aws-sdk-ec2
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: aws-sdk-autoscaling
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1'
69
+ - !ruby/object:Gem::Dependency
70
+ name: capistrano
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">"
74
+ - !ruby/object:Gem::Version
75
+ version: 3.0.0
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">"
81
+ - !ruby/object:Gem::Version
82
+ version: 3.0.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: activesupport
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: 4.0.0
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: 4.0.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: capistrano-bundler
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '2'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '2'
111
+ description: Get all instances in an AutoScaling group by AutoScaling group name.
112
+ email:
113
+ - aftabakram04@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - Gemfile
120
+ - Gemfile.lock
121
+ - LICENSE
122
+ - README.md
123
+ - Rakefile
124
+ - capistrano3-asg-deploy.gemspec
125
+ - lib/capistrano/autoscaling_deploy.rb
126
+ - lib/capistrano/autoscaling_deploy/autoscaling_deploy.rb
127
+ - lib/capistrano/autoscaling_deploy/version.rb
128
+ - lib/capistrano/tasks/autoscaling.rake
129
+ - lib/capistrano3-asg-deploy.rb
130
+ - test/autoscaling_test.rb
131
+ homepage: https://github.com/Aftab-Akram/capistrano3-asg-deploy
132
+ licenses:
133
+ - MIT
134
+ metadata: {}
135
+ post_install_message:
136
+ rdoc_options: []
137
+ require_paths:
138
+ - lib
139
+ required_ruby_version: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - ">="
142
+ - !ruby/object:Gem::Version
143
+ version: '0'
144
+ required_rubygems_version: !ruby/object:Gem::Requirement
145
+ requirements:
146
+ - - ">="
147
+ - !ruby/object:Gem::Version
148
+ version: '0'
149
+ requirements: []
150
+ rubygems_version: 3.0.6
151
+ signing_key:
152
+ specification_version: 4
153
+ summary: Deploy to AWS Auto Scaling group.
154
+ test_files:
155
+ - test/autoscaling_test.rb