Skip to content
This repository has been archived by the owner on Mar 21, 2018. It is now read-only.

Capistrano Tasks

Tom Scott edited this page Nov 2, 2012 · 1 revision

Capistrano Integration

Rain is tightly integrated with Capistrano, utilizing it for all manners of deployment. We also use Capistrano to notify our monitoring tools of new releases (like Flowdock, Airbrake and New Relic), so we can keep our entire team up to date. These tools can be optionally included in your config/deploy.rb.

Rain uses the same deployment script for each environment, with the only difference being server configuration. This configuration is defined in your config/deploy.rb as a :to_{environment} task...

Setting up your configuration tasks

You must create two tasks in config/deploy.rb, called :to_stage and :to_production. These tasks are executed prior to cap deploy, and built to simply set up configuration on a per-environment basis.

It's good practice to use the same 'app' user for anything Capistrano does on the server, that way you can easily see when Capistrano performed actions on your environment in syslog...

# Always use the 'app' user.
set :user, "app"

First, set up your staging server's information. The staging server is where you will ship versions of your software that are just about ready, but require a last-minute code review period before deploying to the production environment. At eLocal, we use stage to test integration with real-life APIs and show features off to the board of directors before it is shipped onto eLocal.com.

desc "Configure deployer for the staging server."
task :to_stage do
  set :rails_env, 'stage'
  role :web,  "ec2-127-0-0-1.compute-1.amazonaws.com"
  role :app,  "ec2-255-255-255-1.compute-1.amazonaws.com"
  role :db,   "ec2-192-168-1-1.compute-1.amazonaws.com"
end

Next, set up your production configuration. This environment is always either in sync or behind stage, only having the ability to update to the last tag that was released to stage. This ensures that production always deploys the same code as what was seen on stage, so no "surprises" occur between deploying the two versions.

desc "Configure deployer for the staging server."
task :to_production do
  set :rails_env, 'production'
  role :web,  "static.elocal.com"
  role :app,  "worker.elocal.com"
  role :db,   "db.elocal.com"
end
Clone this wiki locally