Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep Old Versions of AMIs #44

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ set :aws_secret_key, ENV['AWS_SECRET_ACCESS_KEY']
set :aws_region, ENV['AWS_REGION']
```

Define how many past AMIs to keep during cleanup. The default is 5.

```ruby
set :elbas_keep_amis, 5
```

## Usage

Instead of using Capistrano's `server` method, use `autoscale` instead in
Expand Down
11 changes: 8 additions & 3 deletions lib/elbas/tasks/elbas.rake
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,14 @@ namespace :elbas do
info "Updated launch template, new default version = #{launch_template.version}"

info "Cleaning up old AMIs..."
ami.ancestors.each do |ancestor|
info "Deleting old AMI: #{ancestor.id}"
ancestor.delete
keep = fetch(:elbas_keep_amis) || 5
if ami.ancestors.count > keep
amis = ami.ancestors.drop(keep)
amis.each do |ancestor|
info "Deleting old AMI: #{ancestor.id}"
ancestor.delete
end
info "Deleted #{amis.count} old AMIs and keeping newest #{keep}"
end

info "Deployment complete!"
Expand Down