rosa-build/config/deploy.rb.sample

140 lines
4.8 KiB
Plaintext
Raw Normal View History

2013-03-04 22:51:07 +00:00
require 'cape'
require 'capistrano_colors'
set :default_environment, {
'LANG' => 'en_US.UTF-8'
}
require 'rvm/capistrano'
require 'bundler/capistrano'
2014-02-13 14:59:09 +00:00
require 'new_relic/recipes'
2013-03-04 22:51:07 +00:00
set :whenever_command, "bundle exec whenever"
require 'capistrano/ext/multistage'
# main details
ssh_options[:forward_agent] = true
default_run_options[:pty] = true
2014-02-25 08:40:39 +00:00
set :rvm_ruby_string, 'ruby-2.1.1@rosa_build'
2013-03-04 22:51:07 +00:00
set :application, "rosa_build"
set(:deploy_to) { "/srv/#{application}" }
2014-02-13 14:59:09 +00:00
set :user, "user"
2013-03-04 22:51:07 +00:00
set :use_sudo, false
set :keep_releases, 3
2014-02-13 14:59:09 +00:00
set :git_enable_submodules, 1
2013-03-04 22:51:07 +00:00
set :scm, :git
2014-02-13 14:59:09 +00:00
set :repository, "git@abf.rosalinux.ru:abf/rosa-build.git"
2013-03-04 22:51:07 +00:00
require './lib/recipes/nginx'
2013-11-28 15:23:37 +00:00
require 'puma/capistrano'
2013-03-04 22:51:07 +00:00
set :workers_count, 4
require './lib/recipes/resque'
2014-03-06 15:45:33 +00:00
require './lib/recipes/skype'
set :skype_topic, 'ABF' # Skype chat topic name
2013-03-04 22:51:07 +00:00
namespace :deploy do
task :symlink_all, :roles => :app do
run "mkdir -p #{fetch :shared_path}/config"
# Setup DB, application, newrelic
%w(database application newrelic).each do |config|
run "cp -n #{fetch :release_path}/config/#{config}.yml.sample #{fetch :shared_path}/config/#{config}.yml"
run "ln -nfs #{fetch :shared_path}/config/#{config}.yml #{fetch :release_path}/config/#{config}.yml"
end
# It will survive downloads folder between deployments
run "mkdir -p #{fetch :shared_path}/downloads"
run "ln -nfs #{fetch :shared_path}/downloads/ #{fetch :release_path}/public/downloads"
2014-03-28 23:09:04 +00:00
# It will survive sitemaps folder between deployments
run "mkdir -p #{fetch :shared_path}/sitemaps"
run "ln -nfs #{fetch :shared_path}/sitemaps #{fetch :release_path}/public/sitemaps"
2013-03-04 22:51:07 +00:00
end
task :symlink_pids, :roles => :app do
run "cd #{fetch :shared_path}/tmp && ln -nfs ../pids pids"
end
2015-02-04 00:33:25 +00:00
desc 'Copy compiled assets'
task :copy_assets, :roles => :app do
2015-02-04 13:22:10 +00:00
%w(new_application-*.css new_application-*.css.gz new_application-*.js new_application-*.js.gz).each do |f|
2015-02-04 00:33:25 +00:00
asset_glob = "#{fetch :shared_path}/assets/#{f}"
asset_file = capture %Q{ruby -e "print Dir.glob('#{asset_glob}').max_by { |file| File.mtime(file) }"}
puts asset_file
if asset_file
2015-02-04 13:22:10 +00:00
run "ln -fs #{asset_file} #{fetch :shared_path}/assets/#{ f.gsub('-*', '') }"
2015-02-04 00:33:25 +00:00
else
error "Error #{f} asset does not exist"
end
end
end
2013-03-04 22:51:07 +00:00
end
after "deploy:finalize_update", "deploy:symlink_all"
after "deploy:update_code", "deploy:migrate"
after "deploy:setup", "deploy:symlink_pids"
# Resque
after "deploy:stop", "resque:stop"
2014-02-13 18:52:50 +00:00
after "resque:stop", "resque:scheduler:stop"
2013-03-04 22:51:07 +00:00
after "deploy:start", "resque:start"
2014-02-13 18:52:50 +00:00
after "resque:start", "resque:scheduler:start"
2013-03-04 22:51:07 +00:00
after "deploy:restart", "resque:restart"
2014-02-13 18:52:50 +00:00
after "resque:restart", "resque:scheduler:restart"
2013-03-04 22:51:07 +00:00
after "deploy:restart", "deploy:cleanup"
2015-02-04 00:33:25 +00:00
after "deploy:cleanup", "deploy:copy_assets"
2013-03-04 22:51:07 +00:00
namespace :rake_tasks do
Cape do
mirror_rake_tasks 'db:seeds'
end
end
2014-02-13 14:59:09 +00:00
namespace :puma do
desc 'Restart puma'
task :restart, :roles => :app, :on_no_matching_servers => :continue do
begin
stop
rescue Capistrano::CommandError => ex
puts "Failed to restart puma: #{ex}\nAssuming not started."
ensure
start
end
end
2013-09-27 13:09:18 +01:00
end
2013-03-04 22:51:07 +00: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]
local_settings = YAML::load_file("config/database.yml")["development"]
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