I have a rails application that I need to deploy to 3 servers - machine1.com, machine2.com and machine3.com. I want to be able to deploy it to all machines at once and each machine individually. Can someone help me out with a skeleton Capistrano config file / recipe? Should it all be in deploy.rb or should I break it out in machine1.rb, etc?
I thought I was on the right track getting Capistrano to take in command line arguments, but it choked when I tried set the roles within the namespaces. I'd pass in 'hosts=1,2,3' as an argument and set the role:app/web/db to "machine#{host}.com" after splitting on the command and going into an each do |host| {}...
Anyway, other than creating 4 different deploy.rb files and renaming it before running cap:deploy each time, I'm stumped. I'd like to be able to do the following:
cap deploy:machine1:latest_version_from_svn
cap deploy:all_machines:latest:version_from_svn
Just don't know if it should all be in deploy.rb split up with namespaces or if it should be broken into multiple *deploy**.rb files.
It should all go in one file. Here's an example:
set :application, "my-app"
set :repository, "[email protected]:my-app.git"
set :keep_releases, 5
set :deploy_via, :remote_cache
set :git_enable_submodules, true
set :scm, :git
set :user, 'your-user-here'
set :deploy_to, "/var/www/staging.mydomain.com"
set :branch, 'staging'
set :rails_env, 'staging'
role :web, "machine1.mydomain.com", "machine2.mydomain.com", "machine3.mydomain.com"
role :app, "machine1.mydomain.com", "machine2.mydomain.com", "machine3.mydomain.com"
role :db, "db.mydomain.com"
# ...
You'll see that only one db server was specified. This is the machine the migrations will be run from. If you only have one database (99.9% chance of the answer to that question being YES), then make sure to only provide one.