Run amanita to pull in templated files
This commit is contained in:
parent
208a90e7b9
commit
61c93d04db
15 changed files with 533 additions and 9 deletions
34
.cruft.json
Normal file
34
.cruft.json
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
{
|
||||||
|
"template": "git@gitlab.com:agaric/python/amanita.git",
|
||||||
|
"commit": "8244742e86da5516002efbe79542c87b7576ea9b",
|
||||||
|
"skip": [
|
||||||
|
".gitlab-ci.yml",
|
||||||
|
"drush/sites/self.site.yml"
|
||||||
|
],
|
||||||
|
"checkout": null,
|
||||||
|
"context": {
|
||||||
|
"cookiecutter": {
|
||||||
|
"project_name": "experienceolympic-com",
|
||||||
|
"project_slug": "experienceolympic-com",
|
||||||
|
"composer_source": "drutopia",
|
||||||
|
"hostname": "experienceolympic.com",
|
||||||
|
"live_uri": "experienceolympic-live.drutopia.org",
|
||||||
|
"test_uri": "experienceolympic-test.drutopia.org",
|
||||||
|
"user": "experienceolympic",
|
||||||
|
"test_user": "experienceolympic_test",
|
||||||
|
"live_user": "experienceolympic_live",
|
||||||
|
"sitedir": "site",
|
||||||
|
"webdir": "web",
|
||||||
|
"testuser_homedir": "/home/experienceolympic_test",
|
||||||
|
"liveuser_homedir": "/home/experienceolympic_live",
|
||||||
|
"testuser_sitedir": "/home/experienceolympic_test/site",
|
||||||
|
"liveuser_sitedir": "/home/experienceolympic_live/site",
|
||||||
|
"testuser_webdir": "/home/experienceolympic_test/site/web",
|
||||||
|
"liveuser_webdir": "/home/experienceolympic_live/site/web",
|
||||||
|
"theme_name": "theme",
|
||||||
|
"sync_method": "ssh",
|
||||||
|
"_template": "git@gitlab.com:agaric/python/amanita.git"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"directory": "drupal_template"
|
||||||
|
}
|
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -32,3 +32,6 @@ sites/simpletest
|
||||||
|
|
||||||
# Ignore database backup directory.
|
# Ignore database backup directory.
|
||||||
/backups/
|
/backups/
|
||||||
|
|
||||||
|
# Ignore build directory.
|
||||||
|
/build/
|
||||||
|
|
1
drush/README.md
Normal file
1
drush/README.md
Normal file
|
@ -0,0 +1 @@
|
||||||
|
This directory contains commands, configuration and site aliases for Drush. See http://packages.drush.org/ for a directory of Drush commands installable via Composer.
|
29
drush/drush.yml
Normal file
29
drush/drush.yml
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
command:
|
||||||
|
sql:
|
||||||
|
dump:
|
||||||
|
options:
|
||||||
|
# Omit cache and similar tables (including during a sql:sync).
|
||||||
|
structure-tables-key: common
|
||||||
|
# Don't bother pulling migration tables at all.
|
||||||
|
skip-tables-key: common
|
||||||
|
sql:
|
||||||
|
# List of tables whose *data* is skipped by the 'sql-dump' and 'sql-sync'
|
||||||
|
# commands when the "--structure-tables-key=common" option is provided.
|
||||||
|
# You may add specific tables to the existing array or add a new element.
|
||||||
|
structure-tables:
|
||||||
|
common:
|
||||||
|
- cache
|
||||||
|
- 'cache_*'
|
||||||
|
- history
|
||||||
|
- 'search_*'
|
||||||
|
- 'sessions'
|
||||||
|
- 'watchdog'
|
||||||
|
# List of tables to be omitted entirely from SQL dumps made by the 'sql-dump'
|
||||||
|
# and 'sql-sync' commands when the "--skip-tables-key=common" option is
|
||||||
|
# provided on the command line. This is useful if your database contains
|
||||||
|
# non-Drupal tables used by some other application or during a migration for
|
||||||
|
# example. You may add new tables to the existing array or add a new element.
|
||||||
|
skip-tables:
|
||||||
|
common:
|
||||||
|
- 'migration_*'
|
||||||
|
|
18
drush/sites/self.site.yml
Normal file
18
drush/sites/self.site.yml
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
live:
|
||||||
|
host: experienceolympic.com
|
||||||
|
paths:
|
||||||
|
drush-script: /home/experienceolympic_live/site/vendor/bin/drush
|
||||||
|
env-vars:
|
||||||
|
PATH: /home/experienceolympic_live/bin:/usr/bin:/bin
|
||||||
|
root: /home/experienceolympic_live/site/web
|
||||||
|
uri: 'experienceolympic-live.drutopia.org'
|
||||||
|
user: experienceolympic_live
|
||||||
|
test:
|
||||||
|
host: experienceolympic.com
|
||||||
|
paths:
|
||||||
|
drush-script: /home/experienceolympic_test/site/vendor/bin/drush
|
||||||
|
env-vars:
|
||||||
|
PATH: /home/experienceolympic_test/bin:/usr/bin:/bin
|
||||||
|
root: /home/experienceolympic_test/site/web
|
||||||
|
uri: 'experienceolympic-test.drutopia.org'
|
||||||
|
user: experienceolympic_test
|
36
scripts/build.sh
Executable file
36
scripts/build.sh
Executable file
|
@ -0,0 +1,36 @@
|
||||||
|
#!/bin/bash
|
||||||
|
set -euo pipefail
|
||||||
|
# ~SCRIPT~ update.sh
|
||||||
|
# * Pass in a path to drush, or use a default:
|
||||||
|
# * Runs post-deploy commands to update Drupal
|
||||||
|
|
||||||
|
# ~OPTIONAL~
|
||||||
|
# COMPOSER_ARGS:
|
||||||
|
# Composer command and flags to run
|
||||||
|
# Defaults to "install --no-dev --no-scripts --optimize-autoload"
|
||||||
|
|
||||||
|
# Load env vars, if supplied
|
||||||
|
[ $# -eq 1 ] && source "env-${1}"
|
||||||
|
|
||||||
|
# Complain/stop if we don't have needed values
|
||||||
|
[ -z ${BUILD_ROOT:-} ] && { echo ">> Missing ENV var: BUILD_ROOT"; exit 1 ; }
|
||||||
|
|
||||||
|
# Set defaults
|
||||||
|
[ -z ${COMPOSER_ARGS:- } ] && COMPOSER_ARGS="install --no-dev --no-scripts --optimize-autoloader"
|
||||||
|
|
||||||
|
# Build dir has to exist first (if only for a moment)...
|
||||||
|
[ ! -d ${BUILD_ROOT} ] && { mkdir -p ${BUILD_ROOT} || true ; }
|
||||||
|
|
||||||
|
# Normalize paths (e.g. "./build" => "/project/thisone/build)":
|
||||||
|
BUILD_ROOT="$(cd "${BUILD_ROOT}" && pwd)"
|
||||||
|
proj_dir="$(cd $(dirname ${0})/../ && pwd)" # Parent of this script folder.
|
||||||
|
|
||||||
|
# Wipe out the build dir, so long as it is somewhere OTHER than the project root.
|
||||||
|
if [ "${BUILD_ROOT}" != "${proj_dir}" ] ; then
|
||||||
|
# wipe out existing target, and get latest code.
|
||||||
|
rm -rf ${BUILD_ROOT}
|
||||||
|
mkdir ${BUILD_ROOT}
|
||||||
|
git archive HEAD | tar -x -C ${BUILD_ROOT}
|
||||||
|
cd ${BUILD_ROOT}
|
||||||
|
composer ${COMPOSER_ARGS}
|
||||||
|
fi
|
10
scripts/css.sh
Executable file
10
scripts/css.sh
Executable file
|
@ -0,0 +1,10 @@
|
||||||
|
#!/bin/bash
|
||||||
|
set -euo pipefail
|
||||||
|
# Confirmed with echo `pwd` that as long as we use via composer it's always in
|
||||||
|
# /var/www/html (aka the project root).
|
||||||
|
proj_dir="$(cd $(dirname ${0})/../ && pwd)" # Parent of this script folder.
|
||||||
|
[ "$proj_dir" != "/var/www/html" ] && { echo "Script running from unexpected path - are you running within ddev, as you should? Try ddev composer css"; exit 1; }
|
||||||
|
cd /var/www/html/web/themes/custom/theme
|
||||||
|
# Yarn CSS only
|
||||||
|
yarn node-sass -r ./src --output ./dist --include-path node_modules --include-path src --output-style compressed --quiet
|
||||||
|
yarn postcss ./dist/{**,.,*}.css --replace --verbose --env production
|
220
scripts/deploy.sh
Executable file
220
scripts/deploy.sh
Executable file
|
@ -0,0 +1,220 @@
|
||||||
|
#!/bin/bash
|
||||||
|
set -euo pipefail
|
||||||
|
# ~SCRIPT~ deploy.sh
|
||||||
|
# * Copies a build to the specified target and performs updates.
|
||||||
|
# * The build should already be prepared elsewhere.
|
||||||
|
# * Run from project root folder.
|
||||||
|
# * Will create database dumps (using drush)
|
||||||
|
# * By default, runs all related drush commands.
|
||||||
|
|
||||||
|
#######################################
|
||||||
|
# Using deploy.sh
|
||||||
|
#######################################
|
||||||
|
# ~REQUIRED~
|
||||||
|
# SSH_TARGET:
|
||||||
|
# Server to push code to/run drush commands on (host aliases work if configured in $HOME/.ssh/config)
|
||||||
|
# DEPLOY_ENV:
|
||||||
|
# A label for the environment, used to name backup files, and select settings file
|
||||||
|
# Defaults to ${CI_ENVIRONMENT_NAME}, if available, which is automatically set by gitlab-ci
|
||||||
|
# DEPLOY_ROOT:
|
||||||
|
# Directory name for composer file, containing vendor+config sub-folders
|
||||||
|
|
||||||
|
# ~OPTIONAL~
|
||||||
|
# DRUPAL_DIR:
|
||||||
|
# Defaults to web
|
||||||
|
# BACKUP_DIR:
|
||||||
|
# Defaults to ~/backups
|
||||||
|
# BUILD_ROOT:
|
||||||
|
# Defaults to ${PWD}
|
||||||
|
# DRUSH_DISABLE:
|
||||||
|
# Set to "1" to disable ALL drush commands.
|
||||||
|
# May be needed if an install failed or is not already present.
|
||||||
|
# REMOTE_DRUSH:
|
||||||
|
# Defaults to ${DEPLOY_ROOT}/vendor/bin/drush
|
||||||
|
# UPDATE_SCRIPT:
|
||||||
|
# The post-deploy update routine, specified from perspective of the project root.
|
||||||
|
# This should know how to find drush or can use $1 for it (see update.sh).
|
||||||
|
# Defaults to scripts/update.sh
|
||||||
|
# UPDATE_DISABLE:
|
||||||
|
# Set to "1" to disable only update commands (e.g. drush updb)
|
||||||
|
# Note: system will be left in maintenance mode!
|
||||||
|
# drush state:set system.maintenance_mode FALSE
|
||||||
|
# DEBUG:
|
||||||
|
# Set to "1" to call show-vars.sh
|
||||||
|
# WEB_EXCLUDES:
|
||||||
|
# --exclude .well-known --exclude sites/default/files --exclude sites/default/settings.*.php"
|
||||||
|
|
||||||
|
#######################################
|
||||||
|
# Load env vars, if supplied
|
||||||
|
#######################################
|
||||||
|
[ $# -eq 1 ] && source "env-${1}"
|
||||||
|
|
||||||
|
#######################################
|
||||||
|
# DEFAULTS
|
||||||
|
#######################################
|
||||||
|
_backup_dir="~/backups"
|
||||||
|
_config_dir="config" # Folder under deploy root with config
|
||||||
|
_remote_drush="${DEPLOY_ROOT:-}/vendor/bin/drush" # Full remote path to drush used by ssh
|
||||||
|
_update_script="scripts/update.sh"
|
||||||
|
_web_dir="web" # Under deploy root, the Drupal public web directory
|
||||||
|
_web_excludes="--exclude .well-known --exclude sites/default/files --exclude sites/default/settings.*.php"
|
||||||
|
# Note: `_php_settings_dir` cannot be included here; Default directly in optionals block
|
||||||
|
|
||||||
|
#######################################
|
||||||
|
# Check for required variables:
|
||||||
|
#######################################
|
||||||
|
[ -z "${DEPLOY_ENV:-}" ] && DEPLOY_ENV="${CI_ENVIRONMENT_NAME:-}"
|
||||||
|
[ -z "${DEPLOY_ENV:-}" ] && { echo 'Missing ENV var: CI_ENVIRONMENT_NAME/DEPLOY_ENV'; exit 1; }
|
||||||
|
[ -z "${DEPLOY_ROOT:-}" ] && { echo "Missing ENV var: DEPLOY_ROOT"; exit 1; }
|
||||||
|
[ -z "${SSH_TARGET:-}" ] && { echo "Missing ENV var: SSH_TARGET"; exit 1; }
|
||||||
|
|
||||||
|
#######################################
|
||||||
|
# Optional variable setup from defaults:
|
||||||
|
#######################################
|
||||||
|
[ -z "${BACKUP_DIR:-}" ] && BACKUP_DIR="${_backup_dir}"
|
||||||
|
[ -z "${BUILD_ROOT:-}" ] && BUILD_ROOT="./"
|
||||||
|
[ -z "${CONFIG_DIR:-}" ] && CONFIG_DIR="${_config_dir}" # NO trailing slash!
|
||||||
|
[ -z "${DRUPAL_DIR:-}" ] && DRUPAL_DIR="${_web_dir}" # Name of Drupal public sub-folder
|
||||||
|
[ -z "${REMOTE_DRUSH:-}" ] && REMOTE_DRUSH="${_remote_drush}" # Full path to remote drush
|
||||||
|
[ -z "${UPDATE_SCRIPT:-}" ] && UPDATE_SCRIPT="${_update_script}"
|
||||||
|
[ -z "${WEB_EXCLUDES:-}" ] && WEB_EXCLUDES="${_web_excludes}"
|
||||||
|
[ -z "${DRUSH_DISABLE:-}" ] && DRUSH_DISABLE="0"
|
||||||
|
[ -z "${UPDATE_DISABLE:-}" ] && UPDATE_DISABLE="0"
|
||||||
|
[ -z "${PHP_SETTINGS_DIR:-}" ] && PHP_SETTINGS_DIR="${DRUPAL_DIR}/sites/default"
|
||||||
|
|
||||||
|
# Be sure to not overwrite any server-only .user.ini
|
||||||
|
if [ ! -f ${BUILD_ROOT}/${DRUPAL_DIR}/.user.ini ]; then
|
||||||
|
WEB_EXCLUDES="--exclude .user.ini ${WEB_EXCLUDES}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "${DEBUG:-0}" == "1" ]; then
|
||||||
|
#./scripts/show-vars.sh # per-env
|
||||||
|
echo "[DEBUG] IN-USE SETTINGS:"
|
||||||
|
echo "SSH_TARGET=$SSH_TARGET"
|
||||||
|
echo "DEPLOY_ENV=${DEPLOY_ENV}"
|
||||||
|
echo "DEPLOY_ROOT=${DEPLOY_ROOT}"
|
||||||
|
echo "BUILD_ROOT=${BUILD_ROOT}"
|
||||||
|
echo "CONFIG_DIR=${CONFIG_DIR}"
|
||||||
|
echo "DRUPAL_DIR=${DRUPAL_DIR}"
|
||||||
|
echo "REMOTE_DRUSH=${REMOTE_DRUSH}"
|
||||||
|
echo "BACKUP_DIR=${BACKUP_DIR}"
|
||||||
|
echo "DRUSH_DISABLE=${DRUSH_DISABLE}"
|
||||||
|
echo "UPDATE_SCRIPT=${UPDATE_SCRIPT}"
|
||||||
|
echo "UPDATE_DISABLE=${UPDATE_DISABLE}"
|
||||||
|
echo "WEB_EXCLUDES=${WEB_EXCLUDES}"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
#######################################
|
||||||
|
# Functions
|
||||||
|
#######################################
|
||||||
|
function drush_enabled() {
|
||||||
|
if [ "${DRUSH_DISABLE}" == "1" ]
|
||||||
|
then
|
||||||
|
return 1 #1 is false (so, disabled)
|
||||||
|
else
|
||||||
|
return 0 #0 is true (enabled) because...bash
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
#######################################
|
||||||
|
# Check drush/site status
|
||||||
|
#######################################
|
||||||
|
echo "Starting deployment to ${DEPLOY_ENV}"
|
||||||
|
drush_enabled || echo "Note: Drush commands are disabled. Commands marked [D] will not execute."
|
||||||
|
echo "Verify connectivity (print user & working directory)"
|
||||||
|
ssh ${SSH_TARGET} "whoami; pwd"
|
||||||
|
echo "[D] Verify drush functionality (cr, status bootstrap)"
|
||||||
|
drush_enabled && ssh ${SSH_TARGET} "${REMOTE_DRUSH} cr"
|
||||||
|
# Expected good result: "Drupal bootstrap : Successful", otherwise empty (but drush returns 0)
|
||||||
|
ssh_cmd="${REMOTE_DRUSH} status --fields=bootstrap"
|
||||||
|
drush_enabled && { [[ $(ssh ${SSH_TARGET} "${ssh_cmd}") = *Successful* ]] || { echo ">> Drush failed bootstrap!"; exit 1; } ; }
|
||||||
|
|
||||||
|
#######################################
|
||||||
|
# Enable maintenance mode
|
||||||
|
#######################################
|
||||||
|
# echo "[D] Set maintenance mode ON"
|
||||||
|
# drush_enabled && ssh ${SSH_TARGET} "${REMOTE_DRUSH} state:set system.maintenance_mode TRUE"
|
||||||
|
|
||||||
|
#######################################
|
||||||
|
# Perform a database backup
|
||||||
|
#######################################
|
||||||
|
backup_file="${DEPLOY_ENV}_$(date +%Y%m%dT%H%M%S).sql.gz"
|
||||||
|
ssh_cmd="[ ! -d ${BACKUP_DIR} ] && mkdir -p ${BACKUP_DIR} || true"
|
||||||
|
echo "Using backup dir '${BACKUP_DIR}' (created as needed)"
|
||||||
|
ssh "${SSH_TARGET}" "$ssh_cmd"
|
||||||
|
ssh_cmd="${REMOTE_DRUSH} sql-dump | gzip > ${BACKUP_DIR}/$backup_file"
|
||||||
|
echo "[D] Creating backup file ${backup_file}"
|
||||||
|
drush_enabled && ssh "${SSH_TARGET}" "${ssh_cmd}"
|
||||||
|
|
||||||
|
#######################################
|
||||||
|
# DEPLOY CODE:
|
||||||
|
#######################################
|
||||||
|
# Check for sub-dirs...
|
||||||
|
ssh_cmd="[ ! -d ${DEPLOY_ROOT}/${CONFIG_DIR} ] && mkdir -p ${DEPLOY_ROOT}/${CONFIG_DIR} || true"
|
||||||
|
echo "Ensure '${CONFIG_DIR}' exists"
|
||||||
|
ssh "${SSH_TARGET}" "$ssh_cmd"
|
||||||
|
ssh_cmd="[ ! -d ${DEPLOY_ROOT}/${DRUPAL_DIR}/sites/default ] && mkdir -p ${DEPLOY_ROOT}/${DRUPAL_DIR}/sites/default || true"
|
||||||
|
echo "Ensure '${DRUPAL_DIR}/sites/default exists'"
|
||||||
|
ssh "${SSH_TARGET}" "$ssh_cmd"
|
||||||
|
|
||||||
|
# Disable write protect...
|
||||||
|
echo "Disabling write protection on settings folder and files."
|
||||||
|
ssh_cmd="chmod ug+w ${DEPLOY_ROOT}/${DRUPAL_DIR}/sites/default/"
|
||||||
|
ssh ${SSH_TARGET} ${ssh_cmd}
|
||||||
|
ssh_cmd="find ${DEPLOY_ROOT}/${DRUPAL_DIR}/sites/default/ -maxdepth 1 -type f -name 'settings*php' -exec chmod ug+w '{}' \;"
|
||||||
|
ssh ${SSH_TARGET} ${ssh_cmd}
|
||||||
|
# Rsync's
|
||||||
|
printf "Pushing latest codebase: config…"
|
||||||
|
rsync -rz --delete ${BUILD_ROOT}/${CONFIG_DIR}/ ${SSH_TARGET}:${DEPLOY_ROOT}/config
|
||||||
|
printf "\b ✓, ${DRUPAL_DIR}…"
|
||||||
|
rsync -rz --delete ${WEB_EXCLUDES} ${BUILD_ROOT}/${DRUPAL_DIR}/ ${SSH_TARGET}:${DEPLOY_ROOT}/${DRUPAL_DIR}
|
||||||
|
printf "\b ✓, vendor…"
|
||||||
|
rsync -rz --delete --links ${BUILD_ROOT}/vendor ${SSH_TARGET}:${DEPLOY_ROOT}/
|
||||||
|
printf "\b ✓, scripts…"
|
||||||
|
[ -d ./scripts ] && rsync -rz --delete ${BUILD_ROOT}/scripts ${SSH_TARGET}:${DEPLOY_ROOT}/
|
||||||
|
printf "\b ✓, composer…"
|
||||||
|
scp -q composer.json ${SSH_TARGET}:${DEPLOY_ROOT}/composer.json
|
||||||
|
printf "\b ✓, settings…"
|
||||||
|
scp -q ${BUILD_ROOT}/${PHP_SETTINGS_DIR}/settings.${DEPLOY_ENV}.php ${SSH_TARGET}:${DEPLOY_ROOT}/${DRUPAL_DIR}/sites/default/settings.local.php
|
||||||
|
printf "\b ✓\nFile sync complete!\n"
|
||||||
|
# Re-protect settings
|
||||||
|
echo "Enabling write protection on settings folder and files."
|
||||||
|
ssh_cmd="[ -d ${DEPLOY_ROOT}/${DRUPAL_DIR}/sites/default ] && chmod ug-w ${DEPLOY_ROOT}/${DRUPAL_DIR}/sites/default/"
|
||||||
|
ssh ${SSH_TARGET} ${ssh_cmd}
|
||||||
|
ssh_cmd="find ${DEPLOY_ROOT}/${DRUPAL_DIR}/sites/default/ -maxdepth 1 -type f -name 'settings*php' -exec chmod ug-w '{}' \;"
|
||||||
|
ssh ${SSH_TARGET} ${ssh_cmd}
|
||||||
|
|
||||||
|
#######################################
|
||||||
|
# [P|re]load database
|
||||||
|
#######################################
|
||||||
|
if [ ! -z "${PRELOAD_DB_FILE:-}" -a "${DEPLOY_ENV}" != "live" -a "${DEPLOY_ENV}" != "prod" ]; then
|
||||||
|
ssh_cmd="${REMOTE_DRUSH} sql-drop -y"
|
||||||
|
echo "[D] Dropping existing database"
|
||||||
|
drush_enabled && ssh "${SSH_TARGET}" "${ssh_cmd}"
|
||||||
|
if drush_enabled; then
|
||||||
|
ssh_cmd="${REMOTE_DRUSH} sqlc < ${PRELOAD_DB_FILE}"
|
||||||
|
echo "[D] Loading database from ${PRELOAD_DB_FILE}"
|
||||||
|
ssh "${SSH_TARGET}" "${ssh_cmd}"
|
||||||
|
else
|
||||||
|
echo "Fallback: Load database file using mysql (requires .my.cnf)"
|
||||||
|
ssh_cmd="mysql < ${PRELOAD_DB_FILE}"
|
||||||
|
echo "Loading database from ${PRELOAD_DB_FILE}"
|
||||||
|
ssh "${SSH_TARGET}" "${ssh_cmd}"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
#######################################
|
||||||
|
# RUN DRUPAL TASKS (via UPDATE_SCRIPT):
|
||||||
|
#######################################
|
||||||
|
if drush_enabled && [ "${UPDATE_DISABLE}" == "0" -a -f "${BUILD_ROOT}/${UPDATE_SCRIPT}" ]; then
|
||||||
|
echo ">> Calling ${UPDATE_SCRIPT} to perform updates..."
|
||||||
|
ssh ${SSH_TARGET} "${DEPLOY_ROOT}/${UPDATE_SCRIPT} ${REMOTE_DRUSH}"
|
||||||
|
# echo ">> [D] Set maintenance mode OFF"
|
||||||
|
# ssh ${SSH_TARGET} ${REMOTE_DRUSH} state:set system.maintenance_mode FALSE
|
||||||
|
else
|
||||||
|
echo ">> [D] Skipping follow-up drush (cr, updb, cim, etc)."
|
||||||
|
# echo ">> Maintenence mode on. To disable: ${drush} state:set system.maintenance_mode FALSE"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Deployment to ${DEPLOY_ENV} completed!"
|
12
scripts/example.template
Normal file
12
scripts/example.template
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
<?php
|
||||||
|
$databases['default']['default'] = array(
|
||||||
|
'database' => "${DB_NAME}",
|
||||||
|
'username' => "${DB_USER}",
|
||||||
|
'password' => "${DB_PASSWORD}",
|
||||||
|
'host' => "127.0.0.1",
|
||||||
|
'driver' => "mysql",
|
||||||
|
'port' => 3306,
|
||||||
|
'prefix' => "",
|
||||||
|
);
|
||||||
|
$settings['hash_salt'] = '${SALT}';
|
||||||
|
$settings['trusted_host_patterns'] = [${TRUSTED_HOSTS}];
|
36
scripts/nuke.sh
Executable file
36
scripts/nuke.sh
Executable file
|
@ -0,0 +1,36 @@
|
||||||
|
# Delete Drupal core and any contrib directories.
|
||||||
|
rm -rf web/core
|
||||||
|
rm -rf web/modules/contrib
|
||||||
|
rm -rf web/themes/contrib
|
||||||
|
rm -rf web/profiles/contrib
|
||||||
|
rm -rf drush/Commands/contrib
|
||||||
|
|
||||||
|
# Delete Drupal root files.
|
||||||
|
rm -f web/.csslintrc
|
||||||
|
rm -f web/.editorconfig
|
||||||
|
rm -f web/.eslintignore
|
||||||
|
rm -f web/.eslintrc.json
|
||||||
|
rm -f web/.gitattributes
|
||||||
|
rm -f web/.gitignore
|
||||||
|
rm -f web/.ht.router.php
|
||||||
|
rm -f web/autoload.php
|
||||||
|
rm -f web/example.gitignore
|
||||||
|
rm -f web/index.php
|
||||||
|
rm -f web/INSTALL.txt
|
||||||
|
rm -f web/robots.txt
|
||||||
|
rm -f web/README.txt
|
||||||
|
rm -f web/update.php
|
||||||
|
rm -f web/web.config
|
||||||
|
|
||||||
|
# Delete any Drupal scaffold files.
|
||||||
|
rm -f .editorconfig
|
||||||
|
rm -f .gitattributes
|
||||||
|
|
||||||
|
# Delete any third party libraries.
|
||||||
|
# rm -rf web/libraries
|
||||||
|
|
||||||
|
# Delete the vendor directory.
|
||||||
|
rm -rf vendor
|
||||||
|
|
||||||
|
# Delete any build folders.
|
||||||
|
rm -rf build
|
|
@ -1,17 +1,23 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -e
|
set -euo pipefail
|
||||||
|
# ~SCRIPT~ update.sh
|
||||||
|
# * Pass in a path to drush, or use a default:
|
||||||
|
# * Runs post-deploy commands to update Drupal
|
||||||
|
|
||||||
# Confirmed with echo `pwd` that as long as we use via composer it's always in
|
# Confirmed with echo `pwd` that as long as we use via composer it's always in
|
||||||
# /var/www/html (aka the project root).
|
# /var/www/html (aka the project root).
|
||||||
proj_dir="$(cd $(dirname ${0})/../ && pwd)" # Parent of this script folder.
|
proj_dir="$(cd $(dirname ${0})/../ && pwd)" # Parent of this script folder.
|
||||||
[ "$proj_dir" != "/var/www/html" ] && { echo "Script running from unexpected path - are you running within ddev, as you should?"; exit 1; }
|
[ "$proj_dir" != "/var/www/html" ] && { echo "Script running from unexpected path - are you running within ddev, as you should?"; exit 1; }
|
||||||
backup_file="$(date +%Y%m%dT%H%M%S)_pre_pull.sql"
|
backup_file="$(date +%Y%m%dT%H%M%S)_pre_pull.sql.gz"
|
||||||
[ ! -d /var/www/html/backups ] && mkdir /var/www/html/backups || true
|
[ ! -d /var/www/html/backups ] && mkdir /var/www/html/backups || true
|
||||||
echo "Backing up current db to backups/${backup_file}..."
|
echo ">> Backing up current db to backups/${backup_file}..."
|
||||||
drush sql-dump > /var/www/html/backups/${backup_file}
|
drush sql-dump --gzip > /var/www/html/backups/${backup_file}
|
||||||
echo "Dropping local db..."
|
echo ">> Dropping local db..."
|
||||||
drush -y sql-drop
|
drush -y sql-drop
|
||||||
echo "Pulling db from live into local..."
|
echo ">> Pulling db from live into local..."
|
||||||
drush -y sql-sync @live @self
|
drush -y sql-sync --structure-tables-key=common @live @self
|
||||||
echo "Pulling files from live into local..."
|
echo ">> Pulling files from live into local..."
|
||||||
drush -y rsync @live:%files @self:%files
|
drush -y rsync --exclude-paths=css:js:php @live:%files @self:%files
|
||||||
|
echo ">> Local cache reload..."
|
||||||
|
drush cr
|
||||||
echo "Done"
|
echo "Done"
|
||||||
|
|
14
scripts/show-vars.sh
Executable file
14
scripts/show-vars.sh
Executable file
|
@ -0,0 +1,14 @@
|
||||||
|
#!/bin/sh
|
||||||
|
echo "[DEBUG] ENV SETTINGS (Required):"
|
||||||
|
echo "SSH_TARGET=$SSH_TARGET"
|
||||||
|
echo "DEPLOY_ENV=${DEPLOY_ENV}"
|
||||||
|
echo "CI_ENVIRONMENT_NAME=$CI_ENVIRONMENT_NAME"
|
||||||
|
echo "DEPLOY_ROOT=${DEPLOY_ROOT}"
|
||||||
|
echo "[DEBUG] ENV SETTINGS (Optional):"
|
||||||
|
echo "DRUPAL_ROOT=${DRUPAL_ROOT}"
|
||||||
|
echo "BACKUP_ROOT=${BACKUP_ROOT}"
|
||||||
|
echo "BUILD_ROOT=${BUILD_ROOT}"
|
||||||
|
echo "DRUSH_DISABLE=${DRUSH_DISABLE}"
|
||||||
|
echo "UPDATE_SCRIPT=${UPDATE_SCRIPT}"
|
||||||
|
echo "UPDATE_DISABLE=${UPDATE_DISABLE}"
|
||||||
|
echo "DEBUG=${DEBUG}"
|
57
scripts/sync_to_test.sh
Executable file
57
scripts/sync_to_test.sh
Executable file
|
@ -0,0 +1,57 @@
|
||||||
|
#!/bin/bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
source_site_root="/home/experienceolympic_live/site/web"
|
||||||
|
source_drush="/home/experienceolympic_live/site/vendor/bin/drush -r ${source_site_root}"
|
||||||
|
source_files="${source_site_root}/sites/default/files/"
|
||||||
|
|
||||||
|
# Requires an .ssh/config entry for test-site. May be to localhost, and must not require a password for private key.
|
||||||
|
target_site=test-site
|
||||||
|
target_site_root="/home/experienceolympic_test/site/web"
|
||||||
|
target_drush="/home/experienceolympic_test/site/vendor/bin/drush -r ${target_site_root}"
|
||||||
|
target_files="${target_site_root}/sites/default/files/"
|
||||||
|
# Use ssh to target when target_site is set, otherwise use eval to just run in the local context
|
||||||
|
target_cmd="${target_site:+ssh ${target_site}}"
|
||||||
|
target_cmd="${target_cmd:-eval}"
|
||||||
|
|
||||||
|
sync_date=$(date +%Y%m%d_%H%M%S%Z)
|
||||||
|
|
||||||
|
# Test local drush/file paths/ssh connection/remote drush
|
||||||
|
[ -d ${source_files} ] || (echo "source_files folder does not exist"; exit 1)
|
||||||
|
${source_drush} status > /dev/null || (echo "Cannot execute local drush"; exit 1)
|
||||||
|
target_cmd "[ -d ${target_files} ]" || (echo "${target_cmd} failed, or ${target_files} folder does not exist at target. If using ssh, have you set up the key?"; exit 1)
|
||||||
|
target_cmd "${target_drush} status > /dev/null" || (echo "${target_cmd} ${target_drush} failed - does the site exist"; exit 1)
|
||||||
|
|
||||||
|
echo ">> All checks succeeded!"
|
||||||
|
echo ">> Syncing this site to ${target_site:-${target_site_root}} (using file date: ${sync_date})..."
|
||||||
|
|
||||||
|
# Dump destination DB (extra backup)
|
||||||
|
echo ">> Dumping destination database..."
|
||||||
|
target_cmd "${target_drush} sql-dump | gzip > ~/backups/${sync_date}-paranoia.sql.gz"
|
||||||
|
echo ">> Dumping source database..."
|
||||||
|
${source_drush} sql-dump | gzip > ~/backups/${sync_date}-sync.sql.gz
|
||||||
|
|
||||||
|
|
||||||
|
# Send copy
|
||||||
|
echo ">> Copying source db to target..."
|
||||||
|
'scp' ~/backups/${sync_date}-sync.sql.gz ${target_site}:backups/
|
||||||
|
|
||||||
|
|
||||||
|
# Drop DB and reload from source
|
||||||
|
echo ">> Reloading target database..."
|
||||||
|
target_cmd "${target_drush} sql-drop -y"
|
||||||
|
|
||||||
|
target_cmd "gunzip ~/backups/${sync_date}-sync.sql.gz"
|
||||||
|
target_cmd "${target_drush} sqlc < ~/backups/${sync_date}-sync.sql"
|
||||||
|
|
||||||
|
|
||||||
|
# Copy files
|
||||||
|
echo ">> Sending new files..."
|
||||||
|
rsync -rlptvz --exclude=php --exclude=js --exclude=css --exclude=styles --exclude=twig ${source_files} ${target_site:+${target_site}:}${target_files}
|
||||||
|
|
||||||
|
echo ">> Sync to ${target_site:-${target_site_root}} complete - running cache rebuild..."
|
||||||
|
|
||||||
|
# CR forever!
|
||||||
|
target_cmd "${target_drush} cr"
|
||||||
|
|
||||||
|
echo ">> Target ${target_site:-${target_site_root}} is ready!"
|
22
scripts/update-hook.sh
Executable file
22
scripts/update-hook.sh
Executable file
|
@ -0,0 +1,22 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
# ~SCRIPT~ update-hook.sh
|
||||||
|
# * Pass in a path to drush, or use a default:
|
||||||
|
# * Runs drush deploy command to update Drupal
|
||||||
|
|
||||||
|
# https://stackoverflow.com/questions/59895/how-do-i-get-the-directory-where-a-bash-script-is-located-from-within-the-script
|
||||||
|
DIR="$( dirname -- "${BASH_SOURCE[0]}"; )"; # Get the directory name
|
||||||
|
SCRIPT_DIR="$( realpath -e -- "$DIR"; )"; # Resolve its full path if need be
|
||||||
|
|
||||||
|
drush=${*-${SCRIPT_DIR}/../vendor/bin/drush}
|
||||||
|
echo "Using drush=${drush}"
|
||||||
|
|
||||||
|
_oldpath=$PATH
|
||||||
|
export PATH=$HOME/bin:/usr/local/bin:/usr/bin:/bin
|
||||||
|
|
||||||
|
echo ">> [D] Running drush cache:rebuild"
|
||||||
|
${drush} cache:rebuild
|
||||||
|
echo ">> [D] Running drush deploy"
|
||||||
|
${drush} deploy -y
|
||||||
|
export PATH=$_oldpath
|
||||||
|
exit 0
|
26
scripts/update.sh
Executable file
26
scripts/update.sh
Executable file
|
@ -0,0 +1,26 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
# ~SCRIPT~ update.sh
|
||||||
|
# * Pass in a path to drush, or use a default:
|
||||||
|
# * Runs post-deploy commands to update Drupal
|
||||||
|
|
||||||
|
# https://stackoverflow.com/questions/59895/how-do-i-get-the-directory-where-a-bash-script-is-located-from-within-the-script
|
||||||
|
DIR="$( dirname -- "${BASH_SOURCE[0]}"; )"; # Get the directory name
|
||||||
|
SCRIPT_DIR="$( realpath -e -- "$DIR"; )"; # Resolve its full path if need be
|
||||||
|
|
||||||
|
drush=${*-${SCRIPT_DIR}/../vendor/bin/drush}
|
||||||
|
echo "Using drush=${drush}"
|
||||||
|
|
||||||
|
_oldpath=$PATH
|
||||||
|
export PATH=$HOME/bin:/usr/local/bin:/usr/bin:/bin
|
||||||
|
|
||||||
|
echo ">> [D] Running drush cr"
|
||||||
|
${drush} cr
|
||||||
|
echo ">> [D] Running drush updb -y"
|
||||||
|
${drush} updb -y
|
||||||
|
echo ">> [D] Running drush cim"
|
||||||
|
${drush} cim -y
|
||||||
|
echo ">> [D] Running drush cr (again)"
|
||||||
|
${drush} cr
|
||||||
|
export PATH=$_oldpath
|
||||||
|
exit 0
|
Loading…
Reference in a new issue