Skip to content

Instantly share code, notes, and snippets.

@localhots
Last active December 18, 2015 15:19
Show Gist options
  • Save localhots/5803396 to your computer and use it in GitHub Desktop.
Save localhots/5803396 to your computer and use it in GitHub Desktop.
Keep your deploy.rb clean! Move all customs tasks to config/deploy/recipes/. Define triggers only in deploy.rb file.
require 'bundler/capistrano'
logger.level = Logger::DEBUG # Logger::IMPORTANT
default_run_options[:pty] = true
ssh_options[:forward_agent] = true
server 'example.com', :web, :app, :db, :sidekiq, primary: true
set :application, 'example'
set :user, 'www'
set :deploy_via, :remote_cache
set :use_sudo, false
# Multistage configuration
set :stages, %w[ production staging ]
set :default_stage, 'production'
require 'capistrano/ext/multistage'
set :deploy_to, "/home/#{user}/example/"
set :scm, 'git'
set :repository, 'git@github.com:example/example.git'
# Sidekiq configuration
require 'sidekiq/capistrano'
set :sidekiq_role, :sidekiq
set :sidekiq_pid, "#{current_path}/tmp/pids/sidekiq.pid"
set :sidekiq_processes, 4
%w[ deploy_setup_webservers deploy_setup_config deploy_symlink_config ].each do |recipe|
load File.expand_path("../deploy/recipes/#{recipe}.rb", __FILE__)
end
# Setup unicorn init script and nginx
after 'deploy:setup', 'deploy:setup_webservers'
# Bootstrap *.example.yml files
after 'deploy:setup', 'deploy:setup_config'
# Symlink config files from shared to current
after 'deploy:finalize_update', 'deploy:symlink_config'
# Restart Unicorn
require 'capistrano-unicorn'
after 'deploy:restart', 'unicorn:restart'
# Notify NewRelic
require 'new_relic/recipes'
after 'deploy:restart', 'newrelic:notice_deployment'
# Notify Hipchat
require 'hipchat/capistrano'
set :hipchat_token, 'secret'
set :hipchat_room_name, 'secret'
# Keep only the last 5 releases
after 'deploy', 'deploy:cleanup'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment