rosa-build/config/deploy.rb

102 lines
3.1 KiB
Ruby
Raw Normal View History

2012-01-30 20:39:34 +00:00
# -*- encoding : utf-8 -*-
$:.unshift File.expand_path('.')
2011-10-25 23:30:39 +01:00
$:.unshift(File.expand_path('./lib', ENV['rvm_path']))
set :rvm_type, :user
set :default_environment, {
'LANG' => 'en_US.UTF-8'
}
#set :rake, "#{rake} --trace"
require 'rvm/capistrano'
2011-10-25 23:30:39 +01:00
require 'bundler/capistrano'
require 'delayed/recipes'
2011-10-25 23:30:39 +01:00
require 'airbrake/capistrano'
2011-10-31 17:50:45 +00:00
set :whenever_command, "bundle exec whenever"
# require "whenever/capistrano"
2011-10-31 17:50:45 +00:00
require 'capistrano/ext/multistage'
set :default_stage, "staging"
# set :stages, %w(production staging pingwinsoft) # auto readed
# main details
2011-09-29 14:24:33 +01:00
ssh_options[:forward_agent] = true
2011-12-06 14:52:31 +00:00
default_run_options[:pty] = true
2011-10-25 23:30:39 +01:00
set :application, "rosa_build"
2011-12-06 18:35:19 +00:00
set(:deploy_to) { "/srv/#{application}" }
set :user, "rosa"
set :use_sudo, false
set :keep_releases, 3
set :scm, :git
2011-10-25 23:30:39 +01:00
set :repository, "git@github.com:warpc/rosa-build.git"
set :deploy_via, :remote_cache
require 'lib/recipes/nginx'
require 'lib/recipes/unicorn'
require 'lib/recipes/bluepill'
namespace :deploy do
task :stub_xml_rpc do
2011-12-06 18:35:19 +00:00
path = File.join(release_path, 'config', 'environment.rb')
code = %Q{\nrequire 'stub_xml_rpc'\n}
puts "Stub XML RPC"
run %Q{echo "#{code}" >> #{path}}
end
task :symlink_all, :roles => :app do
2011-12-06 19:33:35 +00:00
run "mkdir -p #{fetch :shared_path}/config"
# Setup DB
2011-12-06 19:33:35 +00:00
run "cp -n #{fetch :release_path}/config/database.yml.sample #{fetch :shared_path}/config/database.yml"
2011-12-06 18:35:19 +00:00
run "ln -nfs #{fetch :shared_path}/config/database.yml #{fetch :release_path}/config/database.yml"
# Setup application
run "cp -n #{fetch :release_path}/config/deploy/application.#{fetch :stage}.yml #{fetch :shared_path}/config/application.yml"
2011-12-06 18:35:19 +00:00
run "ln -nfs #{fetch :shared_path}/config/application.yml #{fetch :release_path}/config/application.yml"
# It will survive downloads folder between deployments
2011-12-06 19:33:35 +00:00
run "mkdir -p #{fetch :shared_path}/downloads"
2011-12-06 18:35:19 +00:00
run "ln -nfs #{fetch :shared_path}/downloads/ #{fetch :release_path}/public/downloads"
end
task :symlink_pids, :roles => :app do
run "cd #{fetch :shared_path}/tmp && ln -nfs ../pids pids"
end
# Speed up precompile (http://www.bencurtis.com/2011/12/skipping-asset-compilation-with-capistrano )
namespace :assets do
task :precompile, :roles => :web, :except => { :no_release => true } do
from = source.next_revision(current_revision)
if capture("cd #{latest_release} && #{source.local.log(from)} app/assets/ lib/assets/ vendor/assets/ | wc -l").to_i > 0
run %Q{cd #{latest_release} && #{rake} RAILS_ENV=#{rails_env} #{asset_env} assets:precompile}
else
logger.info "Skipping asset pre-compilation because there were no asset changes"
end
end
end
2011-03-29 18:06:21 +01:00
end
after "deploy:finalize_update", "deploy:symlink_all"
after "deploy:update_code", "deploy:migrate"
after "deploy:setup", "deploy:symlink_pids"
# after "deploy:restart", "bluepill:start" # "bluepill:processes:restart_dj" # "bluepill:restart"
# DJ
after "deploy:stop", "delayed_job:stop"
after "deploy:start", "delayed_job:start"
# after "deploy:restart", "delayed_job:restart"
after "deploy:restart", "deploy:cleanup"
2011-12-06 18:35:19 +00:00
require 'cape'
namespace :rake_tasks do
Cape do
mirror_rake_tasks 'db:seeds'
end
end