Skip to content

Instantly share code, notes, and snippets.

@shayarnett
Created September 3, 2009 15:47
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save shayarnett/180365 to your computer and use it in GitHub Desktop.
Save shayarnett/180365 to your computer and use it in GitHub Desktop.
set :application, "example.com"
set :deploy_to, "/var/www/#{application}"
role :app, "example.com"
role :web, "example.com"
role :db, "example.com", :primary => true
set :scm, :git
set :repository, "ssh://shay@example.com/git/example.com"
set :branch, "origin/master"
namespace :deploy do
desc "Deploy app"
task :default do
update
restart
cleanup
end
desc "Setup a GitHub-style deployment."
task :setup, :except => { :no_release => true } do
run "git clone #{repository} #{current_path}"
end
desc "Update the deployed code."
task :update_code, :except => { :no_release => true } do
run "cd #{current_path}; git fetch origin; git reset --hard #{branch}"
end
desc "Deploy and run migrations"
task :migrations, :except => { :no_release => true } do
update
migrate
restart
cleanup
end
desc "Run pending migrations on already deployed code"
task :migrate, :except => { :no_release => true } do
run "cd #{current_path}; rake RAILS_ENV=production db:migrate"
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
desc "Make all the symlinks"
task :symlink, :roles => :app, :except => { :no_release => true } do
set :normal_symlinks, %w(
public/system
config/database.yml
)
commands = normal_symlinks.map do |path|
"rm -rf #{current_path}/#{path} && \
ln -s #{shared_path}/#{path} #{current_path}/#{path}"
end
# set :weird_symlinks, {
# "path_on_disk" => "path_to_symlink"
# }
# commands += weird_symlinks.map do |from, to|
# "rm -rf #{current_path}/#{to} && \
# ln -s #{shared_path}/#{from} #{current_path}/#{to}"
# end
# needed for some of the symlinks
run "mkdir -p #{current_path}/tmp && \
mkdir -p #{current_path}/public/system && \
mkdir -p #{current_path}/config"
run <<-CMD
cd #{current_path} &&
#{commands.join(" && ")}
CMD
end
# override default tasks to make capistrano happy
desc "Kick Passenger"
task :start do
run "touch #{current_path}/tmp/restart.txt"
end
desc "Kick Passenger"
task :restart do
stop
start
end
desc "Kick Passenger"
task :stop do
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment