capistrano-asgroup is a Capistrano plugin designed to simplify the task of deploying to infrastructure hosted on Amazon EC2. It was completely inspired by the capistrano-ec2group and capistrano-ec2tag plugins, to which all credit is due.
Both of the prior plugins gave you "a way" to deploy using Capistrano to AWS Auto Scaling groups but both required you to do so in a non-straightforward manner by putting your Auto Scaling group in its own security group or by providing a unique tag for your Auto Scaling group. This plugin simply takes the name of the Auto Scaling group and uses that to find the Auto Scaling instances that it should deploy to. It will work with straight up hand created Auto Scaling groups (exact match of the AS group name) or with Cloud Formation created Auto Scaling groups (looking for the name in the Cloud Formation format).
In order for the plugin to list out the hostnames of your AWS Auto Scaling instances, it will need access to the Amazon AWS API. It is recommended to use IAM to create credentials with limited capabilities for this type of purpose. Specify the following in your Capistrano configuration:
You can use aws-sdk credentials described in AWS docs
set :aws_access_key_id, ENV['AWS_ACCESS_KEY_ID']
set :aws_secret_access_key, ENV['AWS_SECRET_ACCESS_KEY']
Or you can skip this if you have ~/.aws/credentials
configured. If you
want to select a specific profile for your credentials you can set:
set :aws_profile_name, 'my_profile'
The plugin is distributed as a Ruby gem.
Add the following to your Gemfile:
source "https://packagecloud.io/Empatico/packages" do
gem "capistrano-asgroup"
end
Install the gems in your manifest using:
bundle install
Add the gem to your Capfile
require 'capistrano/asgroup'
Then configure your AWS settings in your config/
file.
set :aws_region, 'eu-west-1' # set the region of AWS
set :asgroup_use_private_ips, true
set :aws_profile_name, 'profile_name'
The asgroup_use_private_ips
is needed when deploying through a NAT
Gateway into a VPC. It uses the instance's private IP addresses rather
than their public addresses.
Then replace your role
or similar statement with a statement like:
add_as_instances "<my-autoscale-group-name>"[, roles: <role>]
So instead of:
task :production do
role :web, 'mysever1.example.com','myserver2.example.com'
logger.info 'Deploying to the PRODUCTION environment!'
end
You would do:
task :production do
add_as_instances "my-asg-name", roles: 'web'
logger.info 'Deploying to the PRODUCTION environment!'
end
You can also add instances via the ASG's tagging system.
add_as_by_tag "Name", "#{fetch :stage}-website-webserver", roles: 'web',
user: 'ubuntu'
This would add any instances tagged with the stage plus
-website-webserver
, for example production-website-webserver
.
This a continuation of Thomas Verbiscer's capistrano-asgroup, which was extended again by Piotr Jasiulewicz.
Originally developed by: Thomas Verbiscer, released under the MIT License