Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .vortex/docs/content/hosting/acquia.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,31 @@ or CI builds:
```shell
ahoy download-db
```

### Run a hosting task

Copying databases or files between environments and purging the edge cache run
through a single, platform-agnostic task runner that dispatches each operation
to the implementation for the configured hosting platform:

```shell
./vendor/drevops/vortex-tooling/src/task <operation>
```

| Operation | Description |
|---------------|----------------------------------------|
| `copy-db` | Copy the database between environments |
| `copy-files` | Copy files between environments |
| `purge-cache` | Purge the edge (Varnish) cache |

The platform is read from `VORTEX_PLATFORM`, or from `VORTEX_TASK_PLATFORM` to
override a single task. The Acquia deployment hooks export `VORTEX_PLATFORM`
themselves; set it yourself when running an operation manually - for example,
from your local machine:

```shell
VORTEX_PLATFORM=acquia ./vendor/drevops/vortex-tooling/src/task copy-db
```

Each operation reads its configuration - application name, API credentials, and
source and destination environments - from your `.env` and `.env.local` files.
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ pushd "/var/www/html/${site}.${target_env}" >/dev/null || exit 1

[ "${VORTEX_TASK_COPY_DB_ACQUIA_SKIP}" = "1" ] && echo "Skipping copying of database between Acquia environments." && exit 0

export VORTEX_PLATFORM=acquia
export VORTEX_ACQUIA_KEY="${VORTEX_ACQUIA_KEY?not set}"
export VORTEX_ACQUIA_SECRET="${VORTEX_ACQUIA_SECRET?not set}"
export VORTEX_ACQUIA_APP_NAME="${VORTEX_ACQUIA_APP_NAME:-${site}}"
export VORTEX_TASK_COPY_DB_ACQUIA_SRC="${VORTEX_TASK_COPY_DB_ACQUIA_SRC:-prod}"
export VORTEX_TASK_COPY_DB_ACQUIA_DST="${VORTEX_TASK_COPY_DB_ACQUIA_DST:-${target_env}}"
export VORTEX_TASK_COPY_DB_ACQUIA_NAME="${VORTEX_TASK_COPY_DB_ACQUIA_NAME?not set}"

./vendor/drevops/vortex-tooling/src/task-copy-db-acquia
./vendor/drevops/vortex-tooling/src/task copy-db

popd >/dev/null || exit 1
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ pushd "/var/www/html/${site}.${target_env}" >/dev/null || exit 1

[ "${VORTEX_TASK_COPY_FILES_ACQUIA_SKIP}" = "1" ] && echo "Skipping copying of files between Acquia environments." && exit 0

export VORTEX_PLATFORM=acquia
export VORTEX_ACQUIA_KEY="${VORTEX_ACQUIA_KEY?not set}"
export VORTEX_ACQUIA_SECRET="${VORTEX_ACQUIA_SECRET?not set}"
export VORTEX_ACQUIA_APP_NAME="${VORTEX_ACQUIA_APP_NAME:-${site}}"
export VORTEX_TASK_COPY_FILES_ACQUIA_SRC="${VORTEX_TASK_COPY_FILES_ACQUIA_SRC:-prod}"
export VORTEX_TASK_COPY_FILES_ACQUIA_DST="${VORTEX_TASK_COPY_FILES_ACQUIA_DST:-${target_env}}"

./vendor/drevops/vortex-tooling/src/task-copy-files-acquia
./vendor/drevops/vortex-tooling/src/task copy-files

popd >/dev/null || exit 1
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env bash
#!/usr/bin/env bash
##
# Acquia Cloud hook: Purge edge cache in an environment.
#
Expand All @@ -15,12 +14,13 @@ pushd "/var/www/html/${site}.${target_env}" >/dev/null || exit 1

[ "${VORTEX_PURGE_CACHE_ACQUIA_SKIP}" = "1" ] && echo "Skipping purging of cache in Acquia environment." && exit 0

export VORTEX_PLATFORM=acquia
export VORTEX_ACQUIA_KEY="${VORTEX_ACQUIA_KEY?not set}"
export VORTEX_ACQUIA_SECRET="${VORTEX_ACQUIA_SECRET?not set}"
export VORTEX_ACQUIA_APP_NAME="${VORTEX_ACQUIA_APP_NAME:-${site}}"
export VORTEX_TASK_PURGE_CACHE_ACQUIA_ENV="${VORTEX_TASK_PURGE_CACHE_ACQUIA_ENV:-${target_env}}"
export VORTEX_TASK_PURGE_CACHE_ACQUIA_DOMAINS_FILE="${VORTEX_TASK_PURGE_CACHE_ACQUIA_DOMAINS_FILE:-"/var/www/html/${site}.${target_env}/hooks/library/domains.txt"}"

./vendor/drevops/vortex-tooling/src/task-purge-cache-acquia
./vendor/drevops/vortex-tooling/src/task purge-cache

popd >/dev/null || exit 1
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ pushd "/var/www/html/${site}.${target_env}" >/dev/null || exit 1

[ "${VORTEX_TASK_COPY_DB_ACQUIA_SKIP}" = "1" ] && echo "Skipping copying of database between Acquia environments." && exit 0

export VORTEX_PLATFORM=acquia
export VORTEX_ACQUIA_KEY="${VORTEX_ACQUIA_KEY?not set}"
export VORTEX_ACQUIA_SECRET="${VORTEX_ACQUIA_SECRET?not set}"
export VORTEX_ACQUIA_APP_NAME="${VORTEX_ACQUIA_APP_NAME:-${site}}"
export VORTEX_TASK_COPY_DB_ACQUIA_SRC="${VORTEX_TASK_COPY_DB_ACQUIA_SRC:-prod}"
export VORTEX_TASK_COPY_DB_ACQUIA_DST="${VORTEX_TASK_COPY_DB_ACQUIA_DST:-${target_env}}"
export VORTEX_TASK_COPY_DB_ACQUIA_NAME="${VORTEX_TASK_COPY_DB_ACQUIA_NAME?not set}"

./vendor/drevops/vortex-tooling/src/task-copy-db-acquia
./vendor/drevops/vortex-tooling/src/task copy-db

popd >/dev/null || exit 1
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ pushd "/var/www/html/${site}.${target_env}" >/dev/null || exit 1

[ "${VORTEX_TASK_COPY_FILES_ACQUIA_SKIP}" = "1" ] && echo "Skipping copying of files between Acquia environments." && exit 0

export VORTEX_PLATFORM=acquia
export VORTEX_ACQUIA_KEY="${VORTEX_ACQUIA_KEY?not set}"
export VORTEX_ACQUIA_SECRET="${VORTEX_ACQUIA_SECRET?not set}"
export VORTEX_ACQUIA_APP_NAME="${VORTEX_ACQUIA_APP_NAME:-${site}}"
export VORTEX_TASK_COPY_FILES_ACQUIA_SRC="${VORTEX_TASK_COPY_FILES_ACQUIA_SRC:-prod}"
export VORTEX_TASK_COPY_FILES_ACQUIA_DST="${VORTEX_TASK_COPY_FILES_ACQUIA_DST:-${target_env}}"

./vendor/drevops/vortex-tooling/src/task-copy-files-acquia
./vendor/drevops/vortex-tooling/src/task copy-files

popd >/dev/null || exit 1
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env bash
#!/usr/bin/env bash
##
# Acquia Cloud hook: Purge edge cache in an environment.
#
Expand All @@ -15,12 +14,13 @@ pushd "/var/www/html/${site}.${target_env}" >/dev/null || exit 1

[ "${VORTEX_PURGE_CACHE_ACQUIA_SKIP}" = "1" ] && echo "Skipping purging of cache in Acquia environment." && exit 0

export VORTEX_PLATFORM=acquia
export VORTEX_ACQUIA_KEY="${VORTEX_ACQUIA_KEY?not set}"
export VORTEX_ACQUIA_SECRET="${VORTEX_ACQUIA_SECRET?not set}"
export VORTEX_ACQUIA_APP_NAME="${VORTEX_ACQUIA_APP_NAME:-${site}}"
export VORTEX_TASK_PURGE_CACHE_ACQUIA_ENV="${VORTEX_TASK_PURGE_CACHE_ACQUIA_ENV:-${target_env}}"
export VORTEX_TASK_PURGE_CACHE_ACQUIA_DOMAINS_FILE="${VORTEX_TASK_PURGE_CACHE_ACQUIA_DOMAINS_FILE:-"/var/www/html/${site}.${target_env}/hooks/library/domains.txt"}"

./vendor/drevops/vortex-tooling/src/task-purge-cache-acquia
./vendor/drevops/vortex-tooling/src/task purge-cache

popd >/dev/null || exit 1
42 changes: 42 additions & 0 deletions .vortex/tooling/src/task
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env bash
##
# Run a hosting task.
#
# This is a router script that dispatches a platform-agnostic operation to the
# implementation for the configured hosting platform: 'task <operation> [args...]'
# runs the 'task-<operation>-<platform>' sibling script.
#
# The platform is read from VORTEX_TASK_PLATFORM, falling back to VORTEX_PLATFORM.
#
# shellcheck disable=SC1090,SC1091

set -eu
[ "${VORTEX_DEBUG-}" = "1" ] && set -x

# Hosting platform to run the operation for.
VORTEX_TASK_PLATFORM="${VORTEX_TASK_PLATFORM:-${VORTEX_PLATFORM:-}}"

# @formatter:off
fail() { [ "${TERM:-}" != "dumb" ] && tput colors >/dev/null 2>&1 && printf "\033[31m[FAIL] %s\033[0m\n" "${1}" || printf "[FAIL] %s\n" "${1}"; }
# @formatter:on

operation="${1:-}"
[ -z "${operation}" ] && fail "Missing task operation." && exit 1
shift

case "${operation}" in
copy-db | copy-files | purge-cache) ;;
*) fail "Unsupported task operation '${operation}'." && exit 1 ;;
esac

[ -z "${VORTEX_TASK_PLATFORM}" ] && fail "Missing hosting platform. Set VORTEX_PLATFORM or VORTEX_TASK_PLATFORM." && exit 1

case "${VORTEX_TASK_PLATFORM}" in
acquia | lagoon) ;;
*) fail "Unsupported hosting platform '${VORTEX_TASK_PLATFORM}'." && exit 1 ;;
esac

task_script="$(dirname "${BASH_SOURCE[0]}")/task-${operation}-${VORTEX_TASK_PLATFORM}"
[ ! -x "${task_script}" ] && fail "Operation '${operation}' is not supported on the '${VORTEX_TASK_PLATFORM}' platform." && exit 1

"${task_script}" "$@"
118 changes: 118 additions & 0 deletions .vortex/tooling/tests/unit/task.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
#!/usr/bin/env bats
##
# Unit tests for the task router.
#
# The router resolves a platform-agnostic operation to the
# 'task-<operation>-<platform>' sibling that implements it; these tests cover
# operation validation, platform resolution, and dispatch. The
# operation-specific logic is owned by the sibling scripts.
#
#shellcheck disable=SC2030,SC2031,SC2034

load ../_helper.bash

@test "Task: missing operation" {
pushd "${LOCAL_REPO_DIR}" >/dev/null || exit 1

run ./.vortex/tooling/src/task
assert_failure
assert_output_contains "Missing task operation."

popd >/dev/null || exit 1
}

@test "Task: unsupported operation" {
pushd "${LOCAL_REPO_DIR}" >/dev/null || exit 1

run ./.vortex/tooling/src/task invalid-operation
assert_failure
assert_output_contains "Unsupported task operation 'invalid-operation'."

popd >/dev/null || exit 1
}

@test "Task: missing platform" {
pushd "${LOCAL_REPO_DIR}" >/dev/null || exit 1

unset VORTEX_TASK_PLATFORM
unset VORTEX_PLATFORM
run ./.vortex/tooling/src/task copy-db
assert_failure
assert_output_contains "Missing hosting platform. Set VORTEX_PLATFORM or VORTEX_TASK_PLATFORM."

popd >/dev/null || exit 1
}

@test "Task: unsupported platform" {
pushd "${LOCAL_REPO_DIR}" >/dev/null || exit 1

unset VORTEX_TASK_PLATFORM
export VORTEX_PLATFORM=invalid-platform
run ./.vortex/tooling/src/task copy-db
assert_failure
assert_output_contains "Unsupported hosting platform 'invalid-platform'."

popd >/dev/null || exit 1
}

@test "Task: operation not supported on platform" {
pushd "${LOCAL_REPO_DIR}" >/dev/null || exit 1

# Lagoon has no copy-db implementation, so the sibling resolution fails.
unset VORTEX_TASK_PLATFORM
export VORTEX_PLATFORM=lagoon
run ./.vortex/tooling/src/task copy-db
assert_failure
assert_output_contains "Operation 'copy-db' is not supported on the 'lagoon' platform."

popd >/dev/null || exit 1
}

@test "Task: platform from VORTEX_PLATFORM dispatches copy-db" {
pushd "${LOCAL_REPO_DIR}" >/dev/null || exit 1

# Without credentials the sibling prints its banner and then fails on the
# missing-key guard before any network call, which proves the routing.
unset VORTEX_TASK_PLATFORM
export VORTEX_PLATFORM=acquia
run ./.vortex/tooling/src/task copy-db
assert_failure
assert_output_contains "Started database copying between environments in Acquia."

popd >/dev/null || exit 1
}

@test "Task: VORTEX_TASK_PLATFORM overrides VORTEX_PLATFORM" {
pushd "${LOCAL_REPO_DIR}" >/dev/null || exit 1

export VORTEX_PLATFORM=lagoon
export VORTEX_TASK_PLATFORM=acquia
run ./.vortex/tooling/src/task copy-db
assert_failure
assert_output_contains "Started database copying between environments in Acquia."

popd >/dev/null || exit 1
}

@test "Task: platform override dispatches copy-files" {
pushd "${LOCAL_REPO_DIR}" >/dev/null || exit 1

export VORTEX_TASK_PLATFORM=acquia
run ./.vortex/tooling/src/task copy-files
assert_failure
assert_output_contains "Started files copying between environments in Acquia."

popd >/dev/null || exit 1
}

@test "Task: platform from VORTEX_PLATFORM dispatches purge-cache" {
pushd "${LOCAL_REPO_DIR}" >/dev/null || exit 1

unset VORTEX_TASK_PLATFORM
export VORTEX_PLATFORM=acquia
run ./.vortex/tooling/src/task purge-cache
assert_failure
assert_output_contains "Started cache purging in Acquia."

popd >/dev/null || exit 1
}
3 changes: 2 additions & 1 deletion hooks/library/copy-db.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ pushd "/var/www/html/${site}.${target_env}" >/dev/null || exit 1

[ "${VORTEX_TASK_COPY_DB_ACQUIA_SKIP}" = "1" ] && echo "Skipping copying of database between Acquia environments." && exit 0

export VORTEX_PLATFORM=acquia
export VORTEX_ACQUIA_KEY="${VORTEX_ACQUIA_KEY?not set}"
export VORTEX_ACQUIA_SECRET="${VORTEX_ACQUIA_SECRET?not set}"
export VORTEX_ACQUIA_APP_NAME="${VORTEX_ACQUIA_APP_NAME:-${site}}"
export VORTEX_TASK_COPY_DB_ACQUIA_SRC="${VORTEX_TASK_COPY_DB_ACQUIA_SRC:-prod}"
export VORTEX_TASK_COPY_DB_ACQUIA_DST="${VORTEX_TASK_COPY_DB_ACQUIA_DST:-${target_env}}"
export VORTEX_TASK_COPY_DB_ACQUIA_NAME="${VORTEX_TASK_COPY_DB_ACQUIA_NAME?not set}"

./vendor/drevops/vortex-tooling/src/task-copy-db-acquia
./vendor/drevops/vortex-tooling/src/task copy-db

popd >/dev/null || exit 1
3 changes: 2 additions & 1 deletion hooks/library/copy-files.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ pushd "/var/www/html/${site}.${target_env}" >/dev/null || exit 1

[ "${VORTEX_TASK_COPY_FILES_ACQUIA_SKIP}" = "1" ] && echo "Skipping copying of files between Acquia environments." && exit 0

export VORTEX_PLATFORM=acquia
export VORTEX_ACQUIA_KEY="${VORTEX_ACQUIA_KEY?not set}"
export VORTEX_ACQUIA_SECRET="${VORTEX_ACQUIA_SECRET?not set}"
export VORTEX_ACQUIA_APP_NAME="${VORTEX_ACQUIA_APP_NAME:-${site}}"
export VORTEX_TASK_COPY_FILES_ACQUIA_SRC="${VORTEX_TASK_COPY_FILES_ACQUIA_SRC:-prod}"
export VORTEX_TASK_COPY_FILES_ACQUIA_DST="${VORTEX_TASK_COPY_FILES_ACQUIA_DST:-${target_env}}"

./vendor/drevops/vortex-tooling/src/task-copy-files-acquia
./vendor/drevops/vortex-tooling/src/task copy-files

popd >/dev/null || exit 1
4 changes: 2 additions & 2 deletions hooks/library/purge-cache.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env bash
#!/usr/bin/env bash
##
# Acquia Cloud hook: Purge edge cache in an environment.
#
Expand All @@ -15,12 +14,13 @@ pushd "/var/www/html/${site}.${target_env}" >/dev/null || exit 1

[ "${VORTEX_PURGE_CACHE_ACQUIA_SKIP}" = "1" ] && echo "Skipping purging of cache in Acquia environment." && exit 0

export VORTEX_PLATFORM=acquia
export VORTEX_ACQUIA_KEY="${VORTEX_ACQUIA_KEY?not set}"
export VORTEX_ACQUIA_SECRET="${VORTEX_ACQUIA_SECRET?not set}"
export VORTEX_ACQUIA_APP_NAME="${VORTEX_ACQUIA_APP_NAME:-${site}}"
export VORTEX_TASK_PURGE_CACHE_ACQUIA_ENV="${VORTEX_TASK_PURGE_CACHE_ACQUIA_ENV:-${target_env}}"
export VORTEX_TASK_PURGE_CACHE_ACQUIA_DOMAINS_FILE="${VORTEX_TASK_PURGE_CACHE_ACQUIA_DOMAINS_FILE:-"/var/www/html/${site}.${target_env}/hooks/library/domains.txt"}"

./vendor/drevops/vortex-tooling/src/task-purge-cache-acquia
./vendor/drevops/vortex-tooling/src/task purge-cache

popd >/dev/null || exit 1