2012-01-30 20:39:34 +00:00
|
|
|
# -*- encoding : utf-8 -*-
|
2012-05-03 17:48:22 +01:00
|
|
|
require 'cape'
|
|
|
|
require 'capistrano_colors'
|
2012-01-19 16:20:30 +00:00
|
|
|
|
2012-03-26 20:18:33 +01:00
|
|
|
set :default_environment, {
|
|
|
|
'LANG' => 'en_US.UTF-8'
|
|
|
|
}
|
|
|
|
|
2012-03-26 23:19:47 +01:00
|
|
|
#set :rake, "#{rake} --trace"
|
2012-03-26 20:18:33 +01:00
|
|
|
|
2011-03-28 16:49:22 +01:00
|
|
|
require 'rvm/capistrano'
|
2011-10-25 23:30:39 +01:00
|
|
|
require 'bundler/capistrano'
|
|
|
|
require 'airbrake/capistrano'
|
2012-01-19 16:20:30 +00:00
|
|
|
|
2011-10-31 17:50:45 +00:00
|
|
|
set :whenever_command, "bundle exec whenever"
|
2011-12-06 22:21:08 +00:00
|
|
|
# require "whenever/capistrano"
|
2011-10-31 17:50:45 +00:00
|
|
|
|
2011-11-09 20:15:02 +00:00
|
|
|
require 'capistrano/ext/multistage'
|
2012-01-19 16:20:30 +00:00
|
|
|
set :default_stage, "staging"
|
|
|
|
# set :stages, %w(production staging pingwinsoft) # auto readed
|
2011-11-09 20:15:02 +00:00
|
|
|
|
2011-03-28 16:49:22 +01:00
|
|
|
# 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
|
|
|
|
2011-03-28 16:49:22 +01:00
|
|
|
set :application, "rosa_build"
|
2011-12-06 18:35:19 +00:00
|
|
|
set(:deploy_to) { "/srv/#{application}" }
|
2011-12-06 14:45:20 +00:00
|
|
|
set :user, "rosa"
|
|
|
|
set :use_sudo, false
|
|
|
|
set :keep_releases, 3
|
2011-03-28 16:49:22 +01:00
|
|
|
|
2012-01-19 16:20:30 +00:00
|
|
|
set :scm, :git
|
2011-10-25 23:30:39 +01:00
|
|
|
set :repository, "git@github.com:warpc/rosa-build.git"
|
2012-01-19 16:20:30 +00:00
|
|
|
set :deploy_via, :remote_cache
|
2011-03-28 16:49:22 +01:00
|
|
|
|
2012-05-03 17:48:22 +01:00
|
|
|
require './lib/recipes/nginx'
|
|
|
|
require './lib/recipes/unicorn'
|
2012-06-07 16:13:58 +01:00
|
|
|
#require './lib/recipes/bluepill'
|
2012-06-09 15:53:00 +01:00
|
|
|
set :workers_count, 4
|
2012-06-07 16:13:58 +01:00
|
|
|
require './lib/recipes/resque'
|
2011-12-06 14:45:20 +00:00
|
|
|
|
2012-01-19 19:07:47 +00:00
|
|
|
namespace :deploy do
|
2011-12-06 14:45:20 +00:00
|
|
|
task :stub_xml_rpc do
|
2011-12-06 18:35:19 +00:00
|
|
|
path = File.join(release_path, 'config', 'environment.rb')
|
2011-12-06 14:45:20 +00:00
|
|
|
code = %Q{\nrequire 'stub_xml_rpc'\n}
|
|
|
|
puts "Stub XML RPC"
|
|
|
|
run %Q{echo "#{code}" >> #{path}}
|
2011-03-28 16:49:22 +01:00
|
|
|
end
|
|
|
|
|
2012-01-19 19:07:47 +00:00
|
|
|
task :symlink_all, :roles => :app do
|
2011-12-06 19:33:35 +00:00
|
|
|
run "mkdir -p #{fetch :shared_path}/config"
|
2012-04-03 16:12:11 +01:00
|
|
|
|
2012-01-19 16:20:30 +00:00
|
|
|
# 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"
|
2012-04-03 16:12:11 +01:00
|
|
|
|
2012-01-19 16:20:30 +00:00
|
|
|
# Setup application
|
2012-09-13 21:46:56 +01:00
|
|
|
run "cp -n #{fetch :release_path}/config/application.yml.sample #{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"
|
2011-12-06 14:45:20 +00:00
|
|
|
|
2012-01-19 16:20:30 +00:00
|
|
|
# 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"
|
2011-03-29 17:35:42 +01:00
|
|
|
end
|
2012-01-19 19:07:47 +00:00
|
|
|
|
|
|
|
task :symlink_pids, :roles => :app do
|
|
|
|
run "cd #{fetch :shared_path}/tmp && ln -nfs ../pids pids"
|
|
|
|
end
|
2012-04-03 16:12:11 +01:00
|
|
|
|
2012-03-26 23:19:47 +01:00
|
|
|
# Speed up precompile (http://www.bencurtis.com/2011/12/skipping-asset-compilation-with-capistrano )
|
2012-03-31 00:37:54 +01:00
|
|
|
# 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 "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
|
2012-04-03 16:12:11 +01:00
|
|
|
# end
|
2011-03-29 18:06:21 +01:00
|
|
|
end
|
2011-11-29 22:23:09 +00:00
|
|
|
|
2012-02-27 23:16:14 +00:00
|
|
|
after "deploy:finalize_update", "deploy:symlink_all"
|
|
|
|
after "deploy:update_code", "deploy:migrate"
|
2012-01-19 19:07:47 +00:00
|
|
|
after "deploy:setup", "deploy:symlink_pids"
|
2012-06-07 10:27:19 +01:00
|
|
|
|
|
|
|
# Bluepill
|
2012-06-07 16:13:58 +01:00
|
|
|
#after "deploy:restart", "bluepill:restart" # "bluepill:processes:restart_dj" # "bluepill:restart"
|
|
|
|
#after "deploy:start", "bluepill:start"
|
|
|
|
#after "deploy:stop", "bluepill:stop"
|
2012-02-28 10:09:27 +00:00
|
|
|
|
2012-06-01 13:54:58 +01:00
|
|
|
# Resque
|
2012-06-07 16:13:58 +01:00
|
|
|
after "deploy:stop", "resque:stop"
|
|
|
|
after "deploy:start", "resque:start"
|
|
|
|
after "deploy:restart", "resque:restart"
|
2012-06-01 13:54:58 +01:00
|
|
|
|
2012-02-17 14:32:03 +00:00
|
|
|
after "deploy:restart", "deploy:cleanup"
|
2011-12-06 18:35:19 +00:00
|
|
|
|
|
|
|
namespace :rake_tasks do
|
|
|
|
Cape do
|
|
|
|
mirror_rake_tasks 'db:seeds'
|
|
|
|
end
|
|
|
|
end
|
2012-08-15 14:52:32 +01:00
|
|
|
|
|
|
|
namespace :update do
|
|
|
|
desc "Copy remote production shared files to localhost"
|
|
|
|
task :shared do
|
|
|
|
run_locally "rsync --recursive --times --rsh=ssh --compress --human-readable --progress #{user}@#{domain}:#{shared_path}/shared_contents/uploads public/uploads"
|
|
|
|
end
|
|
|
|
|
|
|
|
desc "Dump remote production postgresql database, rsync to localhost"
|
|
|
|
task :postgresql do
|
|
|
|
get("#{current_path}/config/database.yml", "tmp/database.yml")
|
|
|
|
|
|
|
|
remote_settings = YAML::load_file("tmp/database.yml")[rails_env]
|
2012-08-27 22:12:53 +01:00
|
|
|
local_settings = YAML::load_file("config/database.yml")["development"]
|
|
|
|
|
2012-08-15 14:52:32 +01:00
|
|
|
|
|
|
|
run "export PGPASSWORD=#{remote_settings["password"]} && pg_dump --host=#{remote_settings["host"]} --port=#{remote_settings["port"]} --username #{remote_settings["username"]} --file #{current_path}/tmp/#{remote_settings["database"]}_dump -Fc #{remote_settings["database"]}"
|
|
|
|
|
|
|
|
run_locally "rsync --recursive --times --rsh=ssh --compress --human-readable --progress #{user}@#{domain}:#{current_path}/tmp/#{remote_settings["database"]}_dump tmp/"
|
|
|
|
|
|
|
|
run_locally "dropdb -U #{local_settings["username"]} --host=#{local_settings["host"]} --port=#{local_settings["port"]} #{local_settings["database"]}"
|
|
|
|
run_locally "createdb -U #{local_settings["username"]} --host=#{local_settings["host"]} --port=#{local_settings["port"]} -T template0 #{local_settings["database"]}"
|
|
|
|
run_locally "pg_restore -U #{local_settings["username"]} --host=#{local_settings["host"]} --port=#{local_settings["port"]} -d #{local_settings["database"]} tmp/#{remote_settings["database"]}_dump"
|
|
|
|
end
|
|
|
|
|
|
|
|
desc "Dump all remote data to localhost"
|
|
|
|
task :all do
|
|
|
|
# update.shared
|
|
|
|
update.postgresql
|
|
|
|
end
|
|
|
|
end
|