Skip to content

Drush Configuration

pearcec edited this page Jun 8, 2012 · 3 revisions

drush-deploy uses drush aliases to configure it's targets. An alias is a name assigned to pre-configured set of server settings which are used to ssh into the server and deploy the site to it. These aliases can be used as the target (or TARGET on the command line) setting in drush-deploy. Multiple aliases can be deployed to at once by using a comma (',') separated list of aliases. Note: When deploying to multiple aliases at once, all aliases must share the same root and databases settings.

This allows you to easily adapt existing drush aliases files for use with drush-deploy. It also enables drush-deploy to easily utilize drush when executing tasks. Lastly it means that any targets setup for drush-deploy can be used just as easily with standard drush commands.

Please see the drush documentation for more information about drush.

Setting up aliases

You can find an exhaustive reference at the drush aliases example.

Aliases can be placed in a couple of different places including ~/.drush, /etc/drush or the site folder of the Drupal project you're in.

Single server sites

For targets with only a single server you can use the standard aliases.drushrc.php file. Here is an example configuration:

$aliases['staging'] = array(
   'remote-host' => 'staging.mysite.com',
   'remote-user' => 'drupal',
   'root' => '/srv/drupal'
);

This will allow you to deploy using the command drush-deploy TARGET=staging and also allow drush commands like drush @staging status.

Multiple server sites

For targets with multiple sites you can use a group alias to prevent having to specify all targets on the command line each time you deploy. A group alias is created by putting your aliases in a separate file named GROUP.aliases.drushrc.php where 'GROUP' is the name of the group alias you want to create. Here is an example group alias in a file name staging.aliases.drushrc.php:

$aliases['web1'] = array(
   'remote-host' => 'staging1.mysite.com',
   'remote-user' => 'drupal',
   'root' => '/srv/drupal/current'
);

$aliases['web2'] = array(
   'remote-host' => 'staging1.mysite.com',
   'remote-user' => 'drupal',
   'root' => '/srv/drupal/current'
);

This will create three separate aliases: staging.web1, staging.web2, and staging. The first two correspond to each of the individual servers while the last one refers to both of them. Using just drush this allows you to execute drush commands on all servers in the group: drush @staging status.

This also allows you to deploy to all servers in a group by specifying the group alias as the target.

Attributes

drush-deploy respects many of the attributes that drush recognizes and will utilize them when deploying.

  • root -- This is used as the root directory of the site. Must always end in '/current' because the drush-deploy tool will also place the latest version of the site there. When deploying, drush-deploy will strip off the '/current' and use that as the destination directory on the server. All hosts deployed to in a single deploy must share the same root attribute.
  • remote-site -- The hostname or ip address of the host.
  • remote-user -- Username to use when ssh'ing into the server.
  • parent -- Allows aliases to inherit attributes from other aliases. Works as expected with drush-deploy.
  • ssh-option -- Allows you to pass in a string of options as you would to the ssh command. This is partially supported by drush-deploy. Most options specified with the -o flag are supported as is -C for compression, -i for the identify key file, and -p for specifying the port.
  • databases -- This can be used to set the database configuration for the site. Uses the drupal7 settings.php syntax. See Database-Configuration for more details. All hosts deployed to in a single deploy must share the same databases attribute (or not have one at all).
  • roles -- Either a comma separated string or an array of strings used to set what roles each host has. Each host by default has the 'web' role which means it is a web server. No other roles are used out of the box by drush-deploy but new ones can be defined in custom tasks. Not used by drush.
  • attributes -- Extra attributes related to the host. Not used out of the box by drush-deploy but can be used in custom tasks. Not used by drush.
Clone this wiki locally