Skip to content

Commit

Permalink
Simplified variables to use a single DREVOPS_DB_DOWNLOAD_ENVIRONMENT …
Browse files Browse the repository at this point in the history
…variable.
  • Loading branch information
AlexSkrypnyk committed Feb 15, 2024
1 parent 94b07bf commit faceca7
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 43 deletions.
28 changes: 10 additions & 18 deletions .drevops/docs/content/workflows/variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,14 +222,6 @@ Default value: `your_site`

Defined in: `.env`, `scripts/drevops/download-db-acquia.sh`

### `DREVOPS_DB_DOWNLOAD_ACQUIA_ENV`

Acquia environment to download the database from.

Default value: `prod`

Defined in: `.env`, `scripts/drevops/download-db-acquia.sh`

### `DREVOPS_DB_DOWNLOAD_CURL_URL`

Database dump file sourced from CURL, with optional HTTP Basic Authentication<br />credentials embedded into the value.
Expand All @@ -238,6 +230,14 @@ Default value: `UNDEFINED`

Defined in: `.env`, `scripts/drevops/download-db-curl.sh`

### `DREVOPS_DB_DOWNLOAD_ENVIRONMENT`

Environment to download the database from.

Default value: `prod`

Defined in: `.env`, `scripts/drevops/download-db-acquia.sh`, `scripts/drevops/download-db-lagoon.sh`

### `DREVOPS_DB_DOWNLOAD_FORCE`

Always override existing downloaded DB dump.
Expand Down Expand Up @@ -286,14 +286,6 @@ Default value: `UNDEFINED`

Defined in: `.env.local.default`, `scripts/drevops/download-db-ftp.sh`

### `DREVOPS_DB_DOWNLOAD_LAGOON_BRANCH`

Lagoon environment to download the database from.

Default value: `main`

Defined in: `.env`, `scripts/drevops/download-db-lagoon.sh`

### `DREVOPS_DB_DOWNLOAD_LAGOON_REMOTE_DIR`

Remote DB dump directory location.
Expand Down Expand Up @@ -340,7 +332,7 @@ Defined in: `scripts/drevops/download-db-lagoon.sh`

The SSH user of the Lagoon environment.

Default value: `LAGOON_PROJECT-${DREVOPS_DB_DOWNLOAD_LAGOON_BRANCH`
Default value: `LAGOON_PROJECT-${DREVOPS_DB_DOWNLOAD_ENVIRONMENT`

Defined in: `scripts/drevops/download-db-lagoon.sh`

Expand All @@ -364,7 +356,7 @@ Defined in: `scripts/drevops/download-db-lagoon.sh`

Database can be sourced from one of the following locations:

- `url` - directly from URL as a file using CURL.
- `curl` - directly from URL as a file using CURL.
- `ftp` - directly from FTP as a file using CURL.
- `acquia` - from the latest Acquia backup via Cloud API as a file.
- `lagoon` - from Lagoon main environment as a file.
Expand Down
10 changes: 5 additions & 5 deletions .drevops/tests/bats/_helper.bash
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ assert_files_present_provision_use_profile() {
assert_file_contains ".env" "DREVOPS_PROVISION_USE_PROFILE=1"
assert_file_not_contains ".env" "DREVOPS_DB_DOWNLOAD_SOURCE"
assert_file_not_contains ".env" "DREVOPS_DB_DOWNLOAD_CURL_URL"
assert_file_not_contains ".env" "DREVOPS_DB_DOWNLOAD_LAGOON_BRANCH"
assert_file_not_contains ".env" "DREVOPS_DB_DOWNLOAD_ENVIRONMENT"

assert_file_not_contains ".env.local.default" "DREVOPS_DB_DOWNLOAD_FORCE"
assert_file_not_contains ".env.local.default" "DREVOPS_DB_DOWNLOAD_FTP_USER"
Expand Down Expand Up @@ -754,7 +754,7 @@ assert_files_present_integration_acquia() {
if [ "${include_scripts:-}" -eq 1 ]; then
assert_dir_exists "scripts"
assert_file_contains ".env" "DREVOPS_ACQUIA_APP_NAME="
assert_file_contains ".env" "DREVOPS_DB_DOWNLOAD_ACQUIA_ENV="
assert_file_contains ".env" "DREVOPS_DB_DOWNLOAD_ENVIRONMENT="
assert_file_contains ".env" "DREVOPS_DB_DOWNLOAD_ACQUIA_DB_NAME="
fi

Expand All @@ -773,10 +773,10 @@ assert_files_present_no_integration_acquia() {
assert_file_not_contains "${webroot}/sites/default/settings.php" "if (file_exists('/var/www/site-php')) {"
assert_file_not_contains "${webroot}/.htaccess" "RewriteCond %{ENV:AH_SITE_ENVIRONMENT} prod [NC]"
assert_file_not_contains ".env" "DREVOPS_ACQUIA_APP_NAME="
assert_file_not_contains ".env" "DREVOPS_DB_DOWNLOAD_ACQUIA_ENV="
assert_file_not_contains ".env" "DREVOPS_DB_DOWNLOAD_ENVIRONMENT="
assert_file_not_contains ".env" "DREVOPS_DB_DOWNLOAD_ACQUIA_DB_NAME="
assert_file_not_contains ".ahoy.yml" "DREVOPS_ACQUIA_APP_NAME="
assert_file_not_contains ".ahoy.yml" "DREVOPS_DB_DOWNLOAD_ACQUIA_ENV="
assert_file_not_contains ".ahoy.yml" "DREVOPS_DB_DOWNLOAD_ENVIRONMENT="
assert_file_not_contains ".ahoy.yml" "DREVOPS_DB_DOWNLOAD_ACQUIA_DB_NAME="
assert_dir_not_contains_string "${dir}" "DREVOPS_ACQUIA_KEY"
assert_dir_not_contains_string "${dir}" "DREVOPS_ACQUIA_SECRET"
Expand Down Expand Up @@ -827,7 +827,7 @@ assert_files_present_no_integration_lagoon() {
assert_file_not_contains "docker-compose.yml" "lagoon.type: solr"
assert_file_not_contains "docker-compose.yml" "lagoon.type: none"

assert_file_not_contains ".env" "DREVOPS_DB_DOWNLOAD_LAGOON_BRANCH="
assert_file_not_contains ".env" "DREVOPS_DB_DOWNLOAD_ENVIRONMENT="
assert_file_not_contains ".env.local.default" "DREVOPS_DB_DOWNLOAD_SSH_KEY_FILE="

popd >/dev/null || exit 1
Expand Down
18 changes: 4 additions & 14 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ DREVOPS_DB_FILE=db.sql
#;< !PROVISION_USE_PROFILE
# Database can be sourced from one of the following locations:
#
# - `url` - directly from URL as a file using CURL.
# - `curl` - directly from URL as a file using CURL.
# - `ftp` - directly from FTP as a file using CURL.
# - `acquia` - from the latest Acquia backup via Cloud API as a file.
# - `lagoon` - from Lagoon main environment as a file.
Expand All @@ -137,6 +137,9 @@ DREVOPS_DB_FILE=db.sql
# database storage (when $DREVOPS_DB_DOCKER_IMAGE variable has a value).
DREVOPS_DB_DOWNLOAD_SOURCE=curl

# Environment to download the database from.
DREVOPS_DB_DOWNLOAD_ENVIRONMENT=prod

#;< !DREVOPS_DB_DOWNLOAD_SOURCE_DOCKER_REGISTRY
# Database dump file sourced from CURL, with optional HTTP Basic Authentication
# credentials embedded into the value.
Expand All @@ -158,29 +161,16 @@ DREVOPS_DB_DOWNLOAD_FTP_FILE=db.sql
#;> FTP

#;< ACQUIA
# Database dump file sourced from Acquia.

# Acquia application name to download the database from.
DREVOPS_ACQUIA_APP_NAME=

# Acquia environment to download the database from.
DREVOPS_DB_DOWNLOAD_ACQUIA_ENV=prod

# Acquia database name to download the database from.
DREVOPS_DB_DOWNLOAD_ACQUIA_DB_NAME=your_site
#;> ACQUIA

#;< LAGOON
# Database dump file sourced from Lagoon.

# Lagoon project name. May be different from $DREVOPS_PROJECT.
LAGOON_PROJECT=your_site

#;< !PROVISION_USE_PROFILE
# Lagoon environment to download the database from.
DREVOPS_DB_DOWNLOAD_LAGOON_BRANCH=main
#;> !PROVISION_USE_PROFILE

#;> LAGOON

#;< DEPLOYMENT
Expand Down
8 changes: 4 additions & 4 deletions scripts/drevops/download-db-acquia.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ DREVOPS_ACQUIA_SECRET="${DREVOPS_ACQUIA_SECRET:-}"
DREVOPS_ACQUIA_APP_NAME="${DREVOPS_ACQUIA_APP_NAME:-}"

# Source environment name used to download the database dump from.
DREVOPS_DB_DOWNLOAD_ACQUIA_ENV="${DREVOPS_DB_DOWNLOAD_ACQUIA_ENV:-}"
DREVOPS_DB_DOWNLOAD_ENVIRONMENT="${DREVOPS_DB_DOWNLOAD_ENVIRONMENT:-}"

# Database name within source environment used to download the database dump.
DREVOPS_DB_DOWNLOAD_ACQUIA_DB_NAME="${DREVOPS_DB_DOWNLOAD_ACQUIA_DB_NAME:-}"
Expand Down Expand Up @@ -80,7 +80,7 @@ command -v curl >/dev/null || (fail "curl command is not available." && exit 1)
[ -z "${DREVOPS_ACQUIA_KEY}" ] && fail "Missing value for DREVOPS_ACQUIA_KEY." && exit 1
[ -z "${DREVOPS_ACQUIA_SECRET}" ] && fail "Missing value for DREVOPS_ACQUIA_SECRET." && exit 1
[ -z "${DREVOPS_ACQUIA_APP_NAME}" ] && fail "Missing value for DREVOPS_ACQUIA_APP_NAME." && exit 1
[ -z "${DREVOPS_DB_DOWNLOAD_ACQUIA_ENV}" ] && fail "Missing value for DREVOPS_DB_DOWNLOAD_ACQUIA_ENV." && exit 1
[ -z "${DREVOPS_DB_DOWNLOAD_ENVIRONMENT}" ] && fail "Missing value for DREVOPS_DB_DOWNLOAD_ENVIRONMENT." && exit 1
[ -z "${DREVOPS_DB_DOWNLOAD_ACQUIA_DB_NAME}" ] && fail "Missing value for DREVOPS_DB_DOWNLOAD_ACQUIA_DB_NAME." && exit 1

mkdir -p "${DREVOPS_DB_DIR}"
Expand All @@ -95,8 +95,8 @@ app_uuid_json=$(curl -s -L -H 'Accept: application/json, version=2' -H "Authoriz
app_uuid=$(echo "${app_uuid_json}" | extract_json_value "_embedded" | extract_json_value "items" | extract_json_last_value "uuid")
[ -z "${app_uuid}" ] && fail "Unable to retrieve an environment UUID." && exit 1

note "Retrieving ${DREVOPS_DB_DOWNLOAD_ACQUIA_ENV} environment ID."
envs_json=$(curl -s -L -H 'Accept: application/json, version=2' -H "Authorization: Bearer ${token}" "https://cloud.acquia.com/api/applications/${app_uuid}/environments?filter=name%3D${DREVOPS_DB_DOWNLOAD_ACQUIA_ENV}")
note "Retrieving ${DREVOPS_DB_DOWNLOAD_ENVIRONMENT} environment ID."
envs_json=$(curl -s -L -H 'Accept: application/json, version=2' -H "Authorization: Bearer ${token}" "https://cloud.acquia.com/api/applications/${app_uuid}/environments?filter=name%3D${DREVOPS_DB_DOWNLOAD_ENVIRONMENT}")
env_id=$(echo "${envs_json}" | extract_json_value "_embedded" | extract_json_value "items" | extract_json_last_value "id")
[ -z "${env_id}" ] && fail "Unable to retrieve an environment ID." && exit 1

Expand Down
4 changes: 2 additions & 2 deletions scripts/drevops/download-db-lagoon.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ DREVOPS_DB_DOWNLOAD_REFRESH="${DREVOPS_DB_DOWNLOAD_REFRESH:-}"
LAGOON_PROJECT="${LAGOON_PROJECT:?Missing required environment variable LAGOON_PROJECT.}"

# The source environment branch for the database source.
DREVOPS_DB_DOWNLOAD_LAGOON_BRANCH="${DREVOPS_DB_DOWNLOAD_LAGOON_BRANCH:-main}"
DREVOPS_DB_DOWNLOAD_ENVIRONMENT="${DREVOPS_DB_DOWNLOAD_ENVIRONMENT:-main}"

# Remote DB dump directory location.
DREVOPS_DB_DOWNLOAD_LAGOON_REMOTE_DIR="/tmp"
Expand Down Expand Up @@ -58,7 +58,7 @@ DREVOPS_DB_DOWNLOAD_LAGOON_SSH_HOST="${DREVOPS_DB_DOWNLOAD_LAGOON_SSH_HOST:-ssh.
DREVOPS_DB_DOWNLOAD_LAGOON_SSH_PORT="${DREVOPS_DB_DOWNLOAD_LAGOON_SSH_PORT:-32222}"

# The SSH user of the Lagoon environment.
DREVOPS_DB_DOWNLOAD_LAGOON_SSH_USER="${DREVOPS_DB_DOWNLOAD_LAGOON_SSH_USER:-${LAGOON_PROJECT}-${DREVOPS_DB_DOWNLOAD_LAGOON_BRANCH}}"
DREVOPS_DB_DOWNLOAD_LAGOON_SSH_USER="${DREVOPS_DB_DOWNLOAD_LAGOON_SSH_USER:-${LAGOON_PROJECT}-${DREVOPS_DB_DOWNLOAD_ENVIRONMENT}}"

# Directory where DB dumps are stored on the host.
DREVOPS_DB_DIR="${DREVOPS_DB_DIR:-./.data}"
Expand Down

0 comments on commit faceca7

Please sign in to comment.