Tired of setting hardcoded ips or dns names in your capistrano deploy script? You just found the solution!
cap-aws-ec2 will fetch instances from you EC2 region and define them by project, environment and roles.
This gem should be used in conjunction with capistrano multistage
Note: This gem is only compatibale with Capistrano 2.x
Add this line to your application's Gemfile:
gem 'cap-aws-ec2', require: false
And then execute:
$ bundle
Or install it yourself as:
$ gem install cap-aws-ec2
- Define tags for your servers on EC2:
Name Tag | Project Tag | Environment Tag | Roles Tag | Public IP |
---|---|---|---|---|
ftbpro-web1 | ftbpro-web | production | app,web | 1.1.1.1 |
ftbpro-web2 | ftbpro-web | production | app,web | 2.2.2.2 |
ftbpro-resque | ftbpro-web | production | app,resque | 3.3.3.3 |
- In your
deploy.rb
script:
require 'cap-aws-ec2'
set :aws_key_id, 'XXXXXXXXXXXXXX'
set :secret_access_key, 'XXXXXXXXXXXXXXXXXXXX'
set :aws_region, 'us-west-2'
set :ec2_project, 'my-project-tag-value'
set(:ec2_env) { stage }
- In your corresponding stage file (
config/deploy/production.rb
):
define_servers
This will result in the following statements:
server 1.1.1.1, :app, :web
server 2.2.2.2, :app, :web
server 3.3.3.3, :app, :resque
- Fork it ( http://github.com//cap-aws-ec2/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