No commit activity in last 3 years
No release in over 3 years
Capistrano 3 plugin for updating AWS Launch Template AMI with autoscale group first healthy instance.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 2.2.10
>= 0

Runtime

 Project Readme

Gem Downloads Gem Version MIT license

capistrano3-asg-ami

Capistrano 3 plugin for updating AWS Launch Template AMI with autoscale group first healthy instance.

Requirements

  • aws-sdk-ec2 ~> 1
  • aws-sdk-autoscaling ~> 1
  • capistrano ~> 3

Installation

Add this line to your application's Gemfile:

gem 'capistrano3-asg-ami'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install capistrano3-asg-ami

Add this line to your application's Capfile:

require 'capistrano/autoscaling'

Usage

Create IAM with AmazonEC2FullAccess permission and Set credentials in the capistrano deploy script / stage files add the following lines

set :aws_region, 'ap-northeast-1'
set :aws_access_key_id, 'YOUR AWS KEY ID'
set :aws_secret_access_key, 'YOUR AWS SECRET KEY'
set :aws_autoscaling_group_name, 'YOUR NAME OF AUTO SCALING GROUP NAME'
set :aws_launch_template_id, 'Your AUTOSCALE GROUP Launch template ID'
set :aws_autoscale_ami_prefix, 'server-name-'
set :aws_keep_prev_no_of_ami, 1

To call this task after deploy, in your desire capistrano environment file add the following in deploy section

 namespace :deploy do
    after :finishing, 'autoscaling:update_ami'
 end

And to update autoscale group launch template manually

    cap [stage] autoscaling:update_ami

i.e [stage] can be staging or production

How this works

  1. Fetch only running instances that have an auto scaling group name you specified
  2. Create AMI with first healthy instance
  3. Tag AMI with autoscale group name
  4. Wait for AMI to be available for use
  5. Update Launch template with update AMI
  6. Deleting stale images base on (aws_keep_prev_no_of_ami) variable if not set will only keep the latest one and delete the other AMI tagged with autoscale group name

Contributing

  1. Fork it ( https://github.com/Aftab-Akram/capistrano3-asg-ami/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

To test while developoing just bundle console on the project root directory and execute Capistrano::AutoScaling::VERSION for a quick test

Contact

Aftab Akram - LinkedIn - aftabakram04@gmail.com