Skip to content

Instantly share code, notes, and snippets.

@johngrimes
Created April 22, 2010 09:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johngrimes/375047 to your computer and use it in GitHub Desktop.
Save johngrimes/375047 to your computer and use it in GitHub Desktop.
Capistrano recipe for Rails app
require 'bundler/capistrano'
require 'rvm/capistrano'
set :application, 'myapp'
set :repository, 'git@github.com:johngrimes/myapp.git'
set :scm, 'git'
set :bundle_flags, '--deployment'
set :bundle_without, []
set :rvm_ruby_string, '1.8.7@myapp'
if ENV['branch']
set :branch, ENV['branch']
end
set :user, 'www'
set :runner, 'www'
set :use_sudo, false
role :web, '255.255.255.255'
set :deploy_to, '/var/www/sites/myapp-staging'
environment = 'staging'
task :to_staging do
set :deploy_to, '/var/www/sites/myapp-staging'
environment = 'staging'
end
task :to_prod do
set :deploy_to, '/var/www/sites/myapp'
environment = 'production'
end
namespace :deploy do
task :cold, :roles => :web do
update
create_symlinks
load_schema
run_tests
end
task :default, :roles => :web do
update
create_symlinks
migrate
run_tests
restart
end
task :load_schema, :roles => :web do
run "cd #{release_path} && rake db:schema:load RAILS_ENV=development"
run "cd #{release_path} && rake db:schema:load RAILS_ENV=#{environment}"
end
task :migrate, :roles => :web do
run "cd #{release_path} && rake db:migrate RAILS_ENV=development"
run "cd #{release_path} && rake db:migrate RAILS_ENV=#{environment}"
end
task :create_symlinks, :roles => :web do
run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
run "ln -nfs #{shared_path}/config/unicorn#{environment == 'staging' ? '-staging' : ''}.rb #{release_path}/config/unicorn#{environment == 'staging' ? '-staging' : ''}.rb"
end
task :run_tests, :roles => :web do
run "cd #{release_path} && rake db:test:prepare"
run "cd #{release_path} && rake spec"
end
task :restart, :roles => :web do
run "kill -HUP `cat #{shared_path}/pids/unicorn.pid`"
end
end
after 'deploy', 'deploy:cleanup'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment