diff --git a/.vortex/docs/content/hosting/acquia.mdx b/.vortex/docs/content/hosting/acquia.mdx index 64de84b9a..0b601c599 100644 --- a/.vortex/docs/content/hosting/acquia.mdx +++ b/.vortex/docs/content/hosting/acquia.mdx @@ -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 | 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. diff --git a/.vortex/installer/tests/Fixtures/handler_process/hosting_acquia/hooks/library/copy-db.sh b/.vortex/installer/tests/Fixtures/handler_process/hosting_acquia/hooks/library/copy-db.sh index 9185501b4..ea006da1c 100755 --- a/.vortex/installer/tests/Fixtures/handler_process/hosting_acquia/hooks/library/copy-db.sh +++ b/.vortex/installer/tests/Fixtures/handler_process/hosting_acquia/hooks/library/copy-db.sh @@ -14,6 +14,7 @@ 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}}" @@ -21,6 +22,6 @@ 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 diff --git a/.vortex/installer/tests/Fixtures/handler_process/hosting_acquia/hooks/library/copy-files.sh b/.vortex/installer/tests/Fixtures/handler_process/hosting_acquia/hooks/library/copy-files.sh index 95924c1eb..c718cf166 100755 --- a/.vortex/installer/tests/Fixtures/handler_process/hosting_acquia/hooks/library/copy-files.sh +++ b/.vortex/installer/tests/Fixtures/handler_process/hosting_acquia/hooks/library/copy-files.sh @@ -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 diff --git a/.vortex/installer/tests/Fixtures/handler_process/hosting_acquia/hooks/library/purge-cache.sh b/.vortex/installer/tests/Fixtures/handler_process/hosting_acquia/hooks/library/purge-cache.sh index 81b73bef1..71e693ab7 100755 --- a/.vortex/installer/tests/Fixtures/handler_process/hosting_acquia/hooks/library/purge-cache.sh +++ b/.vortex/installer/tests/Fixtures/handler_process/hosting_acquia/hooks/library/purge-cache.sh @@ -1,5 +1,4 @@ #!/usr/bin/env bash -#!/usr/bin/env bash ## # Acquia Cloud hook: Purge edge cache in an environment. # @@ -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 diff --git a/.vortex/installer/tests/Fixtures/handler_process/hosting_project_name___acquia/hooks/library/copy-db.sh b/.vortex/installer/tests/Fixtures/handler_process/hosting_project_name___acquia/hooks/library/copy-db.sh index 9185501b4..ea006da1c 100755 --- a/.vortex/installer/tests/Fixtures/handler_process/hosting_project_name___acquia/hooks/library/copy-db.sh +++ b/.vortex/installer/tests/Fixtures/handler_process/hosting_project_name___acquia/hooks/library/copy-db.sh @@ -14,6 +14,7 @@ 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}}" @@ -21,6 +22,6 @@ 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 diff --git a/.vortex/installer/tests/Fixtures/handler_process/hosting_project_name___acquia/hooks/library/copy-files.sh b/.vortex/installer/tests/Fixtures/handler_process/hosting_project_name___acquia/hooks/library/copy-files.sh index 95924c1eb..c718cf166 100755 --- a/.vortex/installer/tests/Fixtures/handler_process/hosting_project_name___acquia/hooks/library/copy-files.sh +++ b/.vortex/installer/tests/Fixtures/handler_process/hosting_project_name___acquia/hooks/library/copy-files.sh @@ -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 diff --git a/.vortex/installer/tests/Fixtures/handler_process/hosting_project_name___acquia/hooks/library/purge-cache.sh b/.vortex/installer/tests/Fixtures/handler_process/hosting_project_name___acquia/hooks/library/purge-cache.sh index 81b73bef1..71e693ab7 100755 --- a/.vortex/installer/tests/Fixtures/handler_process/hosting_project_name___acquia/hooks/library/purge-cache.sh +++ b/.vortex/installer/tests/Fixtures/handler_process/hosting_project_name___acquia/hooks/library/purge-cache.sh @@ -1,5 +1,4 @@ #!/usr/bin/env bash -#!/usr/bin/env bash ## # Acquia Cloud hook: Purge edge cache in an environment. # @@ -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 diff --git a/.vortex/tooling/src/task b/.vortex/tooling/src/task new file mode 100755 index 000000000..930477e44 --- /dev/null +++ b/.vortex/tooling/src/task @@ -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 [args...]' +# runs the 'task--' 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}" "$@" diff --git a/.vortex/tooling/tests/unit/task.bats b/.vortex/tooling/tests/unit/task.bats new file mode 100644 index 000000000..3c45fb7fc --- /dev/null +++ b/.vortex/tooling/tests/unit/task.bats @@ -0,0 +1,118 @@ +#!/usr/bin/env bats +## +# Unit tests for the task router. +# +# The router resolves a platform-agnostic operation to the +# 'task--' 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 +} diff --git a/hooks/library/copy-db.sh b/hooks/library/copy-db.sh index 9185501b4..ea006da1c 100755 --- a/hooks/library/copy-db.sh +++ b/hooks/library/copy-db.sh @@ -14,6 +14,7 @@ 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}}" @@ -21,6 +22,6 @@ 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 diff --git a/hooks/library/copy-files.sh b/hooks/library/copy-files.sh index 95924c1eb..c718cf166 100755 --- a/hooks/library/copy-files.sh +++ b/hooks/library/copy-files.sh @@ -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 diff --git a/hooks/library/purge-cache.sh b/hooks/library/purge-cache.sh index 81b73bef1..71e693ab7 100755 --- a/hooks/library/purge-cache.sh +++ b/hooks/library/purge-cache.sh @@ -1,5 +1,4 @@ #!/usr/bin/env bash -#!/usr/bin/env bash ## # Acquia Cloud hook: Purge edge cache in an environment. # @@ -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