Production and Staging with Capistrano

For the benefit of googlers, should you happen to be wanting to use the very good Capistrano to deploy your project, and want to switch between staging or pre-production and live or production environments, the best way to handle the switch is using the Multistage facility in capistrano-ext.

It’s basically just ‘gem install capistrano-ext’, then at the top of your deploy.rb do something like:

set :stages, %w(ppd live dev) # you can use as many stages with whatever names you want here
require ‘capistrano/ext/multistage’

In the config directory create deploy/ppd.rb, deploy/live.rb and deploy/dev.rb and put in the deploy specific stuff into each one - all your tasks can still be defined in the main deploy.rb. My stage rb files are just a bunch of sets and roles (which can’t be set in tasks), and they work brilliantly.

Now when you try to do ‘cap deploy’, it will moan and say you must give it a target: “No stage specified. Please specify one of: ppd, live, dev (e.g. `cap ppd deploy’)”. Do that, and you’re away.

One Comment

  1. jc says:

    I anxiously await a webistrano update … :-)

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>