Darwinweb

Simple Edge Rails Symlink with Capistrano

August 1, 2007     

I’ve been running on Edge Rails for a while now. Mike Clark has written the canonical article on the subject. John Nunemaker has some great followups. The most useful idea for me was symlinking in vendor/rails. Mike Clark’s article really polished this core idea with some capistrano magic. He makes it easy to update to any revision of Rails quite easily. My use case is slightly different though.

Patching Edge Rails

I’m not running out and picking up on every new Rails feature that comes out. Generally I think sticking to official releases is a good idea, but there was one killer feature I couldn’t live without. Beyond that, I’m not itching to update my Edge Rails, in fact I’ve only done it once in the past 3 months.

However I have needed to make a couple patches to Edge Rails. Most importantly to get multisite working. Getting patches into production means logging into the server and applying them manually (or via rsync). If I had more than one server I might look at capastranifying the whole thing, but so far it hasn’t been worth the effort to think up an elegant solution. My solution is not as slick as Mike’s, but it also took less time to set up than this article.

Capistrano Recipe

Since I manually checked out and patched my own copy of Rails (this can either be one directly on the server or via rsync), all that’s left is to symlink in the rails directory:

desc "Symlink in edge rails"
task :after_update_code, :roles => :app do
  run <<-CMD 
    ln -s /home/deploy/RAILS_EDGE #{release_path}/vendor/rails
  CMD
end

Subtle Bug

Originally I had this in an :after_symlink task, which worked well for cap deploy but failed on cap deploy_with_migrations. The issue was that migrations would run before symlinking, and thus would fail if the gem version and vendor versions of Rails were not compatible enough to run the migrations. This wouldn’t always be the case, but it is the case between Edge Rails and 1.2.3, I believe because of the new initializers present in Edge Rails.