jump to navigation

Rake tasks :through Capistrano January 27, 2008

Posted by John Dewey in Capistrano, Example, Rake.

Executing Rake tasks on host(s) through Capistrano is nothing new, and there are quite a few ways to do it. Some of the configurations out there, use a common Capistrano task to execute all Rake tasks. This works quite well, but you run into problems when scoping tasks to specific roles. The common Rake exec task is not scoped to a specific role (because it could run any task on any given role), so if you call it from a Cap task scoped to :db, it will still execute across all roles.

This was corrected by creating a Rake exec method instead of a Cap task. The method can pass any arbitrary variables and/or Rakefile to Rake.An example Capistrano task, displays it’s usage. There are a few Cap variables already set, such as rake and rails_env. Using the rakefile variable allows the execution of a specific Rakefile, which comes in handy when wanting to ignore the Rails Rakefile.

Why ignore the Rails Rakefile? In our configuration the Rakefile loads environment.rb, which sets the load_paths to our custom rubygems path – that means loading Rails! What happens when Rails is not installed, and you need a bootstrap task. The ability to pass in a Rakefile all of the sudden becomes useful.


1. Alex Leverington - December 5, 2008

rails only loads the environment if your rake task depends on the magic ‘:environment’ task. although you can’t be guaranteed that your task or a task which calls your task doesn’t depend on :environment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: