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/deploy.sh".
#!/bin/sh # # Cloud Hook: deploy # # Runs common deployment tasks. site="$1" target_env="$2" # 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/purge-varnish.sh": Note: "*" being every environment folder you wish to clear the varnish cache.
#!/bin/sh # # Cloud Hook: purge-varnish # # Clears varnish cache. site="$1" target_env="$2" 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 example.com
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.