Automate Acquia deployments with cloud hooks

When it comes to deploying I feel there is nothing worse than having to manually repeat steps. It's inconsistent and wastes time, but we all know this. With Acquia cloud hooks we can automate our deployments and save us valuable time.

The manual steps.

So when deploying a Drupal site there are some pretty standard commands we run, such as:

  • Database update.
  • Features revert.
  • Cache clear.
  • Clear Acquia varnish cache so clients get the new changes right away (given we are deploying in an offpeak period).

These are all very standard commands, but how many times have you heard after a deploy "Oh! you need to revert that X feature.". Let's automate this so we never have to care about it again.

Let's automate it - Basic cloud hook deploy script.

For some initial reading on how to setup Acquia cloud hooks please refer to the Cloud hook project page. Next (to separate this post from other Cloud hooks posts) I will provide you with a script you can use on all your projects! First we want to setup a standard script that will run for all environments. This can be done by adding the following script "hooks/common/post-code-deploy/".

# Cloud Hook: deploy
# Runs common deployment tasks.


# Maintenance on.
drush @$site.$target_env vset site_offline 1 -y
drush @$site.$target_env vset maintenance_mode 1 -y

# Registry rebuild.
drush @$site.$target_env dl registry_rebuild --yes
drush @$site.$target_env rr

# Update database.
drush @$site.$target_env updatedb --yes

# Features revert.
drush @$site.$target_env fra --yes

# Maintenance off.
drush @$site.$target_env vset site_offline 0 -y
drush @$site.$target_env vset maintenance_mode 0 -y

With this script we have facilitated the "Database update", "Features revert" and "Cache clear" portions of our manual steps. How it's down to clearing the varnish cache. For this we need to add a script for each environment we want to clear the varnish cache for. This script with be found in the directories "hooks/*/post-code-deploy/": Note: "*" being every environment folder you wish to clear the varnish cache.

# Cloud Hook: purge-varnish
# Clears varnish cache.

username="" # Obtained from Acquia workflow drush page.
password="" # Obtained from Acquia workflow drush page.

drush @$site.$target_env ac-domain-purge --username=$username --password=$password

Let's take a quick look at this script and it's requirements.

  • It's requires Acquia webhooks to be enabled on the project.
  • More drush lines can be added to clear other domain's on this project.


Acquia webhooks can be very powerful, please leave your Acquia cloud hook stories in the comments.


Posted by Phil | November 29, 2013

Perfect timing, this is just what I was looking for to streamline deployments to acquia. Thanks!

Posted by Anders Tolborg | February 7, 2014

First of all, thank you very much. Your article has been a great resource!

Since I like to have my purge varnish script in a single file (in "hooks/common/post-code-deploy"), I have written it like this:

Posted by emmonsaz | May 27, 2015

Great info, thanks!

Post a comment

5 + 2 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.