capistrano3-autoscaling-deploy 2.0.1 → 2.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 +4 -4
- data/CHANGELOG.md +13 -1
- data/README.md +5 -2
- data/lib/capistrano/autoscaling_deploy/version.rb +1 -1
- data/lib/capistrano/autoscaling_deploy.rb +1 -1
- data/lib/capistrano/helpers/aws_helper.rb +11 -17
- data/lib/capistrano/helpers/cap_helper.rb +9 -9
- data/lib/capistrano/tasks/autoscaling.rake +11 -12
- metadata +16 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: cb77459b46142752dfd7581d1d48ff28070b6c7c7b53fa8ed73f4916d41c4667
|
|
4
|
+
data.tar.gz: 7229de6d7283a8936089bb91e1d980fda0fc030b32429cf20257f2a33c19f6b6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 895e0b17df6ef8d4533253eac825511ea172dd18f288215e4399638efed547cdf04ff3d620cd6c648879d14f54e13bf2f09269a94ff8401d4bd7513c350e8fdc
|
|
7
|
+
data.tar.gz: d2d9fc5db891587176762daecc32cf4ad3cc6f9df86bfc0c700c8f6b318ba0a198f6067b7e7706f248aeaa1fc974a633b1a72d1ba67ab0e6f9e8b6113c231652
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 2.0.2
|
|
4
|
+
|
|
5
|
+
No changes to how the plugin works.
|
|
6
|
+
|
|
7
|
+
### Changed
|
|
8
|
+
- The gem's changelog link on RubyGems now points to the `main` branch, which replaced `master`.
|
|
9
|
+
|
|
10
|
+
### Development
|
|
11
|
+
- Code style is checked with Standard Ruby in CI.
|
|
12
|
+
- CodeQL and OpenSSF Scorecard scan the code and workflows, and GitHub Actions are pinned to commit SHAs.
|
|
13
|
+
- Added a security policy (`SECURITY.md`).
|
|
14
|
+
|
|
3
15
|
## 2.0.1
|
|
4
16
|
|
|
5
17
|
### Fixed
|
|
@@ -36,4 +48,4 @@ First release since 1.6 (2017). See [Upgrading to 2.0](README.md#upgrading-to-20
|
|
|
36
48
|
|
|
37
49
|
## 1.6 and earlier
|
|
38
50
|
|
|
39
|
-
See the [commit history](https://github.com/marcoschicote/capistrano3-autoscaling-deploy/commits/
|
|
51
|
+
See the [commit history](https://github.com/marcoschicote/capistrano3-autoscaling-deploy/commits/main).
|
data/README.md
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
[](https://rubygems.org/gems/capistrano3-autoscaling-deploy)
|
|
2
2
|
[](https://github.com/marcoschicote/capistrano3-autoscaling-deploy/actions/workflows/test.yml)
|
|
3
|
+
[](https://scorecard.dev/viewer/?uri=github.com/marcoschicote/capistrano3-autoscaling-deploy)
|
|
3
4
|
|
|
4
5
|
# capistrano3-autoscaling-deploy
|
|
5
6
|
|
|
@@ -123,9 +124,11 @@ See [CHANGELOG.md](CHANGELOG.md) for all changes.
|
|
|
123
124
|
|
|
124
125
|
Run the tests with `bundle exec rake test`. They use the AWS SDK's stubbed responses, so they don't need AWS credentials or network access.
|
|
125
126
|
|
|
127
|
+
The code follows [Standard Ruby](https://github.com/standardrb/standard). Check it with `bundle exec rake standard`, or fix most offenses with `bundle exec standardrb --fix`. Running `bundle exec rake` does both the tests and the style check.
|
|
128
|
+
|
|
126
129
|
## Releasing
|
|
127
130
|
|
|
128
131
|
Releases are published to RubyGems from GitHub Actions using [trusted publishing](https://guides.rubygems.org/trusted-publishing/), so no API key is stored anywhere.
|
|
129
132
|
|
|
130
|
-
1. Update the version in `lib/capistrano/autoscaling_deploy/version.rb` and add a section to `CHANGELOG.md`, and merge them to `
|
|
131
|
-
2. In the repository's **Actions** tab, run the **Release** workflow on `
|
|
133
|
+
1. Update the version in `lib/capistrano/autoscaling_deploy/version.rb` and add a section to `CHANGELOG.md`, and merge them to `main`.
|
|
134
|
+
2. In the repository's **Actions** tab, run the **Release** workflow on `main`. It runs the tests, builds the gem, pushes the `vX.Y.Z` tag and publishes the gem.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
load File.expand_path(
|
|
1
|
+
load File.expand_path("../tasks/autoscaling.rake", __FILE__)
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
require
|
|
2
|
-
require
|
|
1
|
+
require "aws-sdk-autoscaling"
|
|
2
|
+
require "aws-sdk-ec2"
|
|
3
3
|
|
|
4
4
|
module AwsHelper
|
|
5
|
-
IP_TYPES = %w
|
|
6
|
-
LIFECYCLE_STATES = %w
|
|
5
|
+
IP_TYPES = %w[public_ip_address public_dns_name private_ip_address private_dns_name]
|
|
6
|
+
LIFECYCLE_STATES = %w[InService]
|
|
7
7
|
|
|
8
8
|
def get_instances(aws_region, aws_access_key_id, aws_secret_access_key, aws_autoscaling_group_name, aws_ip_type, aws_profile: nil, lifecycle_states: LIFECYCLE_STATES)
|
|
9
9
|
client_options = aws_client_options(aws_region, aws_access_key_id, aws_secret_access_key, aws_profile)
|
|
@@ -14,12 +14,12 @@ module AwsHelper
|
|
|
14
14
|
# credential chain is used: environment variables, shared config and
|
|
15
15
|
# credentials files, SSO, and ECS or EC2 instance roles.
|
|
16
16
|
def aws_client_options(aws_region, aws_access_key_id, aws_secret_access_key, aws_profile = nil)
|
|
17
|
-
options = {
|
|
17
|
+
options = {region: aws_region}
|
|
18
18
|
|
|
19
19
|
if aws_access_key_id && aws_secret_access_key
|
|
20
20
|
options[:credentials] = Aws::Credentials.new(aws_access_key_id, aws_secret_access_key)
|
|
21
21
|
elsif aws_access_key_id || aws_secret_access_key
|
|
22
|
-
raise ArgumentError,
|
|
22
|
+
raise ArgumentError, "Set both :aws_access_key_id and :aws_secret_access_key, or neither to use the default AWS credential chain"
|
|
23
23
|
elsif aws_profile
|
|
24
24
|
options[:profile] = aws_profile
|
|
25
25
|
end
|
|
@@ -42,8 +42,7 @@ module AwsHelper
|
|
|
42
42
|
else
|
|
43
43
|
instance_ids = instances.map(&:instance_id)
|
|
44
44
|
ec2 = Aws::EC2::Client.new(client_options)
|
|
45
|
-
|
|
46
|
-
aws_ip_type = 'public_dns_name' unless IP_TYPES.include? aws_ip_type
|
|
45
|
+
aws_ip_type = "public_dns_name" unless IP_TYPES.include? aws_ip_type
|
|
47
46
|
|
|
48
47
|
ec2_instances = ec2.describe_instances(instance_ids: instance_ids).flat_map do |page|
|
|
49
48
|
page.reservations.flat_map(&:instances)
|
|
@@ -57,8 +56,8 @@ module AwsHelper
|
|
|
57
56
|
# e.g. public_dns_name is empty for instances in a private subnet
|
|
58
57
|
blank_ids = instance_ids.zip(autoscaling_dns).select { |_, address| address.to_s.strip.empty? }.map(&:first)
|
|
59
58
|
unless blank_ids.empty?
|
|
60
|
-
raise "Instances #{blank_ids.join(
|
|
61
|
-
"Set :aws_ip_type to one of #{IP_TYPES.join(
|
|
59
|
+
raise "Instances #{blank_ids.join(", ")} have no #{aws_ip_type}. " \
|
|
60
|
+
"Set :aws_ip_type to one of #{IP_TYPES.join(", ")} (private_ip_address for instances without public addresses)"
|
|
62
61
|
end
|
|
63
62
|
end
|
|
64
63
|
|
|
@@ -68,18 +67,13 @@ module AwsHelper
|
|
|
68
67
|
def fetch_autoscaling_group_instances(client_options, autoscaling_group_name)
|
|
69
68
|
as = Aws::AutoScaling::Client.new(client_options)
|
|
70
69
|
as_groups = as.describe_auto_scaling_groups(
|
|
71
|
-
|
|
72
|
-
|
|
70
|
+
auto_scaling_group_names: [autoscaling_group_name],
|
|
71
|
+
max_records: 1
|
|
73
72
|
).auto_scaling_groups
|
|
74
73
|
|
|
75
|
-
# info("Auto Scaling Groups: #{as_groups}")
|
|
76
|
-
|
|
77
74
|
as_group = as_groups[0]
|
|
78
75
|
raise "Auto Scaling group '#{autoscaling_group_name}' not found in #{client_options[:region]}" unless as_group
|
|
79
76
|
|
|
80
|
-
# info("Auto Scaling Group instances: #{as_group.instances}")
|
|
81
|
-
|
|
82
77
|
as_group.instances
|
|
83
78
|
end
|
|
84
|
-
|
|
85
79
|
end
|
|
@@ -4,15 +4,15 @@ module CapHelper
|
|
|
4
4
|
roles.map { |role| role.is_a?(String) ? role.to_sym : role }
|
|
5
5
|
end
|
|
6
6
|
|
|
7
|
+
# Roles for every instance but the first: no :db (for migrations) and
|
|
8
|
+
# no primary: true (for assets precompile)
|
|
7
9
|
def sanitize_roles(roles)
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
acc << role.reject{|k,v| k == :primary}
|
|
10
|
+
symbolize_roles(roles).filter_map do |role|
|
|
11
|
+
if role.is_a?(Hash)
|
|
12
|
+
role.except(:primary)
|
|
13
|
+
elsif role != :db
|
|
14
|
+
role
|
|
14
15
|
end
|
|
15
|
-
|
|
16
|
-
}
|
|
16
|
+
end
|
|
17
17
|
end
|
|
18
|
-
end
|
|
18
|
+
end
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
require
|
|
2
|
-
require
|
|
1
|
+
require "capistrano/helpers/aws_helper"
|
|
2
|
+
require "capistrano/helpers/cap_helper"
|
|
3
3
|
|
|
4
4
|
namespace :load do
|
|
5
5
|
task :defaults do
|
|
6
6
|
set :aws_autoscaling, true
|
|
7
|
-
set :aws_region,
|
|
8
|
-
set :aws_deploy_roles, %i
|
|
9
|
-
set :aws_ip_type,
|
|
7
|
+
set :aws_region, "us-west-2"
|
|
8
|
+
set :aws_deploy_roles, %i[web app db]
|
|
9
|
+
set :aws_ip_type, "public_dns_name"
|
|
10
10
|
set :aws_lifecycle_states, AwsHelper::LIFECYCLE_STATES
|
|
11
11
|
end
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
namespace :deploy do
|
|
15
15
|
before :starting, :check_autoscaling_hooks do
|
|
16
|
-
invoke
|
|
16
|
+
invoke "autoscaling_deploy:setup_instances" if fetch(:aws_autoscaling)
|
|
17
17
|
end
|
|
18
18
|
end
|
|
19
19
|
|
|
@@ -21,13 +21,13 @@ namespace :autoscaling_deploy do
|
|
|
21
21
|
include AwsHelper
|
|
22
22
|
include CapHelper
|
|
23
23
|
|
|
24
|
-
desc
|
|
24
|
+
desc "Add server from Auto Scaling Group."
|
|
25
25
|
task :setup_instances do
|
|
26
26
|
ec2_instances = fetch_ec2_instances
|
|
27
27
|
aws_deploy_roles = symbolize_roles(fetch(:aws_deploy_roles))
|
|
28
28
|
aws_deploy_user = fetch(:aws_deploy_user)
|
|
29
29
|
|
|
30
|
-
ec2_instances.each_with_index {|instance, index|
|
|
30
|
+
ec2_instances.each_with_index { |instance, index|
|
|
31
31
|
if index == 0
|
|
32
32
|
server instance, user: aws_deploy_user, roles: aws_deploy_roles, primary: true
|
|
33
33
|
puts("First Server: #{instance} - #{aws_deploy_roles}")
|
|
@@ -36,7 +36,6 @@ namespace :autoscaling_deploy do
|
|
|
36
36
|
puts("Server: #{instance} - #{sanitize_roles(aws_deploy_roles)}")
|
|
37
37
|
end
|
|
38
38
|
}
|
|
39
|
-
|
|
40
39
|
end
|
|
41
40
|
|
|
42
41
|
def fetch_ec2_instances
|
|
@@ -51,11 +50,11 @@ namespace :autoscaling_deploy do
|
|
|
51
50
|
instances = get_instances(region, key, secret, group_name, ip_type, aws_profile: profile, lifecycle_states: lifecycle_states)
|
|
52
51
|
|
|
53
52
|
if instances.empty?
|
|
54
|
-
raise "No instances in Auto Scaling group '#{group_name}' with lifecycle state #{lifecycle_states.join(
|
|
53
|
+
raise "No instances in Auto Scaling group '#{group_name}' with lifecycle state #{lifecycle_states.join(" or ")}"
|
|
55
54
|
end
|
|
56
55
|
|
|
57
|
-
puts("Found #{instances.count} servers (#{instances.join(
|
|
56
|
+
puts("Found #{instances.count} servers (#{instances.join(",")}) for Auto Scaling Group: #{group_name} ")
|
|
58
57
|
|
|
59
58
|
instances
|
|
60
59
|
end
|
|
61
|
-
end
|
|
60
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: capistrano3-autoscaling-deploy
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.0.
|
|
4
|
+
version: 2.0.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Marcos Chicote
|
|
@@ -93,6 +93,20 @@ dependencies:
|
|
|
93
93
|
- - ">="
|
|
94
94
|
- !ruby/object:Gem::Version
|
|
95
95
|
version: '0'
|
|
96
|
+
- !ruby/object:Gem::Dependency
|
|
97
|
+
name: standard
|
|
98
|
+
requirement: !ruby/object:Gem::Requirement
|
|
99
|
+
requirements:
|
|
100
|
+
- - ">="
|
|
101
|
+
- !ruby/object:Gem::Version
|
|
102
|
+
version: '0'
|
|
103
|
+
type: :development
|
|
104
|
+
prerelease: false
|
|
105
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
106
|
+
requirements:
|
|
107
|
+
- - ">="
|
|
108
|
+
- !ruby/object:Gem::Version
|
|
109
|
+
version: '0'
|
|
96
110
|
description: Capistrano 3 plugin that finds the in-service instances of an AWS Auto
|
|
97
111
|
Scaling group and deploys to them.
|
|
98
112
|
email:
|
|
@@ -115,7 +129,7 @@ licenses:
|
|
|
115
129
|
- MIT
|
|
116
130
|
metadata:
|
|
117
131
|
source_code_uri: https://github.com/marcoschicote/capistrano3-autoscaling-deploy
|
|
118
|
-
changelog_uri: https://github.com/marcoschicote/capistrano3-autoscaling-deploy/blob/
|
|
132
|
+
changelog_uri: https://github.com/marcoschicote/capistrano3-autoscaling-deploy/blob/main/CHANGELOG.md
|
|
119
133
|
bug_tracker_uri: https://github.com/marcoschicote/capistrano3-autoscaling-deploy/issues
|
|
120
134
|
rubygems_mfa_required: 'true'
|
|
121
135
|
rdoc_options: []
|