Skip to navigation

Capistrano for (gasp) non-rails apps

Published March 25, 2007

The Bells of San Juan Capistrano by DBCondit

Jon Maddox has previously published on how to do automated PHP deployment with capistrano, but I thought an all-ruby solution that handles all the rollbacky goodness of standard Cap was in order.

The trick is to create your standard config/deploy.rb lookin deployment recipe (like this one), and in it you have to redefine the deploy and update_code tasks to read:


# Override deploy to prevent restarting
task :deploy do
  update # task from standard cap recipe
end

# Override update_code to remove Rails directories
task :update_code, :except => { :no_release => true } do
  on_rollback { delete release_path, :recursive => true }
  source.checkout(self)
  set_permissions
  @releases = nil
end

There’s nothing else that’s special; just add your normal set statements up the top, sprinkling after_ and before_ task callbacks as required. Now go ahead and deploy the sucker:

cap setup && cap deploy

If you’re wondering where you’d start looking to discover this sort of thing, all of Capistrano’s magic exists in its standard recipe in the capistrano gem’s lib directory. If you’re using Capistrano 1.4.0 and macports that path would be:

/opt/local/lib/ruby/gems/1.8/gems/capistrano-1.4.0/lib/capistrano/recipes/standard.rb

Archived comments

Comments were previously allowed on articles. Though no new comments are being accepted you can see the old comments below.

  1. Ryan Allen

    Cap is teh awesome! Another Aussie wrote the Deprec gem which is used to set up baremetal ubuntu boxes w/ Ruby/Rails/Etc.

    http://deprec.rubyforge.org/

    !

  2. Tim Lucas

    Yep, not to mention it’s an awesome piece of code to steal and plunder from if you want to learn more about capistrano.

More reading…

Previously: Announcing RailsCamp07

Next up: bangbang your nil is dead

Articles

toolmantim

I'm Tim Lucas, a user experience designer and developer currently in Sydney Australia.

I run a web application design and development company Agency Rainford, present on various technical topics, snap the occasional photo, tweet my going-ons, share teh codes and post other tid-bits to the tumble.

Most recently I published LAN hacking with Bananajour (June 11, 2009)

Shoot an email to and say hello.

Powered by your inner voice