capistrano3-asg-ami 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.
- checksums.yaml +7 -0
- data/.gitignore +53 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +69 -0
- data/LICENSE +21 -0
- data/README.md +83 -0
- data/Rakefile +1 -0
- data/capistrano3-asg-ami.gemspec +29 -0
- data/lib/capistrano/autoscaling/autoscaling.rb +1 -0
- data/lib/capistrano/autoscaling/version.rb +5 -0
- data/lib/capistrano/autoscaling.rb +2 -0
- data/lib/capistrano/tasks/autoscaling.rake +136 -0
- data/lib/capistrano3-asg-ami.rb +0 -0
- data/test/autoscaling_test.rb +18 -0
- metadata +156 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: f05db1b87ff821af3c5662e1b9254aaceb8003441274dd0db07ca89413ff9329
|
|
4
|
+
data.tar.gz: bfc831f2669d3e7a561086a5848a27b3d4edfe7eeadf94cf3bc4469d7b3b2b4f
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: ab3f284e86c3e951f273747771f53e6e9fc7d694b0e13f96447c1611337317b71d623fbd85b0c88d828748ea2790ddb974b75fad0bd349b52c84ecd95042e479
|
|
7
|
+
data.tar.gz: 4c2e9a1d1c2f324dff6d7cbd201b7c857cec533cb7fae1cd54b45acdea6e24500b32cf058546e7a0b8062bd7065c2ea3b8968790d18c83788cf11a59e5dbd88b
|
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
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
capistrano3-asg-ami (1.0.0)
|
|
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.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.1.0)
|
|
23
|
+
aws-partitions (1.430.0)
|
|
24
|
+
aws-sdk-autoscaling (1.55.0)
|
|
25
|
+
aws-sdk-core (~> 3, >= 3.112.0)
|
|
26
|
+
aws-sigv4 (~> 1.1)
|
|
27
|
+
aws-sdk-core (3.112.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.225.0)
|
|
33
|
+
aws-sdk-core (~> 3, >= 3.112.0)
|
|
34
|
+
aws-sigv4 (~> 1.1)
|
|
35
|
+
aws-sigv4 (1.2.2)
|
|
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.8)
|
|
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.3)
|
|
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-asg-ami!
|
|
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,83 @@
|
|
|
1
|
+
[](http://badge.fury.io/rb/capistrano3-asg-ami)
|
|
2
|
+
# capistrano3-asg-ami
|
|
3
|
+
Capistrano 3 plugin for updating AWS [Launch Template](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-launch-templates.html) [AMI](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AMIs.html) with [autoscale group](https://aws.amazon.com/about-aws/whats-new/2018/01/introducing-aws-auto-scaling/) first healthy instance.
|
|
4
|
+
|
|
5
|
+
## Requirements
|
|
6
|
+
|
|
7
|
+
* aws-sdk-ec2 ~> 1
|
|
8
|
+
* aws-sdk-autoscaling ~> 1
|
|
9
|
+
* capistrano ~> 3
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
Add this line to your application's Gemfile:
|
|
15
|
+
|
|
16
|
+
gem 'capistrano3-asg-ami'
|
|
17
|
+
|
|
18
|
+
And then execute:
|
|
19
|
+
|
|
20
|
+
$ bundle install
|
|
21
|
+
|
|
22
|
+
Or install it yourself as:
|
|
23
|
+
|
|
24
|
+
$ gem install capistrano3-asg-ami
|
|
25
|
+
|
|
26
|
+
Add this line to your application's Capfile:
|
|
27
|
+
|
|
28
|
+
```ruby
|
|
29
|
+
require 'capistrano/autoscaling'
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Usage
|
|
33
|
+
|
|
34
|
+
Create [IAM](https://docs.aws.amazon.com/IAM/latest/UserGuide/introduction.html) with [AmazonEC2FullAccess](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_examples_ec2_region.html) permission and Set credentials in the capistrano deploy script / stage files add the following lines
|
|
35
|
+
|
|
36
|
+
```ruby
|
|
37
|
+
set :aws_region, 'ap-northeast-1'
|
|
38
|
+
set :aws_access_key_id, 'YOUR AWS KEY ID'
|
|
39
|
+
set :aws_secret_access_key, 'YOUR AWS SECRET KEY'
|
|
40
|
+
set :aws_autoscaling_group_name, 'YOUR NAME OF AUTO SCALING GROUP NAME'
|
|
41
|
+
set :aws_launch_template_id, 'lt-03f39c5689155e374'
|
|
42
|
+
set :aws_autoscale_ami_prefix, 'server-name-'
|
|
43
|
+
set :aws_keep_prev_no_of_ami, 1
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
To call this task after deploy, in your desire capistrano environment file
|
|
47
|
+
add the following in deploy section
|
|
48
|
+
|
|
49
|
+
```ruby
|
|
50
|
+
namespace :deploy do
|
|
51
|
+
after :finishing, 'autoscaling:update_ami'
|
|
52
|
+
end
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
And to update autoscale group launch template manually
|
|
56
|
+
|
|
57
|
+
```ruby
|
|
58
|
+
cap [stage] autoscaling:update_ami
|
|
59
|
+
```
|
|
60
|
+
i.e [stage] can be staging or production
|
|
61
|
+
|
|
62
|
+
## How this works
|
|
63
|
+
|
|
64
|
+
1. Fetch only running instances that have an auto scaling group name you specified
|
|
65
|
+
2. Create AMI with first healthy instance
|
|
66
|
+
3. Tag AMI with autoscale group name
|
|
67
|
+
4. Wait for AMI to be available for use
|
|
68
|
+
5. Update Launch template with update AMI
|
|
69
|
+
6. Deleting stale images base on (aws_keep_prev_no_of_ami) variable
|
|
70
|
+
if not set will only keep the latest one
|
|
71
|
+
and delete the other AMI tagged with autoscale group name
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
## Contributing
|
|
75
|
+
|
|
76
|
+
1. Fork it ( https://github.com/Aftab-Akram/capistrano3-asg-ami/fork )
|
|
77
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
78
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
79
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
|
80
|
+
5. Create new Pull Request
|
|
81
|
+
|
|
82
|
+
To test while developoing just `bundle console` on the project root directory and execute
|
|
83
|
+
`Capistrano::AutoScaling::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/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = 'capistrano3-asg-ami'
|
|
8
|
+
spec.version = Capistrano::AutoScaling::VERSION
|
|
9
|
+
spec.authors = ['Aftab Akram']
|
|
10
|
+
spec.email = ['aftabakram04@gmail.com']
|
|
11
|
+
spec.summary = %q{Capistrano 3 plugin for updating AWS Launch Template AMI}
|
|
12
|
+
spec.description = %q{Capistrano 3 plugin for updating AWS Launch Template AMI with autoscale group first healthy instance.}
|
|
13
|
+
spec.homepage = 'https://github.com/Aftab-Akram/capistrano3-asg-ami'
|
|
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,136 @@
|
|
|
1
|
+
require 'active_support'
|
|
2
|
+
require 'active_support/time'
|
|
3
|
+
|
|
4
|
+
require 'aws-sdk-ec2'
|
|
5
|
+
require 'aws-sdk-autoscaling'
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
namespace :autoscaling do
|
|
9
|
+
|
|
10
|
+
desc 'Update AMI from Auto Scaling Group.'
|
|
11
|
+
task :update_ami do
|
|
12
|
+
region = fetch(:aws_region)
|
|
13
|
+
key = fetch(:aws_access_key_id)
|
|
14
|
+
secret = fetch(:aws_secret_access_key)
|
|
15
|
+
group_name = fetch(:aws_autoscaling_group_name)
|
|
16
|
+
|
|
17
|
+
credentials = {
|
|
18
|
+
region: region,
|
|
19
|
+
credentials: Aws::Credentials.new(key, secret)
|
|
20
|
+
}
|
|
21
|
+
instances_of_as = get_instances(credentials, group_name)
|
|
22
|
+
|
|
23
|
+
instances_of_as.each { |instance|
|
|
24
|
+
if instance.health_status != 'Healthy'
|
|
25
|
+
puts "Autoscaling: Skipping unhealthy instance #{instance.instance_id}"
|
|
26
|
+
else
|
|
27
|
+
update_ami(credentials, instance.instance_id, group_name)
|
|
28
|
+
end
|
|
29
|
+
}
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# Get Autoscale Group Instance Info
|
|
33
|
+
def get_instances(credentials, group_name)
|
|
34
|
+
as = Aws::AutoScaling::Client.new(credentials)
|
|
35
|
+
instances_of_as = as.describe_auto_scaling_groups(
|
|
36
|
+
auto_scaling_group_names: [group_name],
|
|
37
|
+
max_records: 1,
|
|
38
|
+
).auto_scaling_groups[0].instances
|
|
39
|
+
|
|
40
|
+
instances_of_as
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# 1- Create AMI
|
|
44
|
+
# 2- Tag AMI with autoscale group name
|
|
45
|
+
# 3- Wait for AMI to be available for use
|
|
46
|
+
# 4- Update Launch template with update AMI
|
|
47
|
+
# 5- Deleting stale images base on (aws_keep_prev_no_of_ami) variable
|
|
48
|
+
# if not set will only keep the latest one
|
|
49
|
+
# and delete the other AMI tag with autoscale group name
|
|
50
|
+
def update_ami(credentials, instance_id, group_name)
|
|
51
|
+
ec2 = Aws::EC2::Resource.new(credentials)
|
|
52
|
+
ec_instance = ec2.instance(instance_id)
|
|
53
|
+
ami_prefix = fetch(:aws_autoscale_ami_prefix) || ''
|
|
54
|
+
launch_template_id = fetch(:aws_launch_template_id)
|
|
55
|
+
aws_keep_prev_no_of_ami = fetch(:aws_keep_prev_no_of_ami) || 1
|
|
56
|
+
return if launch_template_id.nil?
|
|
57
|
+
return unless fetch(:asg_ami_id).nil?
|
|
58
|
+
|
|
59
|
+
puts "Creating AMI# #{ami_prefix}#{Time.current.strftime("%F--%H-%M")} with first healthy instance"
|
|
60
|
+
resp = ec_instance.create_image(
|
|
61
|
+
name: "#{ami_prefix}#{Time.current.strftime("%F--%H-%M")}",
|
|
62
|
+
)
|
|
63
|
+
set :asg_ami_id, resp.id # Saving AMI ID in current context to avoid duplicate AMI's
|
|
64
|
+
|
|
65
|
+
puts "Tagging AMI# #{ami_prefix}#{Time.current.strftime("%F--%H-%M")} with autoscale group name"
|
|
66
|
+
resp.create_tags({
|
|
67
|
+
tags: [
|
|
68
|
+
{
|
|
69
|
+
key: 'autoscaling_group_name',
|
|
70
|
+
value: group_name
|
|
71
|
+
},
|
|
72
|
+
],
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
puts "\n================================================================="
|
|
76
|
+
puts 'Lanuch Template will only be updated if image is available for use.'
|
|
77
|
+
puts 'In case connection broken, or any unexpected error'
|
|
78
|
+
puts 'Either re-run the script OR update launch template at AWS with latest AMI id when AMI available'
|
|
79
|
+
puts '================================================================='
|
|
80
|
+
puts "\nWating for AMI# #{resp.id} to be available. This will take some time 4-8 minutes(appox) 😴"
|
|
81
|
+
ec2_client = Aws::EC2::Client.new(credentials)
|
|
82
|
+
ec2_client.wait_until(:image_available, { image_ids: [resp.id] })
|
|
83
|
+
|
|
84
|
+
puts "Updating Launch Template# #{launch_template_id} with latest AMI# #{resp.id}"
|
|
85
|
+
ec2_client.create_launch_template_version({
|
|
86
|
+
launch_template_data: {
|
|
87
|
+
image_id: resp.id,
|
|
88
|
+
},
|
|
89
|
+
launch_template_id: launch_template_id,
|
|
90
|
+
source_version: '$Latest',
|
|
91
|
+
version_description: 'updateAMI',
|
|
92
|
+
})
|
|
93
|
+
puts "Launch Template# #{launch_template_id} with latest AMI updated"
|
|
94
|
+
|
|
95
|
+
puts "Keeping #{aws_keep_prev_no_of_ami}# latest AMI's and cleaning the rest"
|
|
96
|
+
cleaning_ami(credentials, group_name)
|
|
97
|
+
puts 'AMI updated Finished'
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def cleaning_ami(credentials, group_name)
|
|
101
|
+
ec2 = Aws::EC2::Resource.new(credentials)
|
|
102
|
+
aws_keep_prev_no_of_ami = fetch(:aws_keep_prev_no_of_ami) || 1
|
|
103
|
+
images = amis_by_group_name_tag(ec2, group_name)
|
|
104
|
+
images = images.sort_by { |x| Date.parse x.creation_date }.reverse
|
|
105
|
+
return unless images.count > aws_keep_prev_no_of_ami
|
|
106
|
+
|
|
107
|
+
images = images[aws_keep_prev_no_of_ami..-1] || []
|
|
108
|
+
images.each do |ami|
|
|
109
|
+
snapshots = snapshots_attached_to(ec2, ami)
|
|
110
|
+
puts "Deleting #{ami.id}# AMI"
|
|
111
|
+
ami.deregister
|
|
112
|
+
|
|
113
|
+
puts "Deleting #{ami.id}# AMI snapshots"
|
|
114
|
+
delete_snapshots(snapshots)
|
|
115
|
+
|
|
116
|
+
puts "#{ami.id}# AMI deleted"
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
def amis_by_group_name_tag(ec2, group_name)
|
|
121
|
+
ec2.images(owners: ['self']).to_a.select do |image|
|
|
122
|
+
image.tags.any? { |k| k.key == 'autoscaling_group_name' && k.value == group_name }
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
def snapshots_attached_to(ec2, image)
|
|
127
|
+
ids = image.block_device_mappings.map(&:ebs).compact.map(&:snapshot_id)
|
|
128
|
+
ec2.snapshots(snapshot_ids: ids)
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
def delete_snapshots(snapshots)
|
|
132
|
+
snapshots.each do |snapshot|
|
|
133
|
+
snapshot.delete unless snapshot.nil?
|
|
134
|
+
end
|
|
135
|
+
end
|
|
136
|
+
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 'autoscaling' do |mock|
|
|
17
|
+
# Do Test
|
|
18
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: capistrano3-asg-ami
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Aftab Akram
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2021-09-18 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: Capistrano 3 plugin for updating AWS Launch Template AMI with autoscale
|
|
112
|
+
group first healthy instance.
|
|
113
|
+
email:
|
|
114
|
+
- aftabakram04@gmail.com
|
|
115
|
+
executables: []
|
|
116
|
+
extensions: []
|
|
117
|
+
extra_rdoc_files: []
|
|
118
|
+
files:
|
|
119
|
+
- ".gitignore"
|
|
120
|
+
- Gemfile
|
|
121
|
+
- Gemfile.lock
|
|
122
|
+
- LICENSE
|
|
123
|
+
- README.md
|
|
124
|
+
- Rakefile
|
|
125
|
+
- capistrano3-asg-ami.gemspec
|
|
126
|
+
- lib/capistrano/autoscaling.rb
|
|
127
|
+
- lib/capistrano/autoscaling/autoscaling.rb
|
|
128
|
+
- lib/capistrano/autoscaling/version.rb
|
|
129
|
+
- lib/capistrano/tasks/autoscaling.rake
|
|
130
|
+
- lib/capistrano3-asg-ami.rb
|
|
131
|
+
- test/autoscaling_test.rb
|
|
132
|
+
homepage: https://github.com/Aftab-Akram/capistrano3-asg-ami
|
|
133
|
+
licenses:
|
|
134
|
+
- MIT
|
|
135
|
+
metadata: {}
|
|
136
|
+
post_install_message:
|
|
137
|
+
rdoc_options: []
|
|
138
|
+
require_paths:
|
|
139
|
+
- lib
|
|
140
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
141
|
+
requirements:
|
|
142
|
+
- - ">="
|
|
143
|
+
- !ruby/object:Gem::Version
|
|
144
|
+
version: '0'
|
|
145
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
146
|
+
requirements:
|
|
147
|
+
- - ">="
|
|
148
|
+
- !ruby/object:Gem::Version
|
|
149
|
+
version: '0'
|
|
150
|
+
requirements: []
|
|
151
|
+
rubygems_version: 3.0.6
|
|
152
|
+
signing_key:
|
|
153
|
+
specification_version: 4
|
|
154
|
+
summary: Capistrano 3 plugin for updating AWS Launch Template AMI
|
|
155
|
+
test_files:
|
|
156
|
+
- test/autoscaling_test.rb
|