Created
March 27, 2018 13:06
-
-
Save vyasamit2007/9a53f38ffec5ef599370e8e7d24f57d9 to your computer and use it in GitHub Desktop.
BLT - ACSF Backport Hooks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 5c995a21a5bdac8cbd97f794881801444b4ef4ab Mon Sep 17 00:00:00 2001 | |
From: vyasamit2007 <vyasamit2007@gmail.com> | |
Date: Tue, 27 Mar 2018 18:32:58 +0530 | |
Subject: [PATCH] ACSF Cloud Hooks / Factory Hooks Enhancements | |
--- | |
scripts/cloud-hooks/functions.sh | 36 ++++++++++++++++------ | |
.../common/post-code-deploy/post-code-deploy.sh | 4 +++ | |
settings/acsf/db-update/db-update.sh | 25 +++++++++++++++ | |
settings/acsf/post-install/post-install.php | 23 ++++++++++++++ | |
settings/acsf/post-settings-php/includes.php | 12 ++++++++ | |
.../acsf/post-theme-deploy/clear-twig-cache.sh | 14 +++++++++ | |
6 files changed, 104 insertions(+), 10 deletions(-) | |
create mode 100755 settings/acsf/db-update/db-update.sh | |
create mode 100755 settings/acsf/post-install/post-install.php | |
create mode 100644 settings/acsf/post-settings-php/includes.php | |
create mode 100644 settings/acsf/post-theme-deploy/clear-twig-cache.sh | |
diff --git a/scripts/cloud-hooks/functions.sh b/scripts/cloud-hooks/functions.sh | |
index d1ea049c5..4182d19b3 100644 | |
--- a/scripts/cloud-hooks/functions.sh | |
+++ b/scripts/cloud-hooks/functions.sh | |
@@ -7,16 +7,14 @@ drush_alias=${site}'.'${target_env} | |
deploy_updates() { | |
- case $target_env in | |
- 01dev|01test|01live) | |
- acsf_deploy | |
- ;; | |
- 01devup|01testup|01update) | |
- ;; | |
- *) | |
- ace_deploy | |
- ;; | |
- esac | |
+ if [[ $target_env =~ [0-9][1-9](dev|test) ]]; then | |
+ acsf_deploy | |
+ elif [[ $target_env =~ [0-9][1-9](devup|testup|update)|[0-9][1-9](live)|ode[0-9]* ]]; then | |
+ deploy_install | |
+ else | |
+ ace_deploy | |
+ fi | |
+ | |
} | |
acsf_deploy() { | |
@@ -71,6 +69,24 @@ ace_deploy() { | |
echo "Finished updates for environment: $target_env" | |
} | |
+deploy_sync() { | |
+ | |
+ echo "Running sync refresh for environment: $target_env" | |
+ | |
+ # Prep for BLT commands. | |
+ repo_root="/var/www/html/$site.$target_env" | |
+ export PATH=$repo_root/vendor/bin:$PATH | |
+ cd $repo_root | |
+ | |
+ blt deploy:sync:refresh --define environment=$target_env -v -y | |
+ if [ $? -ne 0 ]; then | |
+ echo "Sync errored." | |
+ exit 1 | |
+ fi | |
+ | |
+ echo "Finished sync for environment: $target_env" | |
+} | |
+ | |
deploy_install() { | |
echo "Installing site for environment: $target_env" | |
diff --git a/scripts/cloud-hooks/hooks/common/post-code-deploy/post-code-deploy.sh b/scripts/cloud-hooks/hooks/common/post-code-deploy/post-code-deploy.sh | |
index 6b4492888..20027a845 100755 | |
--- a/scripts/cloud-hooks/hooks/common/post-code-deploy/post-code-deploy.sh | |
+++ b/scripts/cloud-hooks/hooks/common/post-code-deploy/post-code-deploy.sh | |
@@ -20,9 +20,13 @@ repo_url="$5" | |
repo_type="$6" | |
+acsf_file="/mnt/files/$site.$target_env/files-private/sites.json" | |
+if [ ! -f $acsf_file ]; then | |
. /var/www/html/$site.$target_env/vendor/acquia/blt/scripts/cloud-hooks/functions.sh | |
deploy_updates | |
+fi | |
# Send notifications to Slack, if configured. See readme/deploy.md for setup instructions. | |
. `dirname $0`/../slack.sh | |
+ | |
set +v | |
diff --git a/settings/acsf/db-update/db-update.sh b/settings/acsf/db-update/db-update.sh | |
new file mode 100755 | |
index 000000000..b37ac3492 | |
--- /dev/null | |
+++ b/settings/acsf/db-update/db-update.sh | |
@@ -0,0 +1,25 @@ | |
+#!/bin/sh | |
+# | |
+# Factory Hook: db-update | |
+# | |
+# The existence of one or more executable files in the | |
+# /factory-hooks/db-update directory will prompt them to be run *instead of* the | |
+# regular database update (drush updatedb) command. So that update command will | |
+# normally be part of the commands executed below. | |
+# | |
+# Usage: post-code-deploy site env db-role domain custom-arg | |
+# Map the script inputs to convenient names. | |
+# Acquia hosting site / environment names | |
+site="$1" | |
+env="$2" | |
+# database role. (Not expected to be needed in most hook scripts.) | |
+db_role="$3" | |
+# The public domain name of the website. | |
+domain="$4" | |
+ | |
+# BLT executable: | |
+blt="/var/www/html/$site.$env/vendor/acquia/blt/bin/blt" | |
+ | |
+deployupdate="$blt artifact:update:drupal:all-sites --define environment=$env --define drush.uri=$domain --verbose --yes" | |
+ | |
+$deployupdate | |
diff --git a/settings/acsf/post-install/post-install.php b/settings/acsf/post-install/post-install.php | |
new file mode 100755 | |
index 000000000..79f9f0427 | |
--- /dev/null | |
+++ b/settings/acsf/post-install/post-install.php | |
@@ -0,0 +1,23 @@ | |
+<?php | |
+ | |
+/** | |
+ * @file | |
+ * Factory Hook: post-install. | |
+ * | |
+ * This hook enables you to execute PHP after a new website is created | |
+ * in your subscription. Unlike most API-based hooks, this hook does not | |
+ * take arguments, but instead executes the PHP code it is provided. | |
+ * | |
+ * This is used so that an ACSF site install will match a local BLT site | |
+ * install. After a local site install, the update functions are run. | |
+ * | |
+ */ | |
+ | |
+$site = $_ENV['AH_SITE_GROUP']; | |
+$env = $_ENV['AH_SITE_ENVIRONMENT']; | |
+ | |
+// The public domain name of the website. | |
+// Run updates against requested domain rather than acsf primary domain. | |
+$domain = $_SERVER['HTTP_HOST']; | |
+ | |
+exec("/mnt/www/html/$target_env/vendor/acquia/blt/bin/blt artifact:update:drupal --define environment=$env --define drush.uri=$domain --verbose --yes"); | |
diff --git a/settings/acsf/post-settings-php/includes.php b/settings/acsf/post-settings-php/includes.php | |
new file mode 100644 | |
index 000000000..fe8a03593 | |
--- /dev/null | |
+++ b/settings/acsf/post-settings-php/includes.php | |
@@ -0,0 +1,12 @@ | |
+<?php | |
+ | |
+/** | |
+ * @file | |
+ * Example implementation of ACSF post-settings-php hook. | |
+ * | |
+ * @see https://docs.acquia.com/site-factory/tiers/paas/workflow/hooks | |
+ */ | |
+ | |
+// Set config directories to default location. | |
+$config_directories['vcs'] = '../config/default'; | |
+$config_directories['sync'] = '../config/default'; | |
diff --git a/settings/acsf/post-theme-deploy/clear-twig-cache.sh b/settings/acsf/post-theme-deploy/clear-twig-cache.sh | |
new file mode 100644 | |
index 000000000..7283a52f3 | |
--- /dev/null | |
+++ b/settings/acsf/post-theme-deploy/clear-twig-cache.sh | |
@@ -0,0 +1,14 @@ | |
+#!/bin/bash | |
+# Clears TWIG cache for a site after a theme deploy. Executes via drush alias. | |
+# See https://docs.acquia.com/site-factory/theme/external#refresh. | |
+# $1 = The hosting site group. | |
+# $2 = The hosting environment. | |
+# $5 = The site domain. | |
+site="$1" | |
+env="$2" | |
+ | |
+# local drush executable: | |
+repo="/var/www/html/$site.$env" | |
+ | |
+cd $repo | |
+drush @$1.$2 --uri=$5 ev '\Drupal\Core\PhpStorage\PhpStorageFactory::get("twig")->deleteAll();' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment