Skip to content

Instantly share code, notes, and snippets.

@gjohnson
Created October 19, 2013 16:46
Show Gist options
  • Save gjohnson/7058315 to your computer and use it in GitHub Desktop.
Save gjohnson/7058315 to your computer and use it in GitHub Desktop.
deploy.rb
#
# Multistage.
#
set :stages, %w(production staging)
set :default_stage, "production"
require 'capistrano/ext/multistage'
#
# Remote.
#
set :account, "my-account"
set :application, "online-service"
set :default_run_options, :pty => true
set :user, "tag"
set :deploy_to, "/home/tag/apps/#{application}"
set :deploy_via, :remote_cache
set :keep_releases, 6
set :shared_children, %w(node_modules log)
#
# SCM.
#
set :scm, :git
set :branch, "master"
set :repository, "[email protected]:#{account}/#{application}.git"
#
# Custom deployment tasks (since we don't use RoR).
#
namespace :deploy do
desc "Creates remote directory structure(s)."
task :setup, :expect => { :no_release => true } do
dirs = [deploy_to, releases_path, shared_path]
dirs += shared_children.map { |d| File.join(shared_path, d) }
run "mkdir -p #{dirs.join(' ')}"
run "chmod g+w #{dirs.join(' ')}" if fetch(:group_writable, true)
end
desc "Links shared internal resources and dependencies."
task :finalize_update, :except => { :no_release => true } do
run "chmod -R g+w #{latest_release}" if fetch(:group_writable, true)
run "cd #{latest_release} && NODE_ENV=production npm install"
cleanup
end
desc "Deploys and starts new application."
task :cold do
logger.important "cold start: update" if logger
update
logger.important "cold start: start" if logger
start
end
desc "Starts the application service."
task :start do
run "mongroup start #{application}"
end
desc "Restarts the application service."
task :restart do
run "mongroup restart #{application}"
end
desc "Stops the application service."
task :stop do
run "mongroup stop #{application}"
end
end
#
# Notifications
#
namespace :notify do
desc "Notifies rollbar of a deployment"
task :rollbar, :roles => :app do
set :revision, `git log -n 1 --pretty=format:"%H"`
set :local_user, `whoami`
set :rollbar_token, 'xxxxxxxx'
set :node_env, ENV['NODE_ENV']
run "curl https://api.rollbar.com/api/1/deploy/ -F access_token=#{rollbar_token} -F environment=#{node_env} -F revision=#{revision} -F local_username=#{local_user} >/dev/null 2>&1", :once => true
end
end
#
# Hooks
#
after :deploy, 'notify:rollbar'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment