Skip to content

Commit

Permalink
Fixes acquia#1212: Make Acquia Cloud hooks opt-in. (acquia#1219)
Browse files Browse the repository at this point in the history
* Move cloud-hooks from template directory to scripts/cloud-hooks/.

* Add cloud hook setup target.

* Add cloud hook setup info to deploy docs.

* Add call to new cloud hook setup target from doctor.sh.

* Add cloud hook unit test to verify hooks directory setup.

* Move logic that changes cloud hooks to re-install Drupal on deploy.
  • Loading branch information
malikkotob authored and grasmash committed Mar 21, 2017
1 parent f841b2e commit 3922d31
Show file tree
Hide file tree
Showing 23 changed files with 53 additions and 4 deletions.
6 changes: 6 additions & 0 deletions phing/tasks/setup.xml
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,12 @@

</target>

<target name="setup:cloud-hooks" description="Installs Acquia cloud hooks to hooks directory from version controlled scripts/cloud-hooks directory.">
<copy todir="${repo.root}/hooks" >
<fileset dir="${blt.root}/scripts/cloud-hooks/hooks"/>
</copy>
</target>

<target name="setup:hash-salt" description="Generates and writes a hash salt to ${repo.root}/salt.txt if one does not exist.">
<!-- If a hash salt does not exist, generate one. -->
<echo>Checking for hash salt in ${repo.root}/salt.txt</echo>
Expand Down
14 changes: 14 additions & 0 deletions readme/deploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,20 @@ Instead of performing these deployments manually, you can enlist the help of a C

On Acquia Cloud, [Cloud Hooks](https://docs.acquia.com/cloud/manage/cloud-hooks) are the preferred method to run database updates and configuration imports on each deploy. BLT provides a post-code-deploy hook that will conveniently run these updates automatically and fail the deployment task in Insight if anything goes wrong.

To install Acquia Cloud hooks for your BLT project:

1. Initialize Acquia Cloud hooks

blt setup:cloud-hooks

This will add a hooks directory in your project root based on [BLT's default Acquia Cloud hooks](https://github.com/acquia/blt/tree/8.x/scripts/cloud-hooks/hooks).

1. Commit the new directory and push it to your Acquia git remote. Example commands:

git add hooks
git commit -m 'Initializing Acquia Cloud hooks.'
git push origin

For consistency and reliability, you should run the same updates on deployment as you would run locally or in CI testing. BLT provides aliases for the `setup:update` task to support this, such as `local:update` and `deploy:update`. These aliases all run the same updates, but with the appropriate aliases and configuration directories for each environment.

If your team uses Slack, you can also be notified of each successful or failed deployment. Simply set up an incoming webhook in your Slack team to receive the notification (see the API documentation at https://api.slack.com/), and then store the webhook URL in a `$HOME/slack_settings` file on your Acquia Cloud servers:
Expand Down
4 changes: 0 additions & 4 deletions scripts/blt/ci/internal/create_blt_project.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ yaml-cli update:value blt/project.yml git.remotes.1 git@github.com:acquia-pso/bl
# BLT added new dependencies for us, so we must update.
composer update

# Change cloud hooks to re-install Drupal on deployments.
sed -i "s:deploy_updates:deploy_install:g" hooks/common/post-code-deploy/post-code-deploy.sh
sed -i "s:deploy_updates:deploy_install:g" hooks/common/post-code-update/post-code-update.sh

git add -A
git commit -m 'Adding new dependencies from BLT update.' -n
# Create a .travis.yml, just to make sure it works. It won't be executed.
Expand Down
6 changes: 6 additions & 0 deletions scripts/blt/ci/internal/doctor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ set -ev
composer require drupal/acsf:^1.33.0
# Initialize ACSF config.
blt acsf:init:hooks
# Initialize Acquia Cloud hooks.
blt setup:cloud-hooks
# Change cloud hooks to re-install Drupal on deployments.
sed -i "s:deploy_updates:deploy_install:g" hooks/common/post-code-deploy/post-code-deploy.sh
sed -i "s:deploy_updates:deploy_install:g" hooks/common/post-code-update/post-code-update.sh

blt acsf:init:drush
blt doctor
# Add Drupal VM config to repo.
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
27 changes: 27 additions & 0 deletions tests/phpunit/Blt/CloudHookTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Acquia\Blt\Tests\Blt;

use Acquia\Blt\Tests\BltTestBase;

/**
* Class CloudHookTest.
*
* Verifies that acsf support has been initialized.
*/
class CloudHookTest extends BltTestBase {

/**
* Tests Phing setup:cloud-hooks target.
*/
public function testSetupCloudHooks() {
$this->assertFileExists($this->new_project_dir . '/hooks');

$commonPostCodeDeployScript = $this->new_project_dir . '/hooks/common/post-code-deploy/post-code-deploy.sh';
$this->assertFileExists($commonPostCodeDeployScript);

$filePermissions = substr(sprintf('%o', fileperms($commonPostCodeDeployScript)), -4);
$this->assertEquals('0755', $filePermissions);
}

}

0 comments on commit 3922d31

Please sign in to comment.