Skip to content

Instantly share code, notes, and snippets.

@seanbehan
Created October 19, 2011 00:47
Show Gist options
  • Save seanbehan/1297203 to your computer and use it in GitHub Desktop.
Save seanbehan/1297203 to your computer and use it in GitHub Desktop.
Example Multi Stage Capistrano Deploy

README

Install Capistrano

gem install capistrano

Run from the project root of your application.

capify .

This will generate the necessary files.

To add multistage support add the capistrano-ext to your Gemfile.

Capistrano will look for environments in config/deploy/[the environment name].rb, in our case config/deploy/staging.rb.

NOTE: If using RVM (it's awesome) on your remote server, you will need to specify some environment variables. Typically, my environments mirror each other in staging and production so they tend to be the same and therefore, shared in the config/deploy.rb script. If this is not the case, put the :default_environment directive in the deploy specific environment file.

To find out what the values are for your environment, on the remote machine run

rvm info

Find the hash keys in the output and plug them in.

# config/deploy/production.rb
set :domain, "www.example.com"
set :repository, "git@github.com:bseanvt/some-project-repo.git"
set :app_dir, "#{application}"
set :deploy_to, "/home/webapp/#{app_dir}"
set :branch, "master"
set :rails_env, "production"
server "#{domain}", :web, :app, :db, :primary => true
# config/deploy/staging.rb
set :domain, "staging.example.com"
set :repository, "git@github.com:bseanvt/some-project-repo.git"
set :app_dir, "#{application}"
set :deploy_to, "/home/webapp/#{app_dir}"
set :branch, "staging"
set :rails_env, "production"
server "#{domain}", :web, :app, :db, :primary => true
# config/deploy.rb
require 'bundler/capistrano'
require 'capistrano/ext/multistage'
require 'capistrano_colors'
set :stages, %w(staging production)
set :default_stage, "staging"
set :user, "webapp"
set :ssh_option, {:forward_agent => true}
set :application, "example_app"
set :deploy_via, :remote_cache
set :scm, :git
set :use_sudo, false
# If you're using RVM on the remote machine, you will need to set at least these environment variables
# To find out the specifics for your machine run
# rvm info
# on the remote machine.
set :default_environment, {
'PATH' => '',
'RUBY_VERSION' => '',
'GEM_HOME' => '',
'GEM_PATH' => ''
}
default_run_options[:pty] = true
namespace :deploy do
task :start do ; end
task :stop do ; end
task :restart, :roles => :app, :except => { :no_release => true } do
run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
end
end
# Gemfile
# Relevant Capistrano gems
gem 'capistrano'
gem 'capistrano-ext'
gem 'capistrano_colors'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment