capistrano3-autoscaling-deploy 2.0.0 → 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 +22 -1
- data/README.md +71 -68
- data/lib/capistrano/autoscaling_deploy/version.rb +1 -1
- data/lib/capistrano/autoscaling_deploy.rb +1 -1
- data/lib/capistrano/helpers/aws_helper.rb +16 -15
- data/lib/capistrano/helpers/cap_helper.rb +9 -9
- data/lib/capistrano/tasks/autoscaling.rake +12 -13
- metadata +16 -3
- data/lib/capistrano/autoscaling_deploy/autoscaling_deploy.rb +0 -1
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,26 @@
|
|
|
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
|
+
|
|
15
|
+
## 2.0.1
|
|
16
|
+
|
|
17
|
+
### Fixed
|
|
18
|
+
- Instances without an address for `aws_ip_type` (for example `public_dns_name` in a private subnet) now stop the deploy with an error naming them. Before, they were all registered as one server with an empty hostname, and each was treated as the primary server ([#23](https://github.com/marcoschicote/capistrano3-autoscaling-deploy/issues/23)).
|
|
19
|
+
- The primary server is chosen by position in the Auto Scaling group, not by comparing hostnames ([#23](https://github.com/marcoschicote/capistrano3-autoscaling-deploy/issues/23)).
|
|
20
|
+
|
|
21
|
+
### Removed
|
|
22
|
+
- `lib/capistrano/autoscaling_deploy/autoscaling_deploy.rb`, an unused file that loaded the tasks a second time. Require `capistrano/autoscaling_deploy` in your Capfile, as the README says ([#24](https://github.com/marcoschicote/capistrano3-autoscaling-deploy/issues/24)).
|
|
23
|
+
|
|
3
24
|
## 2.0.0
|
|
4
25
|
|
|
5
26
|
First release since 1.6 (2017). See [Upgrading to 2.0](README.md#upgrading-to-20) before updating.
|
|
@@ -27,4 +48,4 @@ First release since 1.6 (2017). See [Upgrading to 2.0](README.md#upgrading-to-20
|
|
|
27
48
|
|
|
28
49
|
## 1.6 and earlier
|
|
29
50
|
|
|
30
|
-
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,80 +1,62 @@
|
|
|
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)
|
|
4
|
+
|
|
3
5
|
# capistrano3-autoscaling-deploy
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
A lot of inspiration (and code) for how this gem was built come from https://github.com/gtforge/capistrano-autoscale-deploy
|
|
7
|
-
I've also taken suggestions from the opened PRs against such repo.
|
|
8
|
-
|
|
9
|
-
I'm mainly building this gem as the author for the gem above has dissapeared
|
|
10
|
-
and I need an updated version that uses Capistrano 3 and current version of
|
|
11
|
-
AWS CLI.
|
|
6
|
+
|
|
7
|
+
Capistrano 3 plugin that deploys to the instances of an AWS Auto Scaling group. Instead of listing servers in your stage files, the plugin asks AWS which instances are in service at deploy time and adds them as Capistrano servers.
|
|
12
8
|
|
|
13
9
|
## Requirements
|
|
14
10
|
|
|
15
|
-
*
|
|
16
|
-
* aws-sdk-ec2 ~> 1
|
|
11
|
+
* Ruby 3.3 or newer
|
|
17
12
|
* capistrano ~> 3
|
|
18
|
-
|
|
13
|
+
* aws-sdk-autoscaling ~> 1 and aws-sdk-ec2 ~> 1 (installed with the gem)
|
|
19
14
|
|
|
20
15
|
## Installation
|
|
21
16
|
|
|
22
|
-
Add
|
|
23
|
-
|
|
24
|
-
gem 'capistrano3-autoscaling-deploy'
|
|
25
|
-
|
|
26
|
-
And then execute:
|
|
17
|
+
Add the gem to your application's Gemfile:
|
|
27
18
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
19
|
+
```ruby
|
|
20
|
+
gem 'capistrano3-autoscaling-deploy', '~> 2.0'
|
|
21
|
+
```
|
|
31
22
|
|
|
32
|
-
|
|
23
|
+
and run `bundle install`.
|
|
33
24
|
|
|
34
|
-
|
|
25
|
+
Then add this line to your Capfile:
|
|
35
26
|
|
|
36
27
|
```ruby
|
|
37
28
|
require 'capistrano/autoscaling_deploy'
|
|
38
29
|
```
|
|
39
30
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
2.0 uses the current AWS SDK for Ruby (`aws-sdk-autoscaling` and `aws-sdk-ec2`) instead of the retired `aws-sdk` v2, so it no longer installs `aws-sdk` v2. If your own deploy code uses `aws-sdk` v2, add it to your Gemfile or, better, move that code to the current SDK.
|
|
43
|
-
|
|
44
|
-
2.0 only deploys to instances whose lifecycle state is `InService`, and stops with an error if the Auto Scaling group doesn't exist or has no such instances. Before, it deployed to every instance in the group, including ones being launched or terminated, and carried on with no servers if the group was empty. To also deploy to other states, set `aws_lifecycle_states` (for example `%w(InService Standby)`).
|
|
45
|
-
|
|
46
|
-
Versions before 2.0 also loaded [capistrano-bundler](https://github.com/capistrano/bundler), which runs `bundle install` on your servers during deploy. 2.0 no longer does this. If your deploy relies on it, add it to your Gemfile:
|
|
47
|
-
|
|
48
|
-
gem 'capistrano-bundler'
|
|
31
|
+
## Usage
|
|
49
32
|
|
|
50
|
-
|
|
33
|
+
In your deploy script or stage file (for example `config/deploy/production.rb`), set the Auto Scaling group to deploy to:
|
|
51
34
|
|
|
52
35
|
```ruby
|
|
53
|
-
|
|
36
|
+
set :aws_region, 'eu-west-1'
|
|
37
|
+
set :aws_autoscaling_group_name, 'my-app-production'
|
|
38
|
+
set :aws_deploy_user, 'deploy'
|
|
54
39
|
```
|
|
55
40
|
|
|
56
|
-
|
|
41
|
+
Before each deploy starts, the plugin adds every in-service instance in that group as a server. Don't also define those servers with `server` or `role`.
|
|
57
42
|
|
|
58
|
-
|
|
43
|
+
### Settings
|
|
59
44
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
# lifecycle states of the instances to deploy to
|
|
72
|
-
set :aws_lifecycle_states, %w(InService)
|
|
73
|
-
```
|
|
45
|
+
| Setting | Default | Description |
|
|
46
|
+
|---|---|---|
|
|
47
|
+
| `aws_autoscaling_group_name` | none (required) | Name of the Auto Scaling group to deploy to. |
|
|
48
|
+
| `aws_region` | `'us-west-2'` | AWS region of the group. |
|
|
49
|
+
| `aws_deploy_user` | none | SSH user for the instances. If unset, Capistrano's usual SSH user applies. |
|
|
50
|
+
| `aws_deploy_roles` | `%i{web app db}` | Roles given to the instances. See [Roles](#roles). |
|
|
51
|
+
| `aws_ip_type` | `'public_dns_name'` | Address used to connect to each instance: `public_dns_name`, `public_ip_address`, `private_dns_name` or `private_ip_address`. Use a private one for instances without public addresses, for example when deploying through a bastion or from inside the VPC. |
|
|
52
|
+
| `aws_lifecycle_states` | `%w(InService)` | [Lifecycle states](https://docs.aws.amazon.com/autoscaling/ec2/userguide/ec2-auto-scaling-lifecycle.html) of the instances to deploy to. |
|
|
53
|
+
| `aws_profile` | none | Named AWS profile to use. See [AWS credentials](#aws-credentials). |
|
|
54
|
+
| `aws_access_key_id`, `aws_secret_access_key` | none | Static AWS keys. See [AWS credentials](#aws-credentials). |
|
|
55
|
+
| `aws_autoscaling` | `true` | Set to `false` to turn the plugin off, for example in a stage whose servers you define yourself. |
|
|
74
56
|
|
|
75
57
|
### AWS credentials
|
|
76
58
|
|
|
77
|
-
The credentials need read access to Auto Scaling and EC2
|
|
59
|
+
The credentials need read access to Auto Scaling and EC2: `autoscaling:DescribeAutoScalingGroups` and `ec2:DescribeInstances`. The `AmazonEC2ReadOnlyAccess` managed policy covers both.
|
|
78
60
|
|
|
79
61
|
By default the gem uses the [AWS SDK's default credential chain](https://docs.aws.amazon.com/sdk-for-ruby/v3/developer-guide/credential-providers.html): environment variables (`AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, `AWS_SESSION_TOKEN`), `AWS_PROFILE` and the shared config and credentials files, AWS SSO, and ECS task or EC2 instance roles. This is the recommended setup, and it needs no settings.
|
|
80
62
|
|
|
@@ -84,48 +66,69 @@ To use a specific profile from your shared config:
|
|
|
84
66
|
set :aws_profile, 'deploy'
|
|
85
67
|
```
|
|
86
68
|
|
|
87
|
-
You can still set static keys, but
|
|
69
|
+
You can still set static keys, but don't commit them to your repository. If both are set, they take precedence over `aws_profile`:
|
|
88
70
|
|
|
89
71
|
```ruby
|
|
90
72
|
set :aws_access_key_id, ENV['DEPLOY_AWS_ACCESS_KEY_ID']
|
|
91
73
|
set :aws_secret_access_key, ENV['DEPLOY_AWS_SECRET_ACCESS_KEY']
|
|
92
74
|
```
|
|
93
75
|
|
|
94
|
-
|
|
76
|
+
### Roles
|
|
77
|
+
|
|
78
|
+
Every instance gets the roles in `aws_deploy_roles`, except that only the **first** instance gets `:db` and `primary: true`. That way tasks meant to run once, such as database migrations, don't run on every instance at the same time.
|
|
79
|
+
|
|
80
|
+
With three instances in the group and the default roles, you end up with the same servers as if you had written:
|
|
81
|
+
|
|
82
|
+
```ruby
|
|
83
|
+
server 'ip-1.example.com', roles: %i{web app db}, primary: true
|
|
84
|
+
server 'ip-2.example.com', roles: %i{web app}
|
|
85
|
+
server 'ip-3.example.com', roles: %i{web app}
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## How it works
|
|
95
89
|
|
|
96
|
-
|
|
90
|
+
Before `deploy:starting`, the plugin:
|
|
97
91
|
|
|
98
|
-
|
|
92
|
+
1. Looks up the Auto Scaling group `aws_autoscaling_group_name`.
|
|
93
|
+
2. Keeps only the instances whose lifecycle state is in `aws_lifecycle_states`, and logs the ones it skips. Instances that are launching, on standby or being terminated are skipped by default. Health status isn't checked, so you can still deploy a fix when every instance is failing its health checks.
|
|
94
|
+
3. Reads each instance's `aws_ip_type` address from EC2.
|
|
95
|
+
4. Adds the instances as servers in the group's order, with roles as described in [Roles](#roles).
|
|
99
96
|
|
|
100
|
-
The deploy stops with an error if
|
|
97
|
+
The deploy stops with an error if:
|
|
101
98
|
|
|
102
|
-
|
|
99
|
+
* the group doesn't exist,
|
|
100
|
+
* no instances are in the selected lifecycle states, or
|
|
101
|
+
* an instance has no address for `aws_ip_type`, for example `public_dns_name` in a private subnet.
|
|
103
102
|
|
|
104
|
-
|
|
103
|
+
## Upgrading to 2.0
|
|
105
104
|
|
|
106
|
-
|
|
105
|
+
2.0 uses the current AWS SDK for Ruby (`aws-sdk-autoscaling` and `aws-sdk-ec2`) instead of the retired `aws-sdk` v2, so it no longer installs `aws-sdk` v2. If your own deploy code uses `aws-sdk` v2, add it to your Gemfile or, better, move that code to the current SDK.
|
|
106
|
+
|
|
107
|
+
2.0 only deploys to instances whose lifecycle state is `InService`, and stops with an error if the Auto Scaling group doesn't exist or has no such instances. Before, it deployed to every instance in the group, including ones being launched or terminated, and carried on with no servers if the group was empty. To also deploy to other states, set `aws_lifecycle_states` (for example `%w(InService Standby)`).
|
|
108
|
+
|
|
109
|
+
Versions before 2.0 also loaded [capistrano-bundler](https://github.com/capistrano/bundler), which runs `bundle install` on your servers during deploy. 2.0 no longer does this. If your deploy relies on it, add `gem 'capistrano-bundler'` to your Gemfile and this line to your Capfile:
|
|
107
110
|
|
|
108
|
-
|
|
111
|
+
```ruby
|
|
112
|
+
require 'capistrano/bundler'
|
|
113
|
+
```
|
|
109
114
|
|
|
110
|
-
|
|
111
|
-
server ip_address1, :app, :db, :web, :primary => true
|
|
112
|
-
server ip_address2, :app, :web
|
|
113
|
-
server ip_address3, :app, :web
|
|
114
|
-
````
|
|
115
|
+
See [CHANGELOG.md](CHANGELOG.md) for all changes.
|
|
115
116
|
|
|
116
117
|
## Contributing
|
|
117
118
|
|
|
118
|
-
1. Fork it (
|
|
119
|
+
1. Fork it (https://github.com/marcoschicote/capistrano3-autoscaling-deploy/fork)
|
|
119
120
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
120
121
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
121
122
|
4. Push to the branch (`git push origin my-new-feature`)
|
|
122
|
-
5. Create new
|
|
123
|
+
5. Create a new pull request
|
|
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)
|
|
@@ -53,6 +52,13 @@ module AwsHelper
|
|
|
53
52
|
autoscaling_dns = instance_ids.map do |instance_id|
|
|
54
53
|
ec2_instances.fetch(instance_id).send(aws_ip_type.to_sym)
|
|
55
54
|
end
|
|
55
|
+
|
|
56
|
+
# e.g. public_dns_name is empty for instances in a private subnet
|
|
57
|
+
blank_ids = instance_ids.zip(autoscaling_dns).select { |_, address| address.to_s.strip.empty? }.map(&:first)
|
|
58
|
+
unless blank_ids.empty?
|
|
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)"
|
|
61
|
+
end
|
|
56
62
|
end
|
|
57
63
|
|
|
58
64
|
autoscaling_dns
|
|
@@ -61,18 +67,13 @@ module AwsHelper
|
|
|
61
67
|
def fetch_autoscaling_group_instances(client_options, autoscaling_group_name)
|
|
62
68
|
as = Aws::AutoScaling::Client.new(client_options)
|
|
63
69
|
as_groups = as.describe_auto_scaling_groups(
|
|
64
|
-
|
|
65
|
-
|
|
70
|
+
auto_scaling_group_names: [autoscaling_group_name],
|
|
71
|
+
max_records: 1
|
|
66
72
|
).auto_scaling_groups
|
|
67
73
|
|
|
68
|
-
# info("Auto Scaling Groups: #{as_groups}")
|
|
69
|
-
|
|
70
74
|
as_group = as_groups[0]
|
|
71
75
|
raise "Auto Scaling group '#{autoscaling_group_name}' not found in #{client_options[:region]}" unless as_group
|
|
72
76
|
|
|
73
|
-
# info("Auto Scaling Group instances: #{as_group.instances}")
|
|
74
|
-
|
|
75
77
|
as_group.instances
|
|
76
78
|
end
|
|
77
|
-
|
|
78
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,14 +21,14 @@ 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.
|
|
31
|
-
if
|
|
30
|
+
ec2_instances.each_with_index { |instance, index|
|
|
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}")
|
|
34
34
|
else
|
|
@@ -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:
|
|
@@ -105,7 +119,6 @@ files:
|
|
|
105
119
|
- LICENSE
|
|
106
120
|
- README.md
|
|
107
121
|
- lib/capistrano/autoscaling_deploy.rb
|
|
108
|
-
- lib/capistrano/autoscaling_deploy/autoscaling_deploy.rb
|
|
109
122
|
- lib/capistrano/autoscaling_deploy/version.rb
|
|
110
123
|
- lib/capistrano/helpers/aws_helper.rb
|
|
111
124
|
- lib/capistrano/helpers/cap_helper.rb
|
|
@@ -116,7 +129,7 @@ licenses:
|
|
|
116
129
|
- MIT
|
|
117
130
|
metadata:
|
|
118
131
|
source_code_uri: https://github.com/marcoschicote/capistrano3-autoscaling-deploy
|
|
119
|
-
changelog_uri: https://github.com/marcoschicote/capistrano3-autoscaling-deploy/blob/
|
|
132
|
+
changelog_uri: https://github.com/marcoschicote/capistrano3-autoscaling-deploy/blob/main/CHANGELOG.md
|
|
120
133
|
bug_tracker_uri: https://github.com/marcoschicote/capistrano3-autoscaling-deploy/issues
|
|
121
134
|
rubygems_mfa_required: 'true'
|
|
122
135
|
rdoc_options: []
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
load File.expand_path('../../tasks/autoscaling.rake', __FILE__)
|