121 lines
4.0 KiB
Plaintext
121 lines
4.0 KiB
Plaintext
require 'cape'
|
|
require 'capistrano_colors'
|
|
|
|
set :default_environment, {
|
|
'LANG' => 'en_US.UTF-8'
|
|
}
|
|
|
|
require 'rvm/capistrano'
|
|
require 'bundler/capistrano'
|
|
require 'new_relic/recipes'
|
|
|
|
set :whenever_command, "bundle exec whenever"
|
|
|
|
require 'capistrano/ext/multistage'
|
|
|
|
# main details
|
|
ssh_options[:forward_agent] = true
|
|
default_run_options[:pty] = true
|
|
|
|
set :rvm_ruby_string, 'ruby-2.1.1@rosa_build'
|
|
set :application, "rosa_build"
|
|
set(:deploy_to) { "/srv/#{application}" }
|
|
set :user, "user"
|
|
set :use_sudo, false
|
|
set :keep_releases, 3
|
|
set :git_enable_submodules, 1
|
|
|
|
set :scm, :git
|
|
set :repository, "git@abf.rosalinux.ru:abf/rosa-build.git"
|
|
|
|
require './lib/recipes/nginx'
|
|
require 'puma/capistrano'
|
|
set :workers_count, 4
|
|
require './lib/recipes/resque'
|
|
|
|
require './lib/recipes/skype'
|
|
set :skype_topic, 'ABF' # Skype chat topic name
|
|
|
|
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"
|
|
end
|
|
|
|
task :symlink_pids, :roles => :app do
|
|
run "cd #{fetch :shared_path}/tmp && ln -nfs ../pids pids"
|
|
end
|
|
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"
|
|
after "resque:stop", "resque:scheduler:stop"
|
|
after "deploy:start", "resque:start"
|
|
after "resque:start", "resque:scheduler:start"
|
|
after "deploy:restart", "resque:restart"
|
|
after "resque:restart", "resque:scheduler:restart"
|
|
|
|
after "deploy:restart", "deploy:cleanup"
|
|
|
|
namespace :rake_tasks do
|
|
Cape do
|
|
mirror_rake_tasks 'db:seeds'
|
|
end
|
|
end
|
|
|
|
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
|
|
end
|
|
|
|
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
|