capistrano3-aws-asg-deploy 1.0.2

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: 5c0ff2751f645519ab855d88cb3ca43301f1c72f92de6b37fcb63625896896a8
4
+ data.tar.gz: edbac2f60cc2bf5ac30beea377d9cd9e6161cc5bf2f55e1cf3730c5dfb7e0556
5
+ SHA512:
6
+ metadata.gz: f000fdb73e382cddc849584e2ca9de7891f43f921b26f51738b5f837e172664b896b6d06b6522785206a33c971b2ae1e62cf718286f09b5aa23eee5472b95712
7
+ data.tar.gz: 5daea3f3347c3f4b98a08cdde03b12856bbb635ffa7fcea0e1b2e537f389f644c23d31b197e1b5ffc6b48f5bf1d3f68a1a68fdd2a753cf2421fd3259d740de3f
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 capistrano3-aws-asg-deploy.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,69 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ capistrano3-aws-asg-deploy (1.0.2)
5
+ activesupport (>= 4.0.0)
6
+ aws-sdk-autoscaling (~> 1)
7
+ aws-sdk-ec2 (~> 1)
8
+ capistrano (> 3.0.0)
9
+ capistrano-bundler (~> 2)
10
+
11
+ GEM
12
+ remote: http://rubygems.org/
13
+ specs:
14
+ activesupport (6.1.4.1)
15
+ concurrent-ruby (~> 1.0, >= 1.0.2)
16
+ i18n (>= 1.6, < 2)
17
+ minitest (>= 5.1)
18
+ tzinfo (~> 2.0)
19
+ zeitwerk (~> 2.3)
20
+ airbrussh (1.4.0)
21
+ sshkit (>= 1.6.1, != 1.7.0)
22
+ aws-eventstream (1.2.0)
23
+ aws-partitions (1.500.0)
24
+ aws-sdk-autoscaling (1.68.0)
25
+ aws-sdk-core (~> 3, >= 3.120.0)
26
+ aws-sigv4 (~> 1.1)
27
+ aws-sdk-core (3.121.0)
28
+ aws-eventstream (~> 1, >= 1.0.2)
29
+ aws-partitions (~> 1, >= 1.239.0)
30
+ aws-sigv4 (~> 1.1)
31
+ jmespath (~> 1.0)
32
+ aws-sdk-ec2 (1.261.0)
33
+ aws-sdk-core (~> 3, >= 3.120.0)
34
+ aws-sigv4 (~> 1.1)
35
+ aws-sigv4 (1.4.0)
36
+ aws-eventstream (~> 1, >= 1.0.2)
37
+ capistrano (3.16.0)
38
+ airbrussh (>= 1.0.0)
39
+ i18n
40
+ rake (>= 10.0.0)
41
+ sshkit (>= 1.9.0)
42
+ capistrano-bundler (2.0.1)
43
+ capistrano (~> 3.1)
44
+ concurrent-ruby (1.1.9)
45
+ i18n (1.8.10)
46
+ concurrent-ruby (~> 1.0)
47
+ jmespath (1.4.0)
48
+ minitest (5.14.4)
49
+ net-scp (3.0.0)
50
+ net-ssh (>= 2.6.5, < 7.0.0)
51
+ net-ssh (6.1.0)
52
+ rake (13.0.6)
53
+ sshkit (1.21.2)
54
+ net-scp (>= 1.1.2)
55
+ net-ssh (>= 2.8.0)
56
+ tzinfo (2.0.4)
57
+ concurrent-ruby (~> 1.0)
58
+ zeitwerk (2.4.2)
59
+
60
+ PLATFORMS
61
+ ruby
62
+
63
+ DEPENDENCIES
64
+ bundler (~> 2.1.4)
65
+ capistrano3-aws-asg-deploy!
66
+ rake
67
+
68
+ BUNDLED WITH
69
+ 2.1.4
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,80 @@
1
+ [![Gem Downloads](http://img.shields.io/gem/dt/capistrano3-asg-deploy.svg)](https://rubygems.org/gems/capistrano3-asg-deploy) [![Gem Version](https://badge.fury.io/rb/capistrano3-asg-deploy.png)](http://badge.fury.io/rb/capistrano3-asg-deploy) [![MIT license](http://img.shields.io/badge/license-MIT-brightgreen.svg)](http://opensource.org/licenses/MIT)
2
+ # capistrano3-aws-asg-deploy
3
+ Capistrano 3 plugin for AWS Auto Scaling deploys.
4
+
5
+ This is a fork of [Aftab-Akram/capistrano3-asg-deploy](https://github.com/Aftab-Akram/capistrano3-asg-deploy), updated with new features and Capistrano 3 conventions.
6
+
7
+ I'm mainly building this gem to work with private ip address
8
+
9
+ ## Requirements
10
+
11
+ * aws-sdk-ec2 ~> 1
12
+ * aws-sdk-autoscaling ~> 1
13
+ * capistrano ~> 3
14
+
15
+
16
+ ## Installation
17
+
18
+ Add this line to your application's Gemfile:
19
+
20
+ gem 'capistrano3-aws-asg-deploy'
21
+
22
+ And then execute:
23
+
24
+ $ bundle install
25
+
26
+ Or install it yourself as:
27
+
28
+ $ gem install capistrano3-aws-asg-deploy
29
+
30
+ Add this line to your application's Capfile:
31
+
32
+ ```ruby
33
+ require 'capistrano/autoscaling_deploy'
34
+ ```
35
+
36
+ ## Usage
37
+
38
+ Set credentials with AmazonEC2FullAccess permission in the capistrano deploy script / stage files add the following lines
39
+
40
+ ```ruby
41
+ set :aws_region, 'ap-northeast-1'
42
+ set :aws_access_key_id, 'YOUR AWS KEY ID'
43
+ set :aws_secret_access_key, 'YOUR AWS SECRET KEY'
44
+ set :aws_autoscaling_group_name, 'YOUR NAME OF AUTO SCALING GROUP NAME'
45
+ set :aws_deploy_roles, [:app, :web, :db]
46
+ set :aws_deploy_user, 'USER FOR SSH CONNECTION'
47
+
48
+ invoke 'autoscaling_deploy:setup_instances'
49
+ ```
50
+
51
+ you can add more auto scaling configs to deploy to multiple auto scaling groups like a cluster
52
+
53
+ ## How this works
54
+
55
+ This gem will fetch only running instances that have an auto scaling group name you specified
56
+
57
+ It will then reject the roles of :db and the :primary => true for all servers found **but the first one**
58
+
59
+ (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)
60
+
61
+ this is to make sure a single working task does not run in parallel
62
+
63
+ you end up as if you defined the servers yourself like so:
64
+
65
+ ````ruby
66
+ server ip_address1, :app, :db, :web, :primary => true
67
+ server ip_address2, :app, :web
68
+ server ip_address3, :app, :web
69
+ ````
70
+
71
+ ## Contributing
72
+
73
+ 1. Fork it ( https://github.com/maximbaibakov/capistrano3-aws-asg-deploy/fork )
74
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
75
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
76
+ 4. Push to the branch (`git push origin my-new-feature`)
77
+ 5. Create new Pull Request
78
+
79
+ To test while developoing just `bundle console` on the project root directory and execute
80
+ `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-aws-asg-deploy'
8
+ spec.version = Capistrano::AutoScalingDeploy::VERSION
9
+ spec.authors = ['Maxim Baibakov']
10
+ spec.email = ['maxim.baibakov@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/maximbaibakov/capistrano3-aws-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', '~> 2.1.4'
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.2'
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 Private 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).private_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-aws-asg-deploy
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Maxim Baibakov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-04-13 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: 2.1.4
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 2.1.4
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
+ - maxim.baibakov@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-aws-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-aws-asg-deploy.rb
130
+ - test/autoscaling_test.rb
131
+ homepage: https://github.com/maximbaibakov/capistrano3-aws-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.3.1
151
+ signing_key:
152
+ specification_version: 4
153
+ summary: Deploy to AWS Auto Scaling group.
154
+ test_files:
155
+ - test/autoscaling_test.rb