Created
October 14, 2010 00:05
-
-
Save hooptie45/625243 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace :deploy do | |
# this can probably be done better once bundler is updated or you can lock before deploying | |
# but I really like the way bundler 0.8.1 just updated the gems on the fly from the cache | |
# I also really don't like deploying all my gems in the system directory, since you can run into | |
# really messy version conflicts. Keep the gems with the app that needs them, and your system gems clean | |
desc "expand the gems" | |
task :gems, :roles => :web, :except => { :no_release => true } do | |
run "cd #{current_path}; #{shared_path}/bin/bundle unlock" | |
run "cd #{current_path}; #{shared_path}/bin/bundle install vendor/" | |
run "cd #{current_path}; #{shared_path}/bin/bundle lock" | |
end | |
desc 'Bundle and minify the JS and CSS files' | |
task :precache_assets, :roles => :app do | |
root_path = File.expand_path(File.dirname(__FILE__) + '/../..') | |
assets_path = "#{root_path}/public/assets" | |
run_locally "#{root_path}/vendor/bin/jammit" | |
top.upload assets_path, "#{current_path}/public", :via => :scp, :recursive => true | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
load 'config/deploy/settings.rb' | |
load 'config/deploy/symlinks.rb' | |
load 'config/deploy/passenger.rb' | |
load 'config/deploy/callbacks.rb' | |
load 'config/deploy/maintenance.rb' | |
load 'config/deploy/git.rb' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace :deploy do | |
desc "Deploy app" | |
task :default do | |
update | |
restart | |
cleanup | |
end | |
# note: the shared children is where we setup for the new bundler | |
# to share the deploy of the gems between deploys. this is kind of bad | |
# since we're re-installing all of them each deploy. Hope to fix this | |
# when bundler gets updated to just install new via the cache like 0.8.1 | |
desc "Setup a GitHub-style deployment." | |
task :setup, :except => { :no_release => true } do | |
run "[ -d #{current_path} ] || git clone #{repository} #{current_path}" | |
set (:shared_path) { File.join(deploy_to, shared_dir) } | |
set :shared_children, %w(public/system log config gems specifications doc bin) | |
dirs = [shared_path] | |
dirs += shared_children.map { |d| File.join(shared_path, d) } | |
run "#{try_sudo} mkdir -p #{dirs.join(' ')} && #{try_sudo} chmod g+w #{dirs.join(' ')}" | |
end | |
desc "Update the deployed code." | |
task :update_code, :except => { :no_release => true } do | |
run "cd #{current_path}; git fetch origin; git reset --hard origin/#{branch}" | |
end | |
desc "Deploy and run migrations" | |
task :migrations, :except => { :no_release => true } do | |
update | |
restart | |
cleanup | |
end | |
desc "write the current version to REVISION" | |
task :write_revision, :except => { :no_release => true } do | |
run "cd #{current_path}; git rev-parse HEAD > #{current_path}/REVISION" | |
end | |
namespace :rollback do | |
desc "Rollback" | |
task :default do | |
code | |
end | |
desc "Rollback a single commit." | |
task :code, :except => { :no_release => true } do | |
set :branch, "HEAD^" | |
default | |
end | |
end | |
# cleanup is a non-op with github deploy strat | |
desc "Cleanup releases" | |
task :cleanup do | |
end | |
desc "Make sure there is something to deploy" | |
task :check_revision, :roles => [:web] do | |
unless `git rev-parse HEAD` == `git rev-parse origin/#{branch}` | |
puts "" | |
puts " [1;33m**************************************************[0m" | |
puts " [1;33m* WARNING: HEAD is not the same as origin/#{branch} *[0m" | |
puts " [1;33m**************************************************[0m" | |
puts "" | |
exit | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
############################################################# | |
# Other Tasks | |
############################################################# | |
# don't really use this, so it may not work 100% but included | |
# for completeness | |
namespace :deploy do | |
namespace :web do | |
desc "Serve up a custom maintenance page." | |
task :disable, :roles => :web do | |
require 'erb' | |
on_rollback { run "rm #{shared_path}/system/maintenance.html" } | |
reason = ENV['REASON'] | |
deadline = ENV['UNTIL'] | |
template = File.read("app/views/layouts/maintenance.html.erb") | |
page = ERB.new(template).result(binding) | |
put page, "#{shared_path}/system/maintenance.html", :mode => 0644 | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace :deploy do | |
# override default tasks to make capistrano happy | |
desc "Start Passenger" | |
task :start do | |
run "touch #{current_path}/tmp/restart.txt" | |
end | |
desc "Restart Passenger" | |
task :restart do | |
stop | |
start | |
end | |
desc "Stop Passenger" | |
task :stop do | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
############################################################# | |
# Application | |
############################################################# | |
set :application, 'appname' | |
set :deploy_to, "/home/username/website/" | |
#use trunk to deploy to production | |
set :branch, "master" | |
set :rails_env, "production" | |
#production | |
set :domain, 'domainname' | |
role :app, domain | |
role :web, domain | |
role :db, domain, :primary => true | |
############################################################# | |
# Git | |
############################################################# | |
set :scm, :git | |
set :repository, "repository-location" | |
############################################################# | |
# Servers | |
############################################################# | |
set :user, 'dreamhost-username' | |
############################################################# | |
# Includes | |
############################################################# | |
############################################################# | |
# Settings | |
############################################################# | |
default_run_options[:pty] = true | |
set :use_sudo, false | |
#before "deploy", "deploy:check_revision" | |
set :ssh_options, {:forward_agent => true} | |
############################################################# | |
# Post Deploy Hooks | |
############################################################# | |
after "deploy:update_code", "deploy:write_revision" | |
before "deploy:gems", "deploy:symlink" | |
after "deploy:update_code", "deploy:gems" | |
#after "deploy:update_code", "deploy:precache_assets" #not working for rails3 yet | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# symlinks are setup for bundler deploy, and are based on 0.8.1 version | |
# of being able to bundle from the cache. right now it's re-deploying | |
# everything. I'd like to get this fixed at some point | |
namespace :deploy do | |
desc "Make all the symlinks" | |
task :symlink, :roles => :app, :except => { :no_release => true } do | |
set :normal_symlinks, %w(public/system config/database.yml log) | |
commands = normal_symlinks.map do |path| | |
"rm -rf #{current_path}/#{path} && ln -s #{shared_path}/#{path} #{current_path}/#{path}" | |
end | |
set :weird_symlinks, { | |
"#{shared_path}/bin" => "vendor/bin", | |
"#{shared_path}/specifications" => "vendor/specifications", | |
"#{shared_path}/gems" => "vendor/gems", | |
"#{shared_path}/doc" => "vendor/doc" | |
} | |
commands += weird_symlinks.map do |from, to| | |
"rm -rf #{current_path}/#{to} && ln -s #{from} #{current_path}/#{to}" | |
end | |
# needed for some of the symlinks | |
run "mkdir -p #{current_path}/tmp && mkdir -p #{current_path}/config" | |
run "cd #{current_path} && #{commands.join(' && ')}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment