Automating with Cloud Hooks

The Cloud > Workflow page automates the most common tasks involved in developing a Drupal website: deploying code from a version control system, and migrating code, databases, and files across your development, staging, and production environments. Cloud Hooks allow you to automate other tasks as part of these migrations.

A Cloud Hook is simply a script in your code repository that Acquia Cloud executes on your behalf when a triggering action occurs. Examples of tasks that you can automate with Cloud Hooks include:

  • Performing Drupal database updates each time you develop new code.
  • Scrubbing your production database each time you copy it to Dev or Staging by removing customer emails or disabling production-only modules.
  • Running your test suite or a website performance test each time you deploy new code.

Installing Cloud Hooks

Your Cloud Hooks live in your Acquia Cloud code repository. In each branch of your repo, there is a directory named docroot that contains your website's source code. Cloud Hooks live in the directory hooks next to docroot (not inside of docroot).

The Cloud Hooks directory structure, sample and community-contributed hook scripts, and documentation live in https://github.com/acquia/cloud-hooks. To start using Cloud Hooks with your website, copy the current version of the Cloud Hooks repository at GitHub into your Acquia Cloud repository.

If your Acquia Cloud website is using Git, you can copy the Cloud Hooks repository with these commands:

cd /my/repo
curl -L -o hooks.tar.gz https://github.com/acquia/cloud-hooks/tarball/master
tar xzf hooks.tar.gz
mv acquia-cloud-hooks-* hooks
git add hooks
git commit -m 'Import Cloud hooks directory and sample scripts.'
git push

If your Acquia Cloud website is using SVN, you can copy the Cloud Hooks repository with these commands:

cd /my/repo
curl -L -o hooks.tar.gz https://github.com/acquia/cloud-hooks/tarball/master
tar xzf hooks.tar.gz
mv acquia-cloud-hooks-* hooks
svn add hooks
svn commit -m 'Import Cloud hooks directory and sample scripts.'

Quick start

To see the power of Cloud Hooks in action, you can run the "Hello, Cloud!" script when new code is deployed in your Dev environment. Be sure to install Cloud Hooks first as previously explained.

  1. Install the hello-world.sh script to run on code deployments to Dev. This example assumes your Dev environment is running the master branch.

    cd /my/repo
    git checkout master
    cp hooks/samples/hello-world.sh hooks/dev/post-code-deploy
    git commit -a 'Run the hello-world script on post-code-deploy to Dev.'
    git push
  2. Visit the Cloud > Workflow page. In the Dev environment, select the master branch (if your Dev environment is already running master, select any other tag, and then select master again), and then click Deploy.
  3. Scroll down the Workflow page, and then view the task log. After the code deployment task is done, click its Details link to see the hook's output. It will look like this:

    Started
    Updating s1.dev to deploy master
    Deploying master on s1.dev
    [05:28:33] Starting hook: post-code-deploy
    Executing: /var/www/html/s1.dev/hooks/dev/post-code-deploy/hello-world.sh
    s1 dev master master s1@svn-3.devcloud.hosting.acquia.com:s1.git git (as s1@srv-4)
    Hello, Cloud!
    [05:28:34] Finished hook: post-code-deploy

You can use the code selection button on the Cloud > Workflow page to restore your Dev environment back to whatever branch it previously had deployed.

Cloud Hooks and Remote Administration

If you have an Acquia Cloud Enterprise website with a Remote Administration (RA) environment, Cloud Hooks in the RA environment may result in unexpected behaviors or task failures, which can cause the RA automated update process to fail. For more information, see Remote Administration environment: Deploy hooks.

Going further with Cloud Hooks

Complete documentation for Cloud Hooks and the latest sample and community-contributed hook scripts are always available at https://github.com/acquia/cloud-hooks. By browsing the GitHub repo, you can do the following:

  • Find and use the latest sample and community-contributed hook scripts.
  • Read the complete documentation on how to write your own custom hook scripts.
  • Contribute your own hook scripts so others can use them.

Check out these blog posts to see how some Acquia Cloud users have taken advantage of the power of Cloud Hooks:

See you over at https://github.com/acquia/cloud-hooks!

Add new comment

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.
By submitting this form, you accept the Mollom privacy policy.

Contact supportStill need assistance? Contact Acquia Support