Last active
January 29, 2016 18:08
-
-
Save fousa/8918242 to your computer and use it in GitHub Desktop.
Deploy with mina on DigitalOcean server.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'mina/bundler' | |
require 'mina/rails' | |
require 'mina/git' | |
require 'mina/rvm' | |
require 'mina_sidekiq/tasks' | |
set :rails_env, 'production' | |
set :domain, 'YOUR_IP_OR_DOMAIN' | |
set :deploy_to, "/home/rails/#{rails_env}" | |
set :repository, '[email protected]:fousa/<YOUR_REPOSITORY>.git' | |
set :branch, 'master' | |
set :user, 'root' | |
set :ssh_options, '-A' | |
set :shared_paths, ['config/database.yml', 'log', 'pids'] | |
set :rvm_path, "/usr/local/rvm/bin/rvm" | |
task :environment do | |
invoke :'rvm:use[ruby-2.0.0-p353@default]' | |
end | |
namespace :whenever do | |
desc "Clear crontab" | |
task :clear do | |
queue %{ | |
echo "-----> Clear crontab for #{domain}_#{rails_env}" | |
#{echo_cmd %[cd #{deploy_to!}/#{current_path!} ; bundle exec whenever --clear-crontab #{domain}_#{rails_env} --set 'environment=#{rails_env}&path=#{deploy_to!}/#{current_path!}']} | |
} | |
end | |
desc "Update crontab" | |
task :update do | |
queue %{ | |
echo "-----> Update crontab for #{domain}_#{rails_env}" | |
#{echo_cmd %[cd #{deploy_to!}/#{current_path!} ; bundle exec whenever --update-crontab #{domain}_#{rails_env} --set 'environment=#{rails_env}&path=#{deploy_to!}/#{current_path!}']} | |
} | |
end | |
desc "Write crontab" | |
task :write do | |
queue %{ | |
echo "-----> Update crontab for #{domain}_#{rails_env}" | |
#{echo_cmd %[cd #{deploy_to!}/#{current_path!} ; bundle exec whenever --write-crontab #{domain}_#{rails_env} --set 'environment=#{rails_env}&path=#{deploy_to!}/#{current_path!}']} | |
} | |
end | |
end | |
namespace :unicorn do | |
set :unicorn_pid, "/home/unicorn/pids/unicorn.pid" | |
set :start_unicorn, %{ | |
service unicorn restart | |
} | |
desc "Start unicorn" | |
task :start => :environment do | |
queue 'echo "-----> Start Unicorn"' | |
queue! start_unicorn | |
end | |
desc "Stop unicorn" | |
task :stop do | |
queue 'echo "-----> Stop Unicorn"' | |
queue! %{ | |
test -s "#{unicorn_pid}" && kill -QUIT `cat "#{unicorn_pid}"` && echo "Stop Ok" && exit 0 | |
echo >&2 "Not running" | |
} | |
end | |
desc "Restart unicorn using 'upgrade'" | |
task :restart => :environment do | |
invoke 'unicorn:stop' | |
invoke 'unicorn:start' | |
end | |
end | |
task :setup => :environment do | |
queue! %[mkdir -p "#{deploy_to}/shared/log"] | |
queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/log"] | |
queue! %[mkdir -p "#{deploy_to}/shared/config"] | |
queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/config"] | |
queue! %[touch "#{deploy_to}/shared/config/database.yml"] | |
queue %[echo "-----> Be sure to edit 'shared/config/database.yml'."] | |
# sidekiq needs a place to store its pid file and log file | |
queue! %[mkdir -p "#{deploy_to}/shared/pids"] | |
queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/pids"] | |
end | |
desc "Deploys the current version to the server." | |
task :deploy => :environment do | |
deploy do | |
invoke :'sidekiq:quiet' | |
invoke :'git:clone' | |
invoke :'deploy:link_shared_paths' | |
invoke :'bundle:install' | |
invoke :'rails:db_migrate' | |
invoke :'rails:assets_precompile' | |
to :launch do | |
invoke :'unicorn:restart' | |
invoke :'sidekiq:restart' | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment