For most of Innova’s applications, we’ve got two environments: staging and production. So it was an easy thing to just hit the proper server and do an SVN operation to push out new code.
With our new project, IMEBase we have a little more complexity in mind: we’ve got multiple testing and multiple production environments. Doing all of our SVN stuff manually would be error-prone and boring as hell.
Enter Capistrano.
Capistrano is usually associated with Rails projects, and it’s certainly five levels more of awesome when used with Rails. But Cap’s just a framework for running commands on a bunch of servers, which makes it ideal for our use.
In keeping with UNIX build utility tradition (make, I’m looking at you), Capistrano gets its marching orders from a capfile. Below is a stupidly-simple example that’s actually exactly what we use:
# Here we're setting some paths that we'll use later
set :dir_puppets, "/path/to/this/environment/"
set :dir_testing, "/path/to/the/demo/environment/"
set :dir_foo, "/oh/look/another/path/"
set :dir_epic, "/yeah/paths/are/cool/"
set :dir_fail, "/okay/the/point/is/made/"
set :dir_somelibrary, "/heres/a/global/library/path/"
# the SVN repository root (for our tags)
set :repository, "svn://your/svn/root/url/"
# the various server roles
role :production, "dethklok.innova-partners.com"
role :staging, "spinaltap.innova-partners.com"
# just prompts for the tag name
task :get_tag do
set :tag do
Capistrano::CLI.ui.ask "Enter tag name: "
end
end
namespace :testing do
before "testing:deploy", :get_tag
desc "Push an SVN tag out to the testing sites"
task :deploy, :roles => :staging do
run "cd #{dir_testing}; svn switch #{repository}#{tag}"
end
desc "Push global libraries out to testing sites"
task :libs, :roles => :staging do
run "cd #{dir_foo}; svn up"
end
end
If you’ve never touched Ruby before, this should still make some basic sense. We’re setting some variables at the top, and then some roles. Roles are special variables that tell Cap what servers to operate on. We’ve also defined a task (get_tag) that has Capistrano prompt for a bit of info and stores it in a variable (tag).
The magic happens in the namespace definition. We’ve set up a “testing” namespace with two tasks inside of it: “deploy” and “libs”, both of which just find the right directory and run an SVN command. We’ve also set up a “before” callback that ensures that we have a valid tag name before we run our deploy task. In order to run these, we type cap testing:libs or cap testing:deploy at the shell, and Cap does the rest (connects to servers, prompts for tag and password, etc.). Cap happily reports back any output, and what the results were!
And that’s the basics! Shoot over to the Capistrano site for some more complicated examples, including the full documentation.
In order to use this, you’ll need Ruby (use whatever install method is appropriate for your platform), RubyGems (should come with Ruby), Capistrano, which can be had for the meager sum of gem install capistrano, and a healthy desire to do less work.

Leave your mark