Fast git-based deploy process inspired by https://github.com/blog/470-deployment-script-spring-cleaning.
Add this line to your application's Gemfile:
gem 'capistrano-deploy', :group => :development, :require => falseCreate a file named Capfile in your project root directory:
require 'capistrano-deploy'
use_recipes :git, :bundle, :rails
server 'server name or ip address', :web, :app, :db, :primary => true
set :user, 'user for deploy'
set :deploy_to, '/deploy/to/path'
set :repository, 'your git repository'
after 'deploy:update', 'bundle:install'And then execute:
bundle
To setup:
cap deploy:setup
Then when you push some changes to git repository simply run:
cap deploy
Or if you have migrations:
cap deploy:migrations
To look through the changes to be deployed:
cap deploy:pending
If you want to update to a specific commit (e.g. to rollback):
cap deploy COMMIT=foobarbaz
Note: it may be required to run bundle exec cap ... instead of cap ....
Basic usage:
use_recipe :multistage
set :default_stage, :development
stage :development do
...
end
stage :production do
...
endYou can also pass options that allow setting variables and default stage:
stage :development, :branch => :develop, :default => true
stage :production, :branch => :masterWhen branches are specified for stages and git recipe is used it will automatically select stage based on current local branch.
Use recipe:
use_recipe :bundleAnd add callback to run bundle install on each deploy:
after 'deploy:update', 'bundle:install'Use recipe:
use_recipe :rails_assetsAdd callback to precompile assets after update:
after 'deploy:update', 'deploy:assets:precompile'Use recipe:
use_recipe :passengerIt will automatically do touch tmp/restart.txt on each deploy.
Use recipe:
use_recipe :unicornYou can setup callback to reload unicorn after deploy is done:
after 'deploy:restart', 'unicorn:reload'Use recipe:
use_recipe :wheneverTo automatically update crontab file:
after 'deploy:restart', 'whenever:update_crontab'You can also clear crontab file with command:
cap whenever:clear_crontab

