Extending Capistrano

Using Capistrano walked you through the built-in tasks, and those cover a large amount of day-to-day tasks for a Rails developer publishing a site. However, they are all the most generic tasks. In almost every application, you will have some specific needs that are not met by the defaults. Not to worry: as with just about every utility ever written for the Ruby on Rails environment, Capistrano can be extended.

You can modify and override existing recipes, or you can write your own. You have access to all the nice plumbing from Capistrano, such as a simple API for moving files around. You have access to all the source code of Capistrano itself, too! Want to make a custom version of symlink? Go look at how Jamis wrote his. Need a task to copy over static files just like the disable_web task? Get your mouse ready to cut and paste!

Simple Tasks

In fact, that custom symlink is exactly what we need for our address book. Our pictures folder should really be a shared element common to all of the instances of our application. Upgrading a feature or fixing a bug should not mean that we have to upload all of the icons again. One possibility is certainly making a fresh copy of all the icons with each build that gets published, but that will grow unwieldy in short order―to say nothing of extending this idea to media systems where a shared folder could be hundreds of gigabytes in size!

We’ll follow our own advice and pull up a copy of the symlink task from standard.rb in ...

Get Capistrano and the Rails Application Lifecycle now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.