Skip to content
xforty edited this page May 8, 2012 · 1 revision

The Capfile is where custom configuration and tasks for a particular project go.

The Capfile must be in the local directory or a parent directory when running drush-deploy and at the top it must have require 'drush_deploy'.

This is just a sample for those unfamiliar with Capistrano. For (much) more information please read the Capistrano documentation.

Syntax

The Capfile is a normal Ruby script with some additional commands provided by Capistrano. Because it is a standard Ruby script all settings and configuration can be done proceduraly with branches, loops and functions.

A couple of common syntax items for people unfamiliar with Ruby and/or Capistrano.

  • set :<variable>, <value> -- Sets the Capistrano variable <variable> to <value>

  • <variable> = <value> -- Sets a local variable, won't influence Capistrano or drush-deploy.

  • "#{<expression>}" -- String interpolation. ` can be any valid Ruby expression.

  • ENV['<environment variable>'] -- Get value of environment variable.

  • if statements -- No parenthesis are needed for the condition. No braces are used for body. Ends with end statement. For example

    if ENV['SVN']
      set :scm, :subversion
      set :repository, ENV['SVN']
    end
    
  • run "<command>" -- Execute command on servers, must be in a task. See below.

  • before "<task1>", "<task2>" -- If <task2> is going to be run then run <task1> immediately before it.

  • after "<task1>", "<task2>" -- Reverse of before

  • exists?(:<variable>) -- Check if Capistrano variable <variable> has been set

Tasks

You can define additional tasks to use with the task command. A task operates like a subroutine that takes no arguments. You can call other tasks within a task if they are in the same scope. Here is an example task:

namespace :drupal do
    desc "Get drush status of all servers"
    task :status do
        run "drush status"
    end
end

This will generate a task call "drupal:status" and will show up when you run drush-deploy -T. You do not need to place a task in a namespace if you want it to be a single word (no colons) and the desc is only used for tasks you want to show up with drush-deploy -T.

Clone this wiki locally