capistrano3-autoscaling-deploy 2.0.0 → 2.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 +4 -4
- data/CHANGELOG.md +9 -0
- data/README.md +66 -66
- data/lib/capistrano/autoscaling_deploy/version.rb +1 -1
- data/lib/capistrano/helpers/aws_helper.rb +7 -0
- data/lib/capistrano/tasks/autoscaling.rake +2 -2
- metadata +1 -2
- 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: 5125a4f0cf87e61f76c8693fa8d434d9799ecbfd210abe6b6d5d4d297f9d0616
|
|
4
|
+
data.tar.gz: 4afd807fd174d4305a797caa38189a951df32cfe08aa33bf5f09dfc2b7300ae5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2118d1de8dd0d3119f9799bb6e177c3790137ca24b368750ec1a8bb1d012ec86ad21b5f6876d3a73f2da2ab94fa6d2e98251b84c1b280c610e6db08b0e7a34b4
|
|
7
|
+
data.tar.gz: 5c8188565e47c2afd1045dac3f5993370c6a0beb49fc9544d16e558701436c482e2a29cb171ce3147f6002f72e6b0e04fc435222df8868b951c1d42be4c7a4a1
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 2.0.1
|
|
4
|
+
|
|
5
|
+
### Fixed
|
|
6
|
+
- 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)).
|
|
7
|
+
- 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)).
|
|
8
|
+
|
|
9
|
+
### Removed
|
|
10
|
+
- `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)).
|
|
11
|
+
|
|
3
12
|
## 2.0.0
|
|
4
13
|
|
|
5
14
|
First release since 1.6 (2017). See [Upgrading to 2.0](README.md#upgrading-to-20) before updating.
|
data/README.md
CHANGED
|
@@ -1,80 +1,61 @@
|
|
|
1
|
-
[](https://rubygems.org/gems/capistrano3-autoscaling-deploy)
|
|
2
2
|
[](https://github.com/marcoschicote/capistrano3-autoscaling-deploy/actions/workflows/test.yml)
|
|
3
|
+
|
|
3
4
|
# 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.
|
|
5
|
+
|
|
6
|
+
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
7
|
|
|
13
8
|
## Requirements
|
|
14
9
|
|
|
15
|
-
*
|
|
16
|
-
* aws-sdk-ec2 ~> 1
|
|
10
|
+
* Ruby 3.3 or newer
|
|
17
11
|
* capistrano ~> 3
|
|
18
|
-
|
|
12
|
+
* aws-sdk-autoscaling ~> 1 and aws-sdk-ec2 ~> 1 (installed with the gem)
|
|
19
13
|
|
|
20
14
|
## Installation
|
|
21
15
|
|
|
22
|
-
Add
|
|
23
|
-
|
|
24
|
-
gem 'capistrano3-autoscaling-deploy'
|
|
16
|
+
Add the gem to your application's Gemfile:
|
|
25
17
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
Or install it yourself as:
|
|
18
|
+
```ruby
|
|
19
|
+
gem 'capistrano3-autoscaling-deploy', '~> 2.0'
|
|
20
|
+
```
|
|
31
21
|
|
|
32
|
-
|
|
22
|
+
and run `bundle install`.
|
|
33
23
|
|
|
34
|
-
|
|
24
|
+
Then add this line to your Capfile:
|
|
35
25
|
|
|
36
26
|
```ruby
|
|
37
27
|
require 'capistrano/autoscaling_deploy'
|
|
38
28
|
```
|
|
39
29
|
|
|
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'
|
|
30
|
+
## Usage
|
|
49
31
|
|
|
50
|
-
|
|
32
|
+
In your deploy script or stage file (for example `config/deploy/production.rb`), set the Auto Scaling group to deploy to:
|
|
51
33
|
|
|
52
34
|
```ruby
|
|
53
|
-
|
|
35
|
+
set :aws_region, 'eu-west-1'
|
|
36
|
+
set :aws_autoscaling_group_name, 'my-app-production'
|
|
37
|
+
set :aws_deploy_user, 'deploy'
|
|
54
38
|
```
|
|
55
39
|
|
|
56
|
-
|
|
40
|
+
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
41
|
|
|
58
|
-
|
|
42
|
+
### Settings
|
|
59
43
|
|
|
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
|
-
```
|
|
44
|
+
| Setting | Default | Description |
|
|
45
|
+
|---|---|---|
|
|
46
|
+
| `aws_autoscaling_group_name` | none (required) | Name of the Auto Scaling group to deploy to. |
|
|
47
|
+
| `aws_region` | `'us-west-2'` | AWS region of the group. |
|
|
48
|
+
| `aws_deploy_user` | none | SSH user for the instances. If unset, Capistrano's usual SSH user applies. |
|
|
49
|
+
| `aws_deploy_roles` | `%i{web app db}` | Roles given to the instances. See [Roles](#roles). |
|
|
50
|
+
| `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. |
|
|
51
|
+
| `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. |
|
|
52
|
+
| `aws_profile` | none | Named AWS profile to use. See [AWS credentials](#aws-credentials). |
|
|
53
|
+
| `aws_access_key_id`, `aws_secret_access_key` | none | Static AWS keys. See [AWS credentials](#aws-credentials). |
|
|
54
|
+
| `aws_autoscaling` | `true` | Set to `false` to turn the plugin off, for example in a stage whose servers you define yourself. |
|
|
74
55
|
|
|
75
56
|
### AWS credentials
|
|
76
57
|
|
|
77
|
-
The credentials need read access to Auto Scaling and EC2
|
|
58
|
+
The credentials need read access to Auto Scaling and EC2: `autoscaling:DescribeAutoScalingGroups` and `ec2:DescribeInstances`. The `AmazonEC2ReadOnlyAccess` managed policy covers both.
|
|
78
59
|
|
|
79
60
|
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
61
|
|
|
@@ -84,42 +65,61 @@ To use a specific profile from your shared config:
|
|
|
84
65
|
set :aws_profile, 'deploy'
|
|
85
66
|
```
|
|
86
67
|
|
|
87
|
-
You can still set static keys, but
|
|
68
|
+
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
69
|
|
|
89
70
|
```ruby
|
|
90
71
|
set :aws_access_key_id, ENV['DEPLOY_AWS_ACCESS_KEY_ID']
|
|
91
72
|
set :aws_secret_access_key, ENV['DEPLOY_AWS_SECRET_ACCESS_KEY']
|
|
92
73
|
```
|
|
93
74
|
|
|
94
|
-
|
|
75
|
+
### Roles
|
|
76
|
+
|
|
77
|
+
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.
|
|
78
|
+
|
|
79
|
+
With three instances in the group and the default roles, you end up with the same servers as if you had written:
|
|
80
|
+
|
|
81
|
+
```ruby
|
|
82
|
+
server 'ip-1.example.com', roles: %i{web app db}, primary: true
|
|
83
|
+
server 'ip-2.example.com', roles: %i{web app}
|
|
84
|
+
server 'ip-3.example.com', roles: %i{web app}
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## How it works
|
|
88
|
+
|
|
89
|
+
Before `deploy:starting`, the plugin:
|
|
95
90
|
|
|
96
|
-
|
|
91
|
+
1. Looks up the Auto Scaling group `aws_autoscaling_group_name`.
|
|
92
|
+
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.
|
|
93
|
+
3. Reads each instance's `aws_ip_type` address from EC2.
|
|
94
|
+
4. Adds the instances as servers in the group's order, with roles as described in [Roles](#roles).
|
|
97
95
|
|
|
98
|
-
|
|
96
|
+
The deploy stops with an error if:
|
|
99
97
|
|
|
100
|
-
|
|
98
|
+
* the group doesn't exist,
|
|
99
|
+
* no instances are in the selected lifecycle states, or
|
|
100
|
+
* an instance has no address for `aws_ip_type`, for example `public_dns_name` in a private subnet.
|
|
101
101
|
|
|
102
|
-
|
|
102
|
+
## Upgrading to 2.0
|
|
103
|
+
|
|
104
|
+
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.
|
|
103
105
|
|
|
104
|
-
|
|
106
|
+
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)`).
|
|
105
107
|
|
|
106
|
-
|
|
108
|
+
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
109
|
|
|
108
|
-
|
|
110
|
+
```ruby
|
|
111
|
+
require 'capistrano/bundler'
|
|
112
|
+
```
|
|
109
113
|
|
|
110
|
-
|
|
111
|
-
server ip_address1, :app, :db, :web, :primary => true
|
|
112
|
-
server ip_address2, :app, :web
|
|
113
|
-
server ip_address3, :app, :web
|
|
114
|
-
````
|
|
114
|
+
See [CHANGELOG.md](CHANGELOG.md) for all changes.
|
|
115
115
|
|
|
116
116
|
## Contributing
|
|
117
117
|
|
|
118
|
-
1. Fork it (
|
|
118
|
+
1. Fork it (https://github.com/marcoschicote/capistrano3-autoscaling-deploy/fork)
|
|
119
119
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
120
120
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
121
121
|
4. Push to the branch (`git push origin my-new-feature`)
|
|
122
|
-
5. Create new
|
|
122
|
+
5. Create a new pull request
|
|
123
123
|
|
|
124
124
|
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
125
|
|
|
@@ -53,6 +53,13 @@ module AwsHelper
|
|
|
53
53
|
autoscaling_dns = instance_ids.map do |instance_id|
|
|
54
54
|
ec2_instances.fetch(instance_id).send(aws_ip_type.to_sym)
|
|
55
55
|
end
|
|
56
|
+
|
|
57
|
+
# e.g. public_dns_name is empty for instances in a private subnet
|
|
58
|
+
blank_ids = instance_ids.zip(autoscaling_dns).select { |_, address| address.to_s.strip.empty? }.map(&:first)
|
|
59
|
+
unless blank_ids.empty?
|
|
60
|
+
raise "Instances #{blank_ids.join(', ')} have no #{aws_ip_type}. " \
|
|
61
|
+
"Set :aws_ip_type to one of #{IP_TYPES.join(', ')} (private_ip_address for instances without public addresses)"
|
|
62
|
+
end
|
|
56
63
|
end
|
|
57
64
|
|
|
58
65
|
autoscaling_dns
|
|
@@ -27,8 +27,8 @@ namespace :autoscaling_deploy do
|
|
|
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
|
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.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Marcos Chicote
|
|
@@ -105,7 +105,6 @@ files:
|
|
|
105
105
|
- LICENSE
|
|
106
106
|
- README.md
|
|
107
107
|
- lib/capistrano/autoscaling_deploy.rb
|
|
108
|
-
- lib/capistrano/autoscaling_deploy/autoscaling_deploy.rb
|
|
109
108
|
- lib/capistrano/autoscaling_deploy/version.rb
|
|
110
109
|
- lib/capistrano/helpers/aws_helper.rb
|
|
111
110
|
- lib/capistrano/helpers/cap_helper.rb
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
load File.expand_path('../../tasks/autoscaling.rake', __FILE__)
|