When I heard that Capistrano 2 was being released without support for deploying subversion tags, I was a little miffed. I thought it was a major oversight with Capistrano 1, and I was hoping they would rectify it.
After a little hacking, though, I realized there was really no reason to be angry at Capistrano for this oversight. All I needed to do was write a tiny bit of code in the deployment recipe and I was good to go.
set :repository, “https://your/repo/here/tags”
set :latest_tag, “latest”
namespace :deploy do
desc “Asks the user for the tag to deploy”
task :before_update_code do
set :tag, Proc.new { CLI.ui.ask “Tag to deploy (relative to #{repository}) or just hit enter to deploy latest: “}
set :tag, “#{latest_tag}” if “#{tag}”.strip.empty?
set :repository, “#{repository}/#{tag}”
end
end
The main drawback to this approach is that the directory created on the production server is named with the timestamp of the deployment, rather than the tag name, which would be ideal. However, with the small amount of searching I did, I was unable to find a way to change this naming scheme. I have a hunch it might break the rollback functionality and is probably not worth the trouble.
Note 1: Part of my tagging for release process is to create a ‘latest’ tag in the tags directory that points to the latest tag (duh!) So, the code above asks which tag to deploy, but will deploy ‘latest’ by default if there is no input from the user. This is not strictly necessary for the tagging, but makes the deployment slightly easier (ie. just hit enter when prompted for a tag).
Note 2: This scheme should work with both cap 1 and cap 2, but I only tested it on cap 2.
Recent Comments