
I can't get enough of the bzr revision control system, and I'm quite fond of Rails too. So, I thought I'd share my deployment setup for Rails applications using Capistrano and bzr.
Capistrano works on the assumption that you're deploying from a revision control system. Secondly, it requires that your deployment server is aware of how to access this system. This leaves you with various options, the most obvious of which are:
Of these, option 1 is out for all but somewhat casual projects, option 2 either opens up your source repository more than I like, or needs fiddly tunnelling of SSH which I don't think Capistrano is up to yet (I only like to use key-based access with SSH, rather than password based access, which seems at the moment complicate life where Capistrano is concerned.)
I've opted for option 3. The pattern I use is this. On setting up the deployment server, I push a copy of the bzr repository to a private directory. Then, on deployment I first update that repository securely from the master repository inside my network, then export the new release locally on the server.
Here are the relevant bits of my Capistrano configuration:
set :repository, "/opt/repo_mirror/#{application}"
…
set :scm, :bzr
set :checkout, "branch"
…
task :before_update_code do
`bzr push sftp://deploy.example.org/opt/repo_mirror/#{application}`
end One big advantage of this over option 2, a remote source repository, is that only the changes are sent up to the server, and the bandwidth-intensive application checkout happens locally on the deployment machine.
The final bit of improvement this could stand is to have the bzr checkout use export and not branch, but I think I'll have to alter the Capistrano's bzr plugin in order to do this.