Down & Brown
since 1998

Telling Capistrano to Deploy from a Branch on EngineYard

I definitely got exited by Simon's simple tweak to his deploy.rb to ensure that he wasn't accidentally deploying to production. So it was with confidence that I started hacking at my deploy.rb to set up deployment from my repository branch. This simple tip helped, but with a little help from Mike, we took it further.

Since we're deploying to EngineYard, we've got the added bonus of using a filtered_remote_cache, so we need to make sure our repository cache is updated with the new branch path.

if variables.include?(:branch)
set :svn_path, "branches/#{branch}"
set :svn_path, 'trunk'
set :repository, "{svn_path}/"
set :repository_cache, "/var/cache/engineyard/#{application}/#{svn_path}"

Then in the :deploy namespace add this chunk of goodness (tip 'o the hat to Simon)

task :confirm do
unless Capistrano::CLI.ui.agree("Sure you want to deploy from #{repository}? (yes/no): ")
puts "No worries, use --set-before branch=whatever to deploy from a specific branch if it exists."
before "deploy:update_code", "deploy:confirm"

This should give you the branch control you need when you're deploying code and migrations, but it won't interfere noisily with your other capistrano tasks.

Ideally, what we should be aiming for is the deploy.rb to be "repository / branch aware", so that if you're in a branch (or tag), then it deploys from there.