Created
September 10, 2011 22:52
-
-
Save partydrone/1208908 to your computer and use it in GitHub Desktop.
Multistage Capistrano Recipe
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
load 'deploy' if respond_to?(:namespace) # cap2 differentiator | |
require 'bundler/capistrano' | |
# Uncomment if you are using Rails' asset pipeline | |
load 'deploy/assets' | |
Dir['vendor/gems/*/recipes/*.rb','vendor/plugins/*/recipes/*.rb'].each { |plugin| load(plugin) } | |
load 'config/deploy' # remove this line to skip loading any of the default tasks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'capistrano/ext/multistage' | |
set :stages, %w(staging production) | |
set :default_stage, 'staging' | |
set :scm, :git | |
set :repository, "your_repository_here" | |
set :ssh_options, { :forward_agent => true } | |
set :deploy_via, :remote_cache | |
set :application, "your_application_name" | |
namespace :deploy do | |
task :default do | |
set(:branch) do | |
br = Capistrano::CLI.ui.ask "What branch do you want to deploy?: ".downcase | |
raise 'You can only deploy master branch to production.' if (stage.to_s.upcase == 'PRODUCTION') && br != 'master' | |
br | |
end | |
puts "*** Deploying to the #{stage.to_s.upcase} server!" | |
update | |
restart | |
# Clean up old deployments | |
deploy.cleanup | |
# Send deployment notification except, for the default stage | |
end | |
# override migrations task to inject branch | |
desc <<-DESC | |
Deploy and run pending migrations. This will work similarly to the \ | |
'deploy' task, but will also run any pending migrations (via the \ | |
'deploy:migrate' task) prior to updating the symlink. Note that the \ | |
update in this case it is not atomic, and transactions are not used, \ | |
because migrations are not guaranteed to be reversible. | |
DESC | |
task :migrations do | |
set :migrate_target, :latest | |
set(:branch) do | |
br = Capistrano::CLI.ui.ask 'What branch do you want to deploy?: '.downcase | |
raise 'You can only deploy master branch to production.' if (stage.to_s.upcase == 'PRODUCTION') && br != 'master' | |
br | |
end | |
puts "*** Deploying to the #{stage.to_s.upcase} server!" | |
update_code | |
migrate | |
symlink | |
restart | |
# cleanup old deployments | |
deploy.cleanup | |
# Send deployment notification, except for the default stage | |
end | |
desc "Create symlink to shared files and folders on each release." | |
task :symlink_shared do | |
# run "mkdir -p #{shared_dir}/bundle && ln -nfs #{shared_path}/bundle #{release_path}/.bundle" | |
run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml" | |
run "ln -nfs #{shared_path}/assets #{release_path}/public/assets" | |
end | |
after "deploy:update_code", "deploy:symlink_shared" | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$:.unshift(File.expand_path('./lib', ENV['rvm_path'])) | |
require 'rvm/capistrano' | |
default_run_options[:pty] = true | |
set :domain, "staging.your_domain.com" | |
set :deploy_to, "/your_deploy_path/#{application}" | |
set :use_sudo, false | |
set :rvm_ruby_string, "ruby-1.9.2-p290@your_application_name" | |
set :rails_env, "staging" | |
role :app, "#{domain}" | |
role :web, "#{domain}" | |
role :db, "#{domain}", :primary => true | |
set :user, "user_name" | |
# set :password, "deploy2k" # not necessary if using ssh keys | |
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment