capistrano-ec2filter is a Capistrano plugin designed to simplify the task of deploying to infrastructure hosted on Amazon EC2.
It allows to declare capistrano deploy servers filtered with ec2-describe-instances
criteria (read more).
Add this line to your application's Gemfile:
gem 'capistrano-ec2filter'
And then execute:
$ bundle
Or install it yourself as:
$ gem install capistrano-ec2filter
Add this to the top of your deploy.rb
:
require 'capistrano/ec2filter'
Then supply your AWS credentials with the environment variables (default):
# aws
export AWS_ACCESS_KEY_ID='...'
export AWS_SECRET_ACCESS_KEY='...'
# export AWS_EC2_ENDPOINT='...'
Or in your deploy.rb
with capistrano variables:
set :aws_access_key_id, "..."
set :aws_secret_access_key, "..."
# set :aws_ec2_endpoint, "ec2.eu-west-1.amazonaws.com"
Define your servers:
ec2_filter("tag:application"=>"SuperApp", "tag:layer"=>"application") do |address|
server address, :web, :app
end
ec2_filter("tag:application"=>"SuperApp", "tag:layer"=>"workers") do |address, instance|
server address, :app, :jobs, :min_job_priority: 10
end
ec2_filter("placement-group-name"=>"matrix") do |address, instance|
server address, :matrix, platform: instance.platform
end
instance
- AWS::EC2::Instance from AWS SDK for Ruby
address
- dns/ip address of instance = instance.dns_name || instance.ip_address || instance.private_ip_address
By default ec2_filter apply "instance-state-name" => "running"
filter. You can overwrite this:
ec2_filter("instance-state-name" => ["stopped", "stopping"], "tag:layer"=>"application") do |address|
server address, :app, stopped: true
end
Full list of supported EC2 filters: click here
- Fork it ( http://github.com/rogal111/capistrano-ec2filter/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request