rosa-build/config/deploy.rb.sample

118 lines
3.9 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-13 14:59:09 +00:00
set :rvm_ruby_string, 'ruby-2.1.0@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'
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"
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"
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