2015-05-05 03:10:25 +02:00
|
|
|
require "bundler/capistrano"
|
|
|
|
require "rvm/capistrano"
|
|
|
|
require 'capistrano/ext/multistage'
|
2016-03-23 18:39:41 +01:00
|
|
|
require 'capistrano/maintenance'
|
2015-05-05 03:10:25 +02:00
|
|
|
|
|
|
|
set :stages, %w(production staging)
|
|
|
|
set :default_stage, "staging"
|
|
|
|
|
|
|
|
|
|
|
|
default_run_options[:pty] = true
|
|
|
|
ssh_options[:forward_agent] = true
|
|
|
|
|
|
|
|
after "deploy", "deploy:cleanup" # keep only the last 5 releases
|
|
|
|
|
2016-03-23 18:39:41 +01:00
|
|
|
# after "deploy:finalize_update", "deploy:assets:precompile"
|
|
|
|
|
2015-05-05 03:10:25 +02:00
|
|
|
namespace :deploy do
|
|
|
|
%w[start stop restart].each do |command|
|
|
|
|
desc "#{command} unicorn server"
|
|
|
|
task command, roles: :app, except: {no_release: true} do
|
|
|
|
run "/etc/init.d/unicorn_#{application} #{command}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
desc 'Symlink bootstrap glyphicons'
|
|
|
|
task :symlink, :roles => :web, :except => { :no_release => true } do
|
|
|
|
#run "rm -R #{shared_path}/assets/bootstrap/glyphicons-halflings-regular-*"
|
|
|
|
run "ln -nfs #{shared_path}/assets/bootstrap/glyphicons-halflings-regular-*.ttf #{shared_path}/assets/bootstrap/glyphicons-halflings-regular.ttf"
|
|
|
|
run "ln -nfs #{shared_path}/assets/bootstrap/glyphicons-halflings-regular-*.svg #{shared_path}/assets/bootstrap/glyphicons-halflings-regular.svg"
|
|
|
|
run "ln -nfs #{shared_path}/assets/bootstrap/glyphicons-halflings-regular-*.woff #{shared_path}/assets/bootstrap/glyphicons-halflings-regular.woff"
|
|
|
|
run "ln -nfs #{shared_path}/assets/bootstrap/glyphicons-halflings-regular-*.woff2 #{shared_path}/assets/bootstrap/glyphicons-halflings-regular.woff2"
|
|
|
|
run "ln -nfs #{shared_path}/assets/bootstrap/glyphicons-halflings-regular-*.eot #{shared_path}/assets/bootstrap/glyphicons-halflings-regular.eot"
|
|
|
|
#run "rm -R #{shared_path}/assets/select2/select2*"
|
|
|
|
run "ln -nfs #{shared_path}/assets/select2/select2-*.png #{shared_path}/assets/select2.png"
|
|
|
|
run "ln -nfs #{shared_path}/assets/select2/select2x2-*.png #{shared_path}/assets/select2x2.png"
|
|
|
|
run "ln -nfs #{shared_path}/assets/select2/select2-spinner-*.gif #{shared_path}/assets/select2-spinner.gif"
|
|
|
|
end
|
|
|
|
|
|
|
|
task :setup_config, roles: :app do
|
|
|
|
sudo "ln -nfs #{current_path}/config/nginx.conf /etc/nginx/sites-enabled/#{application}"
|
|
|
|
sudo "ln -nfs #{current_path}/config/unicorn_init.sh /etc/init.d/unicorn_#{application}"
|
|
|
|
run "mkdir -p #{shared_path}/config"
|
|
|
|
run "mkdir -p #{shared_path}/uploads"
|
2016-03-23 18:39:41 +01:00
|
|
|
run "mkdir -p #{shared_path}/invoices"
|
|
|
|
put File.read("config/database.yml"), "#{shared_path}/config/database.yml"
|
|
|
|
puts "Now edit #{shared_path}/config/database.yml and add your username and password"
|
2015-05-05 03:10:25 +02:00
|
|
|
put File.read("config/application.yml"), "#{shared_path}/config/application.yml"
|
|
|
|
puts "Now edit #{shared_path}/config/application.yml and add your ENV vars"
|
|
|
|
|
|
|
|
end
|
|
|
|
after "deploy:setup", "deploy:setup_config"
|
|
|
|
|
|
|
|
task :symlink_config, roles: :app do
|
|
|
|
run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
|
|
|
|
run "rm -rf #{release_path}/config/application.yml"
|
|
|
|
run "ln -nfs #{shared_path}/config/application.yml #{release_path}/config/application.yml"
|
|
|
|
end
|
|
|
|
after "deploy:finalize_update", "deploy:symlink_config"
|
|
|
|
|
|
|
|
desc "Make sure local git is in sync with remote."
|
|
|
|
task :check_revision, roles: :web do
|
|
|
|
unless `git rev-parse HEAD` == `git rev-parse origin/master`
|
|
|
|
puts "WARNING: HEAD is not the same as origin/master"
|
|
|
|
puts "Run `git push` to sync changes."
|
|
|
|
exit
|
|
|
|
end
|
|
|
|
end
|
|
|
|
#before "deploy", "deploy:check_revision"
|
|
|
|
|
|
|
|
desc "load seed to bd"
|
|
|
|
task :load_seed, :roles => :app do
|
|
|
|
run "cd #{current_path} && bundle exec rake db:seed RAILS_ENV=production"
|
|
|
|
end
|
|
|
|
|
|
|
|
desc "Rake db:migrate"
|
|
|
|
task :db_migrate, :roles => :app do
|
|
|
|
run "cd #{current_path} && bundle exec rake db:migrate RAILS_ENV=production"
|
|
|
|
end
|
|
|
|
after "deploy:create_symlink", "deploy:db_migrate"
|
|
|
|
|
|
|
|
desc "Symlinks the uploads dir"
|
|
|
|
task :symlink_uploads_dir, :roles => :app do
|
|
|
|
run "rm -rf #{release_path}/public/uploads"
|
|
|
|
run "ln -nfs #{shared_path}/uploads/ #{release_path}/public/"
|
|
|
|
end
|
|
|
|
after "deploy:finalize_update", 'deploy:symlink_uploads_dir'
|
|
|
|
|
2016-03-23 18:39:41 +01:00
|
|
|
desc "Symlinks the invoices dir"
|
|
|
|
task :symlink_invoices_dir, :roles => :app do
|
|
|
|
run "rm -rf #{release_path}/invoices"
|
|
|
|
run "ln -nfs #{shared_path}/invoices/ #{release_path}/"
|
|
|
|
end
|
|
|
|
after "deploy:finalize_update", 'deploy:symlink_invoices_dir'
|
2015-05-05 03:10:25 +02:00
|
|
|
|
|
|
|
namespace :assets do
|
|
|
|
desc 'Run the precompile task locally and rsync with shared'
|
|
|
|
task :precompile, :roles => :web, :except => { :no_release => true } do
|
|
|
|
%x{bundle exec rake assets:precompile RAILS_ENV=production}
|
|
|
|
%x{rsync --recursive --times --rsh='ssh -p#{port}' --compress --human-readable --progress public/assets #{user}@#{domain}:#{shared_path}}
|
|
|
|
%x{bundle exec rake assets:clean}
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|