Created
December 6, 2011 06:07
-
-
Save kevinkarwaski/1436972 to your computer and use it in GitHub Desktop.
Multi-stage Capistrano Example
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
# | |
# Multi-stage Capistrano Example | |
# | |
# Example calls: cap dev deploy, cap prod deploy | |
# Env specific data defined in deploy/dev, deploy/prod | |
# | |
# Required gems: capistrano, capistrano-ext, rubygems, cloudfiles | |
# | |
require 'capistrano/ext/multistage' | |
require 'rubygems' | |
require 'thinking_sphinx/deploy/capistrano' | |
#require 'cloudfiles' | |
#require 'fog' | |
# capistrano-ext provides multi-stage deployments. | |
set :stages, %w(dev prod) | |
set :default_stage, "dev" | |
# Set our SCM details... | |
set :scm, :git | |
set :repository, "git-repo-path" | |
set :branch, "master" | |
set :deploy_via, :remote_cache | |
# Use the web user account on the server for deployments. | |
set :user, "webuser" | |
set :port, 50001 | |
set :ssh_options, {:forward_agent => true} | |
set :use_sudo, false | |
# Upload static assets to the CDN... | |
#namespace :sync_assets do | |
# | |
# desc "Uploading static assets..." | |
# task :upload, roles => :app do | |
# storage = Fog::Compute.new( | |
# :provider => 'Rackspace', | |
# :rackspace_api_key => key, | |
# :rackspace_username => username | |
# ) | |
# Deploy the app and restart passenger (mod_rails). | |
namespace :deploy do | |
desc "Restarting mod_rails with restart.txt" | |
task :restart, :roles => :app, :except => { :no_release => true } do | |
run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}" | |
end | |
desc "Update the crontab file" | |
task :update_crontab, :roles => :db do | |
run "cd #{current_path} && whenever --update-crontab #{application}" | |
end | |
desc "Stop sphinx before deploying app." | |
task :stop_sphinx, :roles => [:app] do | |
#run "cd #{current_path} && rake RAILS_ENV=development ts:stop" | |
thinking_sphinx.stop | |
end | |
desc "Symlink Indexes, recreate config files and start sphinx." | |
task :start_sphinx, :roles => [:app] do | |
thinking_sphinx.configure | |
thinking_sphinx.start | |
end | |
desc "Upload credentials files..." | |
task :upload_creds, :roles => :app do | |
top.upload("config/rackspace_cloudfiles.yml", "#{shared_path}/config", :via => :scp) | |
top.upload("config/database.yml", "#{shared_path}/config", :via => :scp) | |
end | |
desc "Create symlinks for configuration files and uploads directory..." | |
task :create_symlinks, :roles => :app do | |
#run "ln -sf #{shared_path}/db #{current_path}/" | |
run "ln -sf #{shared_path}/config/rackspace_cloudfiles.yml #{current_path}/config/" | |
run "ln -sf #{shared_path}/uploads #{current_path}/public/" | |
end | |
[:start, :stop].each do |t| | |
desc "#{t} task is a no-op with mod_rails" | |
task t, :roles => :app do ; end | |
end | |
end | |
# After deploying, update the ruby cronjobs with whenever gem, | |
# rebuild the sphinx search index, and re-create the symlinks | |
# for the credentials files and ensure that only the 5 most | |
# recent releases live on the server. | |
before "deploy", "deploy:stop_sphinx" | |
#after "deploy", "deploy:update_crontab" | |
#after "deploy", "deploy:upload_creds" | |
after "deploy", "deploy:create_symlinks" | |
before "deploy", "deploy:start_sphinx" | |
after "deploy", "deploy:cleanup" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment