capistrano, thin, remote_cache, safe credentials and symlinked vendor/rails
June 12th, 2008 • Uncategorized
set :application, "coolapp"
set :repository, "http://snusnu.info/svn/#{coolapp}/trunk/coolapp"
set :deploy_via, :remote_cache
set :deploy_to, "/u/apps/coolapp"
role :app, "snusnu.info", :primary => true
# rely on ssh-agent or the likes to serve our private key on authentication
ssh_options[:port] = 22
ssh_options[:username] = 'coolio'
ssh_options[:host_key] = "ssh-rsa"
ssh_options[:auth_methods] = %w(publickey)
# workaround for capistrano-2.3 bug
ssh_options[:keys] = %w(~/.ssh/id_dsa.snusnu.info ~/.ssh/id_rsa.snusnu.info)
# taken from Advanced Rails Recipes
desc "Watch multiple log files at the same time"
task :tail_log, :roles => :app do
stream "tail -f #{shared_path}/log/production.log"
end
# call this if 'deploy_via :remote_cache' is set
# and you want to deploy a different tag or branch
# inspired from Jonathan Weiss' explanation of the issue
# http://blog.innerewut.de/2008/3/12/remote-cache-pitfalls
task :delete_remote_cache, :roles => :app do
run "rm -rf #{shared_path}/cached-copy"
end
namespace :symlink do
task :vendor_rails, :roles => :app do
run "ln -s #{shared_path}/rails #{release_path}/vendor/rails"
end
end
after "deploy:update_code", "symlink:vendor_rails"
namespace :thin do
%w(start stop restart).each do |action|
desc "#{action.to_s.capitalize} the application's thin server(s)"
task action.to_sym, :roles => :app do
run "thin #{action} -C #{deploy_to}/current/config/thin.yml"
end
end
end
namespace :deploy do
# we don't need sudo for cleanup
before("deploy:cleanup") do
set :use_sudo, false
end
# taken from Advanced Rails Recipes
desc "Runs after every successful deployment"
task :after_default do
cleanup
end
# taken from Advanced Rails Recipes
task :copy_database_configuration do
production_db_config = "#{deploy_to}/shared/production.database.yml"
run "cp #{production_db_config} #{release_path}/config/database.yml"
end
after "deploy:update_code", "deploy:copy_database_configuration"
%w(start stop restart).each do |action|
desc "#{action.to_s.capitalize} the thin server(s)"
task action.to_sym do
find_and_execute_task("thin:#{action}")
end
end
end