Capistrano provides a Multistage extension which allows to use a different deployment strategy for different scenarios. For instance, for your application, you might have two servers: one for production, where the “live” code is, and one for staging, where you can test features out without risk of affecting anything critical.
In order to use the Multistage extension, you need to add the following lines to your
set :stages, %w(production staging) set :default_stage, "staging" set :stage_dir, "app/config" require 'capistrano/ext/multistage'
The first parameter
:stages configures your different stages. In that case, we just have two stages
staging which is also the default stage. The
:stage_dir parameter allows to configure the path to your configuration files for each stage.
In order to configure each stage, you must create a configuration file per stage. In that case, you have to create both
production.rb file contains your production settings:
server 'production.server.com', :app, :web, :primary => true
staging.rb file contains your staging settings:
server 'staging.server.com', :app, :web, :primary => true
As you configured the
:default_stage parameter with
staging, all tasks will be run with your
But now, you can run
cap production deploy to deploy your application to your production server, and it’s the same pattern for all tasks:
cap stage taskname
Where stage can be either
production in our example.