|
# config/deploy.rb |
|
# custom file for whenever.rb with roles, https://gist.github.com/priyank-gupta/e15b5dab570e54cde2ee |
|
|
|
require 'mina/multistage' |
|
require 'mina/bundler' |
|
require 'mina/rails' |
|
require 'mina/git' |
|
require 'yaml' |
|
# require custom file for whenever.rb with roles, https://gist.github.com/priyank-gupta/e15b5dab570e54cde2ee |
|
require_relative '../lib/mina/whenever' |
|
|
|
desc 'Default Setup.' |
|
task :defaults do |
|
set_default :term_mode, :pretty |
|
set_default :rails_env, 'staging' |
|
set_default :branch, 'master' |
|
end |
|
|
|
set :shared_paths, ['log', 'config/secrets.yml', 'config/aws.yml', 'config/database.yml', 'tmp', 'public/assets'] |
|
set :asset_paths, ['vendor/assets/', 'app/assets/', 'app/assets/fonts/'] |
|
|
|
set :default_server, :staging |
|
set :server, ENV['on'] || default_server |
|
invoke :"env:#{server}" |
|
set :app_path, lambda { "#{deploy_to}/#{current_path}" } |
|
|
|
# custom setup task |
|
task :setup => :environment do |
|
queue! %[mkdir -p "#{deploy_to}/#{shared_path}/log"] |
|
queue! %[chmod g+rx,u+rwx "#{deploy_to}/#{shared_path}/log"] |
|
|
|
queue! %[mkdir -p "#{deploy_to}/#{shared_path}/config"] |
|
queue! %[chmod g+rx,u+rwx "#{deploy_to}/#{shared_path}/config"] |
|
|
|
queue! %[mkdir -p "#{deploy_to}/#{shared_path}/tmp"] |
|
queue! %[chmod g+rx,u+rwx "#{deploy_to}/#{shared_path}/tmp"] |
|
|
|
queue! %[mkdir -p "#{deploy_to}/#{shared_path}/public/assets"] |
|
queue! %[chmod g+rx,u+rwx "#{deploy_to}/#{shared_path}/public/assets"] |
|
|
|
queue! %[touch "#{deploy_to}/#{shared_path}/config/database.yml"] |
|
queue %[echo "-----> Be sure to edit '#{deploy_to}/#{shared_path}/config/database.yml'."] |
|
end |
|
|
|
# custom deploy task |
|
desc "Deploys the current version to the server." |
|
task :deploy => :environment do |
|
deploy do |
|
to :prepare do |
|
end |
|
|
|
invoke :'git:clone' |
|
invoke :'deploy:link_shared_paths' |
|
invoke :'bundle:install' |
|
invoke :'rails:db_migrate' |
|
invoke :'deploy:cleanup' |
|
|
|
to :launch do |
|
queue "mkdir -p #{app_path}/tmp/" |
|
invoke :'nginx:restart' |
|
invoke :'whenever:update' |
|
if role?(:admin) || role?(:staging) |
|
invoke :'delayed_job:restart' |
|
end |
|
end |
|
end |
|
end |
|
|
|
# Custom nginx tasks |
|
# Module for the same is also available, mina-nginx |
|
namespace :nginx do |
|
%w(stop start restart reload status).each do |action| |
|
desc "#{action.capitalize} Nginx" |
|
task action.to_sym do |
|
queue %{echo "-----> #{action.capitalize} Nginx"} |
|
set :term_mode, :system |
|
queue "sudo service nginx #{action}" |
|
end |
|
end |
|
end |
|
|
|
# Custom Delayed Job tasks |
|
# Module is also available |
|
namespace :delayed_job do |
|
%w(stop start restart).each do |action| |
|
desc "#{action.capitalize} Delayed Job" |
|
task action.to_sym do |
|
queue %{echo "-----> #{action.capitalize} Delayed Job"} |
|
queue "cd #{app_path} ; RAILS_ENV=#{rails_env} ./bin/delayed_job #{action}" |
|
end |
|
end |
|
end |
|
|
|
def role?(role) |
|
roles.include?(role) |
|
end |