Capistrano deploy to multiple locations

Pretty simple, but wanted to log here so I can look this up in the future…

I wanted to deploy to both a stage and a live site. Here’s how that went down:

First I installed the capistrano-ext gem. Second, I edited my Capfile to look like this:

require 'capistrano/ext/multistage'
set :default_stage, "beta"
set :stages, %w(beta live)

Third, I created a deploy folder and added my two recipes there. beta.rb looks like this:

load 'deploy' if respond_to?(:namespace) # cap2 differentiator

default_run_options[:pty] = true

# be sure to change these
set :user, 'username'
set :domain, 'beta.example.org'
set :application, 'fundastache'

# the rest should be good
set :repository,  "#{user}@#{domain}:git/#{application}.git" 
#set :repository,  "/home/#{user}/git/#{application}.git" 
set :deploy_to, "/home/#{user}/#{domain}" 
set :deploy_via, :remote_cache
set :scm, 'git'
set :branch, 'master'
set :git_shallow_clone, 1
set :scm_verbose, true
set :use_sudo, false

server domain, :app, :web

namespace :deploy do
  task :restart do
    run "touch #{current_path}/tmp/restart.txt" 
  end
end

The live recipe looks almost identical.

Now when I

cap live deploy

the site is deployed to the live environment and when I

cap beta deploy

or simply

cap deploy

the site is deployed to the beta site.

Leave a Reply

Your email address will not be published. Required fields are marked *

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