Skip to content

Commit

Permalink
Allow setting of AutoRollback instance refresh preference (#10)
Browse files Browse the repository at this point in the history
* Allow setting of `AutoRollback` instance refresh preference

* Update context name
  • Loading branch information
lloydwatkin authored Nov 26, 2024
1 parent 269366d commit e323de0
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ set :asg_wait_for_instance_refresh, true
set :asg_instance_refresh_polling_interval, 30 # default
```

Enable or disable auto-rollback on instance refreshes (default: false):

```ruby
# config/deploy.rb
set :asg_instance_refresh_auto_rollback, true

## Usage

Specify the Auto Scaling Groups with the keyword `autoscale` instead of using the `server` keyword in Capistrano's stage configuration. Provide the name of the Auto Scaling Group and any properties you want to pass to the server:
Expand Down
7 changes: 6 additions & 1 deletion lib/capistrano/asg/rolling/autoscale_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ def min_healthy_percentage
properties.fetch(:min_healthy_percentage, nil)
end

def auto_rollback
properties.fetch(:asg_instance_refresh_auto_rollback, nil)
end

def max_healthy_percentage
properties.fetch(:max_healthy_percentage, nil)
end
Expand All @@ -73,7 +77,8 @@ def start_instance_refresh(launch_template)
instance_warmup: instance_warmup_time,
skip_matching: true,
min_healthy_percentage: min_healthy_percentage,
max_healthy_percentage: max_healthy_percentage
max_healthy_percentage: max_healthy_percentage,
auto_rollback: auto_rollback
}.compact
).instance_refresh_id
rescue Aws::AutoScaling::Errors::InstanceRefreshInProgress => e
Expand Down
16 changes: 16 additions & 0 deletions spec/capistrano/asg/rolling/autoscale_group_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,22 @@
end
end

describe '#auto_rollback' do
subject(:group) { described_class.new('test-asg', asg_instance_refresh_auto_rollback: false) }

it 'returns the value set in the configuration' do
expect(group.auto_rollback).to be false
end

context 'when no value is set' do
subject(:group) { described_class.new('test-asg', {}) }

it 'returns `nil`' do
expect(group.auto_rollback).to be_nil
end
end
end

describe '#min_healthy_percentage' do
context 'when no value is set' do
it 'returns nil' do
Expand Down

0 comments on commit e323de0

Please sign in to comment.