├── README.md ├── common ├── post-code-deploy │ └── .gitignore ├── post-code-update │ └── .gitignore ├── post-db-copy │ └── .gitignore ├── post-files-copy │ └── .gitignore └── pre-web-activate │ └── .gitignore ├── dev ├── post-code-deploy │ └── .gitignore ├── post-code-update │ └── .gitignore ├── post-db-copy │ └── .gitignore ├── post-files-copy │ └── .gitignore └── pre-web-activate │ └── .gitignore ├── prod ├── post-code-deploy │ └── .gitignore ├── post-code-update │ └── .gitignore ├── post-db-copy │ └── .gitignore ├── post-files-copy │ └── .gitignore └── pre-web-activate │ └── .gitignore ├── samples ├── db-scrub.sh ├── domain_fix.sh ├── drupal-tests.sh ├── drush-cache-clear.sh ├── email │ ├── README.md │ └── email.sh ├── hello-world.sh ├── hipchat │ ├── README.md │ ├── hipchat.sh │ └── hipchat_settings ├── newrelic │ ├── README.md │ ├── newrelic.sh │ └── newrelic_settings ├── post-code-deploy.tmpl ├── post-code-update.tmpl ├── post-db-copy.tmpl ├── post-files-copy.tmpl ├── pushbullet │ ├── README.md │ ├── pushbullet.sh │ └── pushbullet_settings ├── rollback │ ├── README.md │ ├── rollback.sh │ └── rollback_settings ├── slack │ ├── README.md │ ├── slack.sh │ └── slack_settings └── update-db.sh └── test ├── post-code-deploy └── .gitignore ├── post-code-update └── .gitignore ├── post-db-copy └── .gitignore ├── post-files-copy └── .gitignore └── pre-web-activate └── .gitignore /README.md: -------------------------------------------------------------------------------- 1 | ## What are Cloud Hooks? 2 | 3 | Cloud Hooks is a feature of Acquia Cloud, the Drupal cloud hosting platform. For more information, see https://www.acquia.com/products-services/acquia-dev-cloud. 4 | 5 | The Acquia Cloud Workflow page automates the most common tasks involved in developing a Drupal site: 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. 6 | 7 | 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: 8 | 9 | * Perform Drupal database updates each time new code is deployed. 10 | * "Scrub" your Production database when it is copied to Dev or Staging by removing customer emails or disabling production-only modules. 11 | * Run your test suite or a site performance test each time new code is deployed. 12 | 13 | ## Installing Cloud Hooks 14 | 15 | Cloud hook scripts live in your Acquia Cloud code repository. In each branch of your repo, there is a directory named docroot that contains your site's source code. Cloud hooks live in the directory hooks NEXT TO docroot (not inside of docroot). 16 | 17 | To install the correct directory structure and sample hook scripts, simply copy this repo into your Acquia Cloud repo. 18 | 19 | cd /my/repo 20 | curl -L -o hooks.tar.gz https://github.com/acquia/cloud-hooks/tarball/master 21 | tar xzf hooks.tar.gz 22 | mv acquia-cloud-hooks-* hooks 23 | git add hooks 24 | git commit -m 'Import Cloud hooks directory and sample scripts.' 25 | git push 26 | 27 | ## Quick Start 28 | 29 | To get an idea of the power of Cloud Hooks, let's run the "Hello, Cloud!" script when new code is deployed in to your Dev environment. 30 | 31 | 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*. 32 | 33 | cd /my/repo 34 | git checkout master 35 | cp hooks/samples/hello-world.sh hooks/dev/post-code-deploy 36 | git commit -a 'Run the hello-world script on post-code-deploy to Dev.' 37 | git push 38 | 39 | 2. Visit the Workflow page in the Acquia Cloud UI. 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), then press Deploy. 40 | 41 | 3. Scroll down on the Workflow page. When the code deployment task is done, click its "Show" link to see the hook's output. It will look like this: 42 | 43 | Started 44 | Updating s1.dev to deploy master 45 | Deploying master on s1.dev 46 | [05:28:33] Starting hook: post-code-deploy 47 | Executing: /var/www/html/s1.dev/hooks/dev/post-code-deploy/hello-world.sh s1 dev master master s1@svn-3.bjaspan.hosting.acquia.com:s1.git git (as s1@srv-4) 48 | Hello, Cloud! 49 | [05:28:34] Finished hook: post-code-deploy 50 | 51 | You can use the Code drop-down list to put your Dev environment back to whatever it was previously deploying. 52 | 53 | ## The Cloud Hooks directory 54 | 55 | The hooks directory in your repo has a directory structure like this: 56 | 57 | /hooks / [env] / [hook] / [script] 58 | 59 | * [env] is a directory whose name is an environment name: 'dev' for Development, 'test' for Staging, and 'prod' for Production, as well as 'common' for all environments. 60 | 61 | * [hook] is a directory whose name is a Cloud Hook name: see below for supported hooks. 62 | 63 | * [script] is a program or shell script within the [env]/[hook] directory. 64 | 65 | Each time a hookable action occurs, Acquia Cloud runs scripts from the directory common/[hook] and [target-env]/[hook]. All scripts in the hook directory are run, in lexicographical (shell glob) order. If one of the hook scripts exits with non-zero status, the remaining hook scripts are skipped, and the task is marked "failed" on the Workflow page so you know to check it. All stdout and stderr output from all the hooks that ran are displayed in the task log on the Workflow page. 66 | 67 | Note that hook scripts must have the Unix "executable" bit in order to run. If your script has the execute bit set when you first add it to Git, you're all set. Otherwise, to set the execute bit to a file already in your Git repo: 68 | 69 | chmod a+x ./my-hook.sh 70 | git add ./my-hook.sh 71 | git commit -m 'Add execute bit to my-hook.sh' 72 | git push 73 | 74 | 75 | ## Sample scripts 76 | 77 | The samples directory contains bare-bones example scripts for each of the supported hooks, plus a variety of useful user-contributed scripts. Each script starts with comments explaining what it is for and how it works. 78 | 79 | Sample scripts currently include: 80 | 81 | * post-code-deploy.tmpl: Template for post-code-deploy hook scripts. 82 | * post-code-update.tmpl: Template for post-code-update hook scripts. 83 | * post-db-copy.tmpl: Template for post-db-copy hook scripts. 84 | * post-files-copy.tmpl: Template for post-files-copy hook scripts. 85 | * update-db.sh: Run drush updatedb to perform database updates. 86 | * db-scrub.sh: Scrub important information from a Drupal database. 87 | * drupal-tests.sh: Run Drupal simpletests. 88 | * rollback.sh: Run designated simpletest testing against a branch/tag and rollback on failure. 89 | * newrelic.sh: Example of Acquia Hosting Cloud Hook to notify New Relic API of code version deployments. 90 | 91 | 92 | ## Supported hooks 93 | 94 | This section defines the currently supported Cloud Hooks and the command-line arguments they receive. 95 | 96 | ### post-code-deploy 97 | 98 | The post-code-deploy hook is run whenever you use the Workflow page to deploy new code to an environment, either via drag-drop or by selecting an existing branch or tag from the Code drop-down list. (The post-code-update hook runs after every code commit.) 99 | 100 | Usage: post-code-deploy site target-env source-branch deployed-tag repo-url repo-type 101 | 102 | * site: The site name. This is the same as the Acquia Cloud username for the site. 103 | * target-env: The environment to which code was just deployed. 104 | * source-branch: The code branch or tag being deployed. See below. 105 | * deployed-tag: The code branch or tag being deployed. See below. 106 | * repo-url: The URL of your code repository. 107 | * repo-type: The version control system your site is using; "git". 108 | 109 | The meaning of source-branch and deployed-tag depends on whether you use drag-drop to move code from one environment to another or whether you select a new branch or tag for an environment from the Code drop-down list: 110 | 111 | * With drag-drop, the "source branch" is the branch or tag that the environment you dragged from is set to, and the "deployed tag" is the tag just deployed in the target environment. If source-branch is a branch (does not start with "tags/"), deployed-tag will be a newly created tag pointing at the tip of source-branch. If source-branch is a tag, deployed-tag will be the same tag. 112 | 113 | * With the Code drop-down list, source-branch and deployed-tag will both be the name of branch or tag selected from the drop-down list. 114 | 115 | Example: If the Dev environment is deploying the master branch and you drag Dev code to Stage, the code-deploy arguments will be like: 116 | 117 | post-code-deploy mysite test master tags/2011-11-05 mysite@svn-3.devcloud.hosting.acquia.com:mysite.git git 118 | 119 | ### post-code-update 120 | 121 | The post-code-update hook runs in response to code commits. When you push commits to a Git branch, the post-code-update hooks runs for each environment that is currently running that branch. 122 | 123 | The arguments for post-code-update are the same as for post-code-deploy, with the source-branch and deployed-tag arguments both set to the name of the environment receiving the new code. 124 | 125 | ### post-db-copy 126 | 127 | The post-db-copy hook is run whenever you use the Workflow page to copy a database from one environment to another. 128 | 129 | Usage: post-db-copy site target-env db-name source-env 130 | 131 | * site: The site name. This is the same as the Acquia Cloud username for the site. 132 | * target-env: The environment to which the database was copied. 133 | * db-name: The name of the database that was copied. See below. 134 | * source-env: The environment from which the database was copied. 135 | 136 | db-name is not the actual MySQL database name but rather the common name for the database in all environments. Use the drush ah-sql-cli to connect to the actual MySQL database, or use the drush ah-sql-connect command to convert the site name and target environment into the specific MySQL database name and credentials. (The drush sql-cli and sql-connect commands work too, but only if your Drupal installation is set up correctly.) 137 | 138 | Example: To "scrub" your production database by removing all user accounts every time it is copied into your Stage environment, put this script into /hooks/test/post-db-copy/delete-users.sh: 139 | 140 | #!/bin/bash 141 | site=$1 142 | env=$2 143 | db=$3 144 | echo "DELETE FROM users" | drush @$site.$env ah-sql-cli --db=$db 145 | 146 | ### post-files-copy 147 | 148 | The post-files-copy hook is run whenever you use the Workflow page to copy the user-uploaded files directory from one environment to another. 149 | 150 | Usage: post-files-copy site target-env source-env 151 | 152 | * site: The site name. This is the same as the Acquia Cloud username for the site. 153 | * target-env: The environment to which files were copied. 154 | * source-env: The environment from which the files were copied. 155 | 156 | Example: When you use the Workflow page to drag files from Prod to Dev, the files-copy hook will be run like: 157 | 158 | post-files-copy mysite prod dev 159 | -------------------------------------------------------------------------------- /common/post-code-deploy/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/acquia/cloud-hooks/e88d74974f96889010e05c3e30d28b0fceb451ed/common/post-code-deploy/.gitignore -------------------------------------------------------------------------------- /common/post-code-update/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/acquia/cloud-hooks/e88d74974f96889010e05c3e30d28b0fceb451ed/common/post-code-update/.gitignore -------------------------------------------------------------------------------- /common/post-db-copy/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/acquia/cloud-hooks/e88d74974f96889010e05c3e30d28b0fceb451ed/common/post-db-copy/.gitignore -------------------------------------------------------------------------------- /common/post-files-copy/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/acquia/cloud-hooks/e88d74974f96889010e05c3e30d28b0fceb451ed/common/post-files-copy/.gitignore -------------------------------------------------------------------------------- /common/pre-web-activate/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/acquia/cloud-hooks/e88d74974f96889010e05c3e30d28b0fceb451ed/common/pre-web-activate/.gitignore -------------------------------------------------------------------------------- /dev/post-code-deploy/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/acquia/cloud-hooks/e88d74974f96889010e05c3e30d28b0fceb451ed/dev/post-code-deploy/.gitignore -------------------------------------------------------------------------------- /dev/post-code-update/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/acquia/cloud-hooks/e88d74974f96889010e05c3e30d28b0fceb451ed/dev/post-code-update/.gitignore -------------------------------------------------------------------------------- /dev/post-db-copy/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/acquia/cloud-hooks/e88d74974f96889010e05c3e30d28b0fceb451ed/dev/post-db-copy/.gitignore -------------------------------------------------------------------------------- /dev/post-files-copy/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/acquia/cloud-hooks/e88d74974f96889010e05c3e30d28b0fceb451ed/dev/post-files-copy/.gitignore -------------------------------------------------------------------------------- /dev/pre-web-activate/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/acquia/cloud-hooks/e88d74974f96889010e05c3e30d28b0fceb451ed/dev/pre-web-activate/.gitignore -------------------------------------------------------------------------------- /prod/post-code-deploy/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/acquia/cloud-hooks/e88d74974f96889010e05c3e30d28b0fceb451ed/prod/post-code-deploy/.gitignore -------------------------------------------------------------------------------- /prod/post-code-update/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/acquia/cloud-hooks/e88d74974f96889010e05c3e30d28b0fceb451ed/prod/post-code-update/.gitignore -------------------------------------------------------------------------------- /prod/post-db-copy/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/acquia/cloud-hooks/e88d74974f96889010e05c3e30d28b0fceb451ed/prod/post-db-copy/.gitignore -------------------------------------------------------------------------------- /prod/post-files-copy/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/acquia/cloud-hooks/e88d74974f96889010e05c3e30d28b0fceb451ed/prod/post-files-copy/.gitignore -------------------------------------------------------------------------------- /prod/pre-web-activate/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/acquia/cloud-hooks/e88d74974f96889010e05c3e30d28b0fceb451ed/prod/pre-web-activate/.gitignore -------------------------------------------------------------------------------- /samples/db-scrub.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # db-copy Cloud hook: db-scrub 4 | # 5 | # Scrub important information from a Drupal database. 6 | # 7 | # Usage: db-scrub.sh site target-env db-name source-env 8 | 9 | site="$1" 10 | target_env="$2" 11 | db_name="$3" 12 | source_env="$4" 13 | 14 | echo "$site.$target_env: Scrubbing database $db_name" 15 | 16 | (cat < 0); 39 | 40 | -- don't leave e-mail addresses, etc in comments table. 41 | -- UPDATE comments SET name='Anonymous', mail='', homepage='http://example.com' WHERE uid=0; 42 | 43 | -- Scrub webform submissions. 44 | -- UPDATE webform_submitted_data set data='*scrubbed*'; 45 | 46 | -- remove sensitive customer data from custom module 47 | -- TRUNCATE custom_customer_lead_data; 48 | 49 | -- USER PASSWORDS 50 | -- These statements assume you want to preserve real passwords for developers. Change 'rid=3' to the 51 | -- developer or test role you want to preserve. 52 | 53 | -- DRUPAL 6 54 | -- Remove passwords unless users have 'developer role' 55 | -- UPDATE users SET pass=md5('devpassword') WHERE uid IN (SELECT uid FROM users_roles WHERE rid=3) AND uid > 0; 56 | 57 | -- Admin user should not be same but not really well known 58 | -- UPDATE users SET pass = MD5('supersecret!') WHERE uid = 1; 59 | 60 | -- DRUPAL 7 61 | -- Drupal 7 requires sites to generate a hashed password specific to their site. A script in the 62 | -- docroot/scripts directory is provided for doing this. From your docroot run the following: 63 | -- 64 | -- scripts/password-hash.sh password 65 | -- 66 | -- this will generate a hash for the password "password". In the following statements replace 67 | -- $REPLACE THIS$ with your generated hash. 68 | 69 | -- Remove passwords unless users have 'developer role' 70 | -- UPDATE users SET pass='$REPLACE THIS$' WHERE uid IN (SELECT uid FROM users_roles WHERE rid=3) AND uid > 0; 71 | 72 | -- Admin user should not be same but not really well known 73 | -- UPDATE users SET pass='$REPLACE THIS$' WHERE uid = 1; 74 | 75 | -- TRUNCATE accesslog; 76 | -- TRUNCATE access; 77 | -- TRUNCATE cache; 78 | -- TRUNCATE cache_filter; 79 | -- TRUNCATE cache_menu; 80 | -- TRUNCATE cache_page; 81 | -- TRUNCATE cache_views; 82 | -- TRUNCATE cache_views_data; 83 | -- TRUNCATE devel_queries; 84 | -- TRUNCATE devel_times; 85 | -- TRUNCATE flood; 86 | -- TRUNCATE history; 87 | -- TRUNCATE search_dataset; 88 | -- TRUNCATE search_index; 89 | -- TRUNCATE search_total; 90 | -- TRUNCATE sessions; 91 | -- TRUNCATE watchdog; 92 | 93 | 94 | EOF 95 | ) | drush @$site.$target_env ah-sql-cli --db=$db_name 96 | -------------------------------------------------------------------------------- /samples/domain_fix.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env php 2 | 7 | * 8 | * This file should be placed in /hooks/common/post-db-copy 9 | * and will allow domains in domain_access module to be updated 10 | * following database copy. This ensures no manual updates to 11 | * the domains configuration are necessary after copying a db 12 | * between environments. 13 | */ 14 | 15 | $site = $argv[1]; 16 | $env = $argv[2]; 17 | $db = $argv[3]; 18 | $source = $argv[4]; 19 | 20 | // First ensure the domain module is installed. We do this by checking 21 | // existence of the domain table in the appropriate database. 22 | $domain=`echo "SHOW TABLES LIKE 'domain'" | drush @$site.$env ah-sql-cli --db=$db"`; 23 | 24 | if (!$domain) { 25 | $returns[] = "Domain module not installed, aborting"; 26 | } 27 | else { 28 | 29 | // Build a list of domains that require changing after the db has copied. 30 | // Each element of the $domains array should be keyed the machine name 31 | // and have key/value pairs of environment => URL. 32 | $domains = array( 33 | 'foo_com' => array( 34 | 'dev' => 'dev.foo.com', 35 | 'test' => 'stg.foo.com', 36 | 'prod' => 'foo.com', 37 | ), 38 | 'bar_com' => array( 39 | 'dev' => 'dev.bar.com', 40 | 'test' => 'stg.bar.com', 41 | 'prod' => 'bar.com', 42 | ), 43 | 'example_com' => array( 44 | 'dev' => 'dev.example.com', 45 | 'test' => 'stg.example.com', 46 | 'prod' => 'example.com', 47 | ), 48 | ); 49 | 50 | // Iterate through the domains and update the record to the URL specified. 51 | // If the domain machine name does not exist, the record will be skipped. 52 | foreach ($domains as $domain => $info) { 53 | if (isset($info[$env])) { 54 | $to = $info[$env]; 55 | $returns[] = "Updating domain table to update $domain to $to"; 56 | echo "UPDATE domain SET subdomain = "$to" where machine_name = "$domain" | drush @$site.$env ah-sql-cli --db=$db"; 57 | } 58 | } 59 | } 60 | 61 | // This output will be visible from the insights dashboard to reveal 62 | // which domains have been updated. 63 | foreach ($returns as $output) { 64 | print "$output\n"; 65 | } 66 | 67 | -------------------------------------------------------------------------------- /samples/drupal-tests.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Cloud Hook: drupal-tests 4 | # 5 | # Run Drupal simpletests in the target environment using drush test-run. 6 | 7 | site="$1" 8 | target_env="$2" 9 | 10 | # Select the tests to run. Run "drush help test-run" for options. 11 | TESTS="UserRegistrationTestCase" 12 | # To run all tests (very slow!), uncomment this line. 13 | TESTS="--all" 14 | 15 | # Enable the simpletest module if it is not already enabled. 16 | simpletest=`drush @$site.$target_env pm-info simpletest | perl -F'/[\s:]+/' -lane '/Status/ && print $F[2]'` 17 | if [ "$simpletest" = "disabled" ]; then 18 | echo "Temporarily enabling simpletest module." 19 | drush @$site.$target_env pm-enable simpletest --yes 20 | fi 21 | 22 | # Run the tests. 23 | drush @$site.$target_env test-run $TESTS 24 | status=$? 25 | 26 | # If we enabled simpletest, disable it. 27 | if [ "$simpletest" = "disabled" ]; then 28 | echo "Disabling simpletest module." 29 | drush @$site.$target_env pm-disable simpletest --yes 30 | fi 31 | 32 | exit $status 33 | -------------------------------------------------------------------------------- /samples/drush-cache-clear.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Cloud Hook: drush-cache-clear 4 | # 5 | # Run drush cache-clear all in the target environment. This script works as 6 | # any Cloud hook. 7 | 8 | 9 | # Map the script inputs to convenient names. 10 | site=$1 11 | target_env=$2 12 | drush_alias=$site'.'$target_env 13 | 14 | # Execute a standard drush command. 15 | drush @$drush_alias cc all 16 | -------------------------------------------------------------------------------- /samples/email/README.md: -------------------------------------------------------------------------------- 1 | # Email Notification 2 | 3 | This cloud hook sends an email after a code deployment has been performed on 4 | Acquia Cloud. 5 | 6 | ### Example Scenario 7 | 8 | 1. A new tag or branch is deployed to the production environment. 9 | 2. An email is sent indicating that the code has been deployed. 10 | 11 | ### Installation Steps 12 | 13 | * Define the email(s) you want to send to in MAILTO variable in `email.sh`. 14 | * Add `email.sh` (but _not_ README.md) to the dev, test, prod or common 15 | __post-code-deploy__ hook folder. 16 | -------------------------------------------------------------------------------- /samples/email/email.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Cloud Hook: post-code-deploy 4 | # 5 | # The post-code-deploy hook is run whenever you use the Workflow page to 6 | # deploy new code to an environment, either via drag-drop or by selecting 7 | # an existing branch or tag from the Code drop-down list. See 8 | # ../README.md for details. 9 | # 10 | # Usage: email site target-env source-branch deployed-tag repo-url 11 | # repo-type 12 | 13 | # Enter the email(s) you want to send notifications to 14 | MAILTO=address@example.com 15 | 16 | site="$1" 17 | target_env="$2" 18 | source_branch="$3" 19 | deployed_tag="$4" 20 | repo_url="$5" 21 | repo_type="$6" 22 | 23 | if [ "$source_branch" != "$deployed_tag" ]; then 24 | MSG="$site.$target_env: Deployed branch $source_branch as $deployed_tag." 25 | else 26 | MSG="$site.$target_env: Deployed $deployed_tag." 27 | fi 28 | 29 | echo "$MSG" | mail -s "$MSG" "$MAILTO" 30 | -------------------------------------------------------------------------------- /samples/hello-world.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # This sample Cloud Hook script just echos "Hello, Cloud!" to standard 4 | # output. It will work in any hook directory. 5 | 6 | echo "Hello, Cloud!" 7 | 8 | -------------------------------------------------------------------------------- /samples/hipchat/README.md: -------------------------------------------------------------------------------- 1 | # HipChat Notification 2 | 3 | This cloud hook posts a notification to a HipChat room after a code deployment 4 | has been performed on Acquia Cloud. 5 | 6 | ### Example Scenario 7 | 8 | 1. A new tag is deployed to the production environment. 9 | 2. A HipChat notification is posted indicating that a tag has been deployed. 10 | 11 | ### Installation Steps 12 | 13 | Installation Steps (assumes HipChat subscription setup and Acquia Cloud Hooks installed in repo): 14 | 15 | * See the API documentation at https://www.hipchat.com/docs/apiv2 and https://www.hipchat.com/docs/apiv2/method/send_room_notification 16 | * Visit https://YOURCOMPANY.hipchat.com/rooms/tokens/ROOM_ID create your notification token `AUTH_TOKEN`. 17 | * Store the AUTH_TOKEN and the ROOM_ID in `$HOME/hipchat_settings` file on your Acquia Cloud Server (see hipchat_settings file). 18 | * Set the execution bit to on e.g. `chmod a+x hipchat_settings` 19 | * Add `hipchat.sh` to dev, test, prod or common __post-cody-deploy__ hook. 20 | 21 | 22 | -------------------------------------------------------------------------------- /samples/hipchat/hipchat.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Cloud Hook: post-code-deploy 4 | # 5 | # The post-code-deploy hook is run whenever you use the Workflow page to 6 | # deploy new code to an environment, either via drag-drop or by selecting 7 | # an existing branch or tag from the Code drop-down list. See 8 | # ../README.md for details. 9 | # 10 | # Usage: post-code-deploy site target-env source-branch deployed-tag repo-url 11 | # repo-type 12 | 13 | site="$1" 14 | target_env="$2" 15 | source_branch="$3" 16 | deployed_tag="$4" 17 | repo_url="$5" 18 | repo_type="$6" 19 | 20 | # Load the HipChat webhook URL (which is not stored in this repo). 21 | . $HOME/hipchat_settings 22 | 23 | # Post deployment notice to HipChat 24 | 25 | if [ "$source_branch" != "$deployed_tag" ]; then 26 | curl --header "content-type: application/json" --header "Authorization: Bearer $AUTH_TOKEN" -X POST \ 27 | -d "{\"message\":\"An updated deployment has been made to $site.$target_env using branch $source_branch as $deployed_tag.\"}" $HIPCHAT_WEBHOOK_URL 28 | else 29 | curl --header "content-type: application/json" --header "Authorization: Bearer $AUTH_TOKEN" -X POST \ 30 | -d "{\"message\":\"An updated deployment has been made to $site.$target_env using tag $deployed_tag.\"}" $HIPCHAT_WEBHOOK_URL 31 | fi 32 | 33 | 34 | -------------------------------------------------------------------------------- /samples/hipchat/hipchat_settings: -------------------------------------------------------------------------------- 1 | ROOM_ID=AAABBBAAA 2 | AUTH_TOKEN=XXXYYYXXX 3 | 4 | HIPCHAT_WEBHOOK_URL=https://api.hipchat.com/v2/room/$ROOM_ID/notification -------------------------------------------------------------------------------- /samples/newrelic/README.md: -------------------------------------------------------------------------------- 1 | # Example of Acquia Cloud Hook to notify New Relic API of code version deployments 2 | 3 | Installation Steps (assumes New Relic subscription setup and Acquia Cloud Hooks installed in repo): 4 | 5 | * Login to New Relic and goto https://rpm.newrelic.com/accounts/(UserID)/applications/(ApplicationID)/deployments/instructions 6 | * From the instructions get your application_id and your x-api-key. Store these variables and a username you wish to send to New Relic in $HOME/newrelic_settings file on your Acquia Cloud Server (see example file). 7 | * Set the execution bit to on i.e. chmod a+x newrelic_settings 8 | * Add newrelic.sh to dev, test, prod or common post-code-deploy hook. 9 | 10 | 11 | -------------------------------------------------------------------------------- /samples/newrelic/newrelic.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # This sample a Cloud Hook script to update New Relic whenever there is a new code deployment 4 | 5 | site=$1 # The site name. This is the same as the Acquia Cloud username for the site. 6 | targetenv=$2 # The environment to which code was just deployed. 7 | sourcebranch=$3 # The code branch or tag being deployed. 8 | deployedtag=$4 # The code branch or tag being deployed. 9 | repourl=$5 # The URL of your code repository. 10 | repotype=$6 # The version control system your site is using; "git" or "svn". 11 | 12 | 13 | #Load the New Relic APPID and APPKEY variables. 14 | . $HOME/newrelic_settings 15 | 16 | #https://docs.newrelic.com/docs/apm/new-relic-apm/maintenance/recording-deployments#post-deployment 17 | curl -X POST "https://api.newrelic.com/v2/applications/$APPID/deployments.json" \ 18 | -H "X-Api-Key:$APIKEY" -i \ 19 | -H "Content-Type: application/json" \ 20 | -d \ 21 | "{ 22 | \"deployment\": { 23 | \"revision\": \"$deployedtag\", 24 | \"changelog\": \"$deployedtag deployed to $site.$targetenv\", 25 | \"description\": \"$deployedtag deployed to $site.$targetenv\", 26 | \"user\": \"$username\" 27 | } 28 | }" 29 | -------------------------------------------------------------------------------- /samples/newrelic/newrelic_settings: -------------------------------------------------------------------------------- 1 | APIKEY='123456abcdefgh1234567890abcdefgh1234567890abc1234567890' 2 | APPID='123456' 3 | username='myname@mydomain.com' 4 | -------------------------------------------------------------------------------- /samples/post-code-deploy.tmpl: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Cloud Hook: post-code-deploy 4 | # 5 | # The post-code-deploy hook is run whenever you use the Workflow page to 6 | # deploy new code to an environment, either via drag-drop or by selecting 7 | # an existing branch or tag from the Code drop-down list. See 8 | # ../README.md for details. 9 | # 10 | # Usage: post-code-deploy site target-env source-branch deployed-tag repo-url 11 | # repo-type 12 | 13 | site="$1" 14 | target_env="$2" 15 | source_branch="$3" 16 | deployed_tag="$4" 17 | repo_url="$5" 18 | repo_type="$6" 19 | 20 | if [ "$source_branch" != "$deployed_tag" ]; then 21 | echo "$site.$target_env: Deployed branch $source_branch as $deployed_tag." 22 | else 23 | echo "$site.$target_env: Deployed $deployed_tag." 24 | fi 25 | -------------------------------------------------------------------------------- /samples/post-code-update.tmpl: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Cloud Hook: post-code-update 4 | # 5 | # The post-code-update hook runs in response to code commits. 6 | # When you push commits to a Git branch, the post-code-update hooks runs for 7 | # each environment that is currently running that branch. See 8 | # ../README.md for details. 9 | # 10 | # Usage: post-code-update site target-env source-branch deployed-tag repo-url 11 | # repo-type 12 | 13 | site="$1" 14 | target_env="$2" 15 | source_branch="$3" 16 | deployed_tag="$4" 17 | repo_url="$5" 18 | repo_type="$6" 19 | 20 | 21 | if [ "$target_env" != 'prod' ]; then 22 | echo "$site.$target_env: The $source_branch branch has been updated on $target_env. Clearing the cache." 23 | drush @$site.$target_env cc all 24 | else 25 | echo "$site.$target_env: The $source_branch branch has been updated on $target_env." 26 | fi 27 | -------------------------------------------------------------------------------- /samples/post-db-copy.tmpl: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Cloud Hook: post-db-copy 4 | # 5 | # The post-db-copy hook is run whenever you use the Workflow page to copy a 6 | # database from one environment to another. See ../README.md for 7 | # details. 8 | # 9 | # Usage: post-db-copy site target-env db-name source-env 10 | 11 | site="$1" 12 | target_env="$2" 13 | db_name="$3" 14 | source_env="$4" 15 | 16 | echo "$site.$target_env: Received copy of database $db_name from $source_env." 17 | -------------------------------------------------------------------------------- /samples/post-files-copy.tmpl: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Cloud Hook: post-files-copy 4 | # 5 | # The post-files-copy hook is run whenever you use the Workflow page to 6 | # copy the files directory from one environment to another. See 7 | # ../README.md for details. 8 | # 9 | # Usage: post-files-copy site target-env source-env 10 | 11 | site="$1" 12 | target_env="$2" 13 | source_env="$3" 14 | 15 | echo "$site.$target_env: Received copy of files from $source_env." 16 | -------------------------------------------------------------------------------- /samples/pushbullet/README.md: -------------------------------------------------------------------------------- 1 | # Pushbullet Notification 2 | 3 | This cloud hook posts a notification to Pushbullet after a code deployment 4 | has been performed on Acquia Cloud. 5 | 6 | ### Example Scenario 7 | 8 | 1. A new tag is deployed to the production environment. 9 | 2. A Pushbullet notification is posted and sent to your devices indicating that a tag has been deployed. 10 | 11 | ### Installation Steps 12 | 13 | Installation Steps (assumes Pushbullet account and Acquia Cloud Hooks installed in repo): 14 | 15 | * See the API documentation at https://docs.pushbullet.com/#push 16 | * Visit https://www.pushbullet.com/#settings create an access token `AUTH_TOKEN`. 17 | * Store the AUTH_TOKEN in `$HOME/pushbullet_settings` file on your Acquia Cloud Server (see pushbullet_settings file). 18 | * Set the execution bit to on e.g. `chmod a+x pushbullet_settings` (On windows `git update-index --chmod=+x pushbullet_settings`) 19 | * Add `pushbullet.sh` to dev, test, prod or common __post-code-deploy__ hook. 20 | -------------------------------------------------------------------------------- /samples/pushbullet/pushbullet.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Cloud Hook: post-code-deploy 4 | # 5 | # The post-code-deploy hook is run whenever you use the Workflow page to 6 | # deploy new code to an environment, either via drag-drop or by selecting 7 | # an existing branch or tag from the Code drop-down list. See 8 | # ../README.md for details. 9 | # 10 | # Usage: post-code-deploy site target-env source-branch deployed-tag repo-url 11 | # repo-type 12 | 13 | site="$1" 14 | target_env="$2" 15 | source_branch="$3" 16 | deployed_tag="$4" 17 | repo_url="$5" 18 | repo_type="$6" 19 | 20 | # Load the Pushbullet API URL (which is not stored in this repo). 21 | . $HOME/pushbullet_settings 22 | 23 | # Link to your enviorment 24 | push_url="http://www.acquia.com/" 25 | 26 | # Post deployment notice to Pushbullet 27 | curl -k -u $AUTH_TOKEN: -X POST $PUSHBULLET_API_URL --header 'Content-Type: application/json' -d "{\"type\": \"link\", \"title\": \"$site.$target_env\", \"body\": \"Deployed $deployed_tag\", \"url\": \"$push_url\"}" 28 | -------------------------------------------------------------------------------- /samples/pushbullet/pushbullet_settings: -------------------------------------------------------------------------------- 1 | AUTH_TOKEN=XXXYYYXXX 2 | 3 | PUSHBULLET_API_URL=https://api.pushbullet.com/v2/pushes 4 | -------------------------------------------------------------------------------- /samples/rollback/README.md: -------------------------------------------------------------------------------- 1 | # Code Deploy Rollback 2 | 3 | This hook utilizes the simpletest module to test code base during deployment and automatically 4 | rollback to the last deployed set of code on test failure. Since pre-code-deploy hooks don't exist 5 | yet we store original code source in the origsource variable in the rollback settings file stored in 6 | the $HOME dir. This file also lists drush test-run tests to be run and the number of attempts to make 7 | before giving up. 8 | 9 | ### Example Scenario 10 | 11 | ### Installation Steps 12 | 13 | 14 | Installation Steps (assumes ah cloud hooks installed in Version Control Software) 15 | 16 | * Copy rollback.sh into your dev, stage, prod, or common hooks directory. 17 | * SCP or SFTP rollback_settings to your $HOME dir on your Acquia Host Server. 18 | * $TEST settings are available SimpleTests (or core Testing module in D7+). You may use '--all' for all tests (very slow). See http://drupal.org/simpletest for details. 19 | * Edit rollback_settings to your existing code base ($ORIGSOURCE), test setting ($TEST) and number of attempts ($ATTEMPTS). Ensure execute bits are set on both files. (i.e. chmod a+x rollback_settings and chmod a+x rollback.sh) 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /samples/rollback/rollback.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Cloud Hook: tests_rollback 4 | # 5 | # Run Drupal simpletests in the target environment using drush test-run. On failure, 6 | # rollback to last deployed code set 7 | # 8 | # implements Cloud_hook post_code_deploy 9 | # @todo needs to have pre_code_deploy for proper handling of files. 10 | # 11 | 12 | 13 | site="$1" 14 | target_env="$2" 15 | sourcebranch=$3 # The code branch or tag being deployed. 16 | deployedtag=$4 # The code branch or tag being deployed. 17 | repourl=$5 # The URL of your code repository. 18 | repotype=$6 # The version control system your site is using; "git" or "svn". 19 | 20 | #load variable settings from $HOME/rollback_settings 21 | #Check rollback_settings exists; if not alert and exit 22 | if [ -x "$HOME/rollback_settings" ]; then 23 | . $HOME/rollback_settings 24 | else 25 | echo "rollback_settings file not found in $HOME or not able to include (check execution bit)" 26 | exit 1 27 | fi 28 | 29 | #check attempts variable has any number of tries left. To prevent infinite loops. 30 | if [ "$ATTEMPTS" -le 0 ]; then 31 | echo "Maximum Number of attempts exceeded! Exiting." 32 | exit 1 33 | fi 34 | 35 | #now set the variable and append it into the settings file. 36 | ORIGATTEMPTS=$ATTEMPTS 37 | let "ATTEMPTS-=1" 38 | sed -i "s/ATTEMPTS=$ORIGATTEMPTS/ATTEMPTS=$ATTEMPTS/" $HOME/rollback_settings 39 | 40 | #initialize exit code so we can exit with 0 after rollback 41 | extcode=0 42 | 43 | # Enable the simpletest module if it is not already enabled. 44 | simpletest=`drush @$site.$target_env pm-info simpletest | perl -F'/[\s:]+/' -lane '/Status/ && print $F[2]'` 45 | if [ "$simpletest" = "disabled" ]; then 46 | echo "Temporarily enabling simpletest module." 47 | drush @$site.$target_env pm-enable simpletest --yes 48 | fi 49 | 50 | # Run the tests. 51 | CMD=`drush @$site.$target_env test-run $TESTS` 52 | 53 | #test output from drush 54 | if [ $? -ne 0 ]; then 55 | 56 | #sanity check to make sure we have a $origsource to fall back to. 57 | if [ $ORIGSOURCE ]; then 58 | #if simpletests fail tell the user and launch a new job rolling back to the original source 59 | echo "Testing failed on deploy rolling back to $ORIGSOURCE" 60 | echo "Executing: drush @$site.$target_env ac-code-path-deploy $ORIGSOURCE" 61 | drush @$site.$target_env ac-code-path-deploy $ORIGSOURCE 62 | else #something is very wrong should never get here, if we do notify and quit. 63 | echo "Cannot rollback. No fallback source identified." 64 | exit 1 65 | fi 66 | #set exitcode to fail so this code base does not deploy 67 | extcode=1 68 | 69 | else 70 | 71 | #simpletests passed! Inform user then clear and set rollback_settings to new code base 72 | echo "Testing passed on deploy of $deployedtag" 73 | sed -i "s/ORIGSOURCE=$ORIGSOURCE/ORIGSOURCE=$deployedtag/" $HOME/rollback_settings 74 | extcode=0 75 | 76 | fi 77 | 78 | # If we enabled simpletest, disable it. 79 | if [ "$simpletest" = "disabled" ]; then 80 | echo "Disabling simpletest module." 81 | drush @$site.$target_env pm-disable simpletest --yes 82 | fi 83 | 84 | #cleanly exit 85 | exit $extcode 86 | 87 | 88 | 89 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /samples/rollback/rollback_settings: -------------------------------------------------------------------------------- 1 | ORIGSOURCE="master" 2 | TESTS="UserRegistrationTestCase" 3 | ATTEMPTS=3 4 | -------------------------------------------------------------------------------- /samples/slack/README.md: -------------------------------------------------------------------------------- 1 | # Slack Notification 2 | 3 | This cloud hook posts a notification to Slack chat room after a code deployment 4 | has been performed on Acquia Cloud. 5 | 6 | ### Example Scenario 7 | 8 | 1. A new tag is deployed to the production environment. 9 | 2. A slack notification is posted indicating that a tag has been deployed. 10 | 11 | ### Installation Steps 12 | 13 | Installation Steps (assumes Slack subscription setup and Acquia Cloud Hooks installed in repo): 14 | 15 | * See the API documentation at https://api.slack.com/ to set up an Incoming Webhook. 16 | * Store the webhook URL in `$HOME/slack_settings` file on your Acquia Cloud Server (see slack_settings file). 17 | * Add `slack.sh` to dev, test, prod or common __post-code-deploy__ and __post-code-update__ hooks. 18 | 19 | 20 | -------------------------------------------------------------------------------- /samples/slack/slack.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Cloud Hook: post-code-deploy 4 | # 5 | # The post-code-deploy hook is run whenever you use the Workflow page to 6 | # deploy new code to an environment, either via drag-drop or by selecting 7 | # an existing branch or tag from the Code drop-down list. See 8 | # ../README.md for details. 9 | # 10 | # Usage: post-code-deploy site target-env source-branch deployed-tag repo-url 11 | # repo-type 12 | 13 | site="$1" 14 | target_env="$2" 15 | source_branch="$3" 16 | deployed_tag="$4" 17 | repo_url="$5" 18 | repo_type="$6" 19 | 20 | FILE=$HOME/slack_settings 21 | 22 | if [ -f $FILE ]; then 23 | # Load the Slack webhook URL (which is not stored in this repo). 24 | . $HOME/slack_settings 25 | 26 | # Post deployment notice to Slack 27 | 28 | if [ "$source_branch" != "$deployed_tag" ]; then 29 | curl -X POST --data-urlencode "payload={\"username\": \"Acquia Cloud\", \"text\": \"An updated deployment has been made to *$site.$target_env* using branch *$source_branch* as *$deployed_tag*.\", \"icon_emoji\": \":acquiacloud:\"}" $SLACK_WEBHOOK_URL 30 | else 31 | curl -X POST --data-urlencode "payload={\"username\": \"Acquia Cloud\", \"text\": \"An updated deployment has been made to *$site.$target_env* using tag *$deployed_tag*.\", \"icon_emoji\": \":acquiacloud:\"}" $SLACK_WEBHOOK_URL 32 | fi 33 | else 34 | echo "File $FILE does not exist." 35 | fi 36 | -------------------------------------------------------------------------------- /samples/slack/slack_settings: -------------------------------------------------------------------------------- 1 | SLACK_WEBHOOK_URL=https://hooks.slack.com/services/xxx/yyy/zzz 2 | -------------------------------------------------------------------------------- /samples/update-db.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Cloud Hook: update-db 4 | # 5 | # Run drush updatedb in the target environment. This script works as 6 | # any Cloud hook. 7 | 8 | site="$1" 9 | target_env="$2" 10 | 11 | drush @$site.$target_env updatedb --yes 12 | -------------------------------------------------------------------------------- /test/post-code-deploy/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/acquia/cloud-hooks/e88d74974f96889010e05c3e30d28b0fceb451ed/test/post-code-deploy/.gitignore -------------------------------------------------------------------------------- /test/post-code-update/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/acquia/cloud-hooks/e88d74974f96889010e05c3e30d28b0fceb451ed/test/post-code-update/.gitignore -------------------------------------------------------------------------------- /test/post-db-copy/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/acquia/cloud-hooks/e88d74974f96889010e05c3e30d28b0fceb451ed/test/post-db-copy/.gitignore -------------------------------------------------------------------------------- /test/post-files-copy/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/acquia/cloud-hooks/e88d74974f96889010e05c3e30d28b0fceb451ed/test/post-files-copy/.gitignore -------------------------------------------------------------------------------- /test/pre-web-activate/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/acquia/cloud-hooks/e88d74974f96889010e05c3e30d28b0fceb451ed/test/pre-web-activate/.gitignore --------------------------------------------------------------------------------