Skip to content

Instantly share code, notes, and snippets.

@kylewelsby
Forked from anonymous/staging.rb
Created January 3, 2013 09:44
Show Gist options
  • Save kylewelsby/4442255 to your computer and use it in GitHub Desktop.
Save kylewelsby/4442255 to your computer and use it in GitHub Desktop.
require 'capistrano/ext/multistage'
require "rvm/capistrano"
require "bundler/capistrano"
require "delayed/recipes"
require 'new_relic/recipes'
set :rvm_ruby_string, ENV['GEM_HOME'].gsub(/.*\//,"") # Read from local system
set :default_environment, {
'PATH' => "/home/rails/.rvm/gems/ruby-1.8.7-p370@appname/bin:/home/rails/.rvm/bin:/home/rails/.rvm/rubies/ruby-1.8.7-p370/bin:$PATH",
'GEM_HOME' => '/home/rails/.rvm/gems/ruby-1.8.7-p370@appname',
'GEM_PATH' => '/home/rails/.rvm/gems/ruby-1.8.7-p370@appname:/home/rails/.rvm/gems/ruby-1.8.7-p370@global',
'BUNDLE_PATH' => '/home/rails/.rvm/gems/ruby-1.8.7-p370@appname' # If you are using bundler.
}
set :application, "example.com"
set :domain, "example.com"
set :repository, "git@github.com:user/app.git"
set :rails_env, "staging"
# If you aren't deploying to /u/apps/#{application} on the target
# servers (which is the default), you can specify the actual location
# via the :deploy_to variable:
set :deploy_to, "/var/www/#{application}"
set :deploy_via, :remote_cache
set :user, "rails"
set :use_sudo, false
# If you aren't using Subversion to manage your source code, specify
# your SCM below:
set :scm, :git
# Deploy the current branch that is checked out.
set :branch, $1 if `git branch` =~ /\* (\S+)\s/m
role :app, domain
role :web, domain
role :worker, domain
role :db, domain, :primary => true
set :delayed_job_server_role, :worker
namespace :rvm do
task :trust_rvmrc do
run "rvm rvmrc trust #{release_path}"
end
end
namespace :deploy do
after "deploy", "rvm:trust_rvmrc"
after "deploy:stop", "delayed_job:stop"
after "deploy:start", "delayed_job:start"
after "deploy:restart", "delayed_job:restart"
# Passenger
task :start do ; end
task :stop do ; end
task :restart, :roles => :app, :except => { :no_release => true } do
run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
end
# after 'deploy:update_code', 'deploy:symlink_all'
after "deploy:update", "newrelic:notice_deployment"
after "bundle:install", "deploy:symlink_all"
desc "Symlinks the database.yml"
task :symlink_all, :roles => :app do
puts "* Symlinking database.yml"
run "ln -nfs #{deploy_to}/shared/config/database.yml #{release_path}/config/database.yml"
run "ln -nfs #{deploy_to}/shared/config/connectware.yml #{release_path}/config/connectware.yml"
end
namespace :assets do
task :precompile, :roles => :web, :except => { :no_release => true } do
from = source.next_revision(current_revision)
if capture("cd #{latest_release} && #{source.local.log(from)} vendor/assets/ app/assets/ | wc -l").to_i > 0
run %Q{cd #{latest_release} && #{rake} RAILS_ENV=#{rails_env} #{asset_env} assets:precompile}
else
logger.info "Skipping asset pre-compilation because there were no asset changes"
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment