Skip to content

Instantly share code, notes, and snippets.

@joshk
Created January 18, 2011 11:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshk/784304 to your computer and use it in GitHub Desktop.
Save joshk/784304 to your computer and use it in GitHub Desktop.
deploy.rb
# - TS related capistrano tasks
require "vendor/plugins/thinking-sphinx/lib/thinking_sphinx/deploy/capistrano"
require 'new_relic/recipes'
set :stages, %w(staging production)
set :default_stage, "staging"
require 'capistrano/ext/multistage'
# Global deployment information
set :application, "mysite
set :user, 'deploy'
set :use_sudo, false
set :repository, "git@github.com:me/mysite.git"
set :scm, :git
set :deploy_via, :remote_cache
set :deploy_to, "/var/www/#{application}"
set :ree_path, "/opt/ruby-enterprise-1.8.6-20090610/bin"
set :rake, "bundle exec rake"
set :default_environment, { :PATH => "#{ree_path}:$PATH" }
after 'deploy:update_code', 'db:symlink'
after 'deploy:update_code', 'gems:bundle'
after 'deploy:symlink', 'deploy:update_crontab'
after 'deploy:symlink', 'deploy:precache_assets'
after 'deploy:restart', 'delayed_job:restart'
after 'deploy', 'deploy:cleanup'
desc "Shortcut for TS reindex"
task :with_reindex do
thinking_sphinx.index
end
namespace :deploy do
desc "Restart Application override (passenger)"
task :restart, :roles => :app, :except => { :no_release => true } do
run "touch #{current_path}/tmp/restart.txt"
end
[:start, :stop].each do |t|
desc "#{t} task is a no-op with mod_rails"
task t, :roles => :app do ; end
end
desc "Update the crontab file"
task :update_crontab, :roles => :db do
run "cd #{current_path} && bundle exec whenever --update-crontab #{application} -s environment=#{rails_env}"
end
desc 'Bundle and minify the JS and CSS files'
task :precache_assets, :roles => :app do
run "cd #{current_path} && bundle exec jammit"
end
namespace :web do
# http://shiftcommathree.com/articles/make-your-rails-maintenance-page-respond-with-a-503
task :disable, :roles => :web, :except => { :no_release => true } do
# invoke with
# UNTIL="16:00 MST" REASON="a database upgrade" cap deploy:web:disable
on_rollback { rm "#{shared_path}/system/maintenance.html" }
require 'erb'
deadline, reason = ENV['UNTIL'], ENV['REASON']
maintenance = ERB.new(File.read("./app/views/layouts/maintenance.html.erb")).result(binding)
put maintenance, "#{shared_path}/system/maintenance.html", :mode => 0644
end
end
end
namespace :gems do
desc "Bundles cached gems from bundler"
task :bundle, :roles => :app do
run "cd #{release_path} && bundle install"
end
end
namespace :db do
# http://archive.jvoorhis.com/articles/2006/07/07/managing-database-yml-with-capistrano
# http://shanesbrain.net/2007/5/30/managing-database-yml-with-capistrano-2-0
desc "Link in the production database.yml in shared"
task :symlink do
run "ln -nfs #{deploy_to}/#{shared_dir}/config/database.yml #{release_path}/config/database.yml"
end
end
desc "use for testing deployment environment"
task :uname do
run "uname -a"
end
# path checking
desc "Echo environment vars"
namespace :env do
task :echo do
run "echo printing out cap info on remote server"
run "echo $PATH"
run "printenv"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment