From 9b7d2dfb0cb343e92a0e70597ba52ae7e6c497a0 Mon Sep 17 00:00:00 2001 From: Alex Skrypnyk Date: Fri, 10 May 2024 05:54:57 +1000 Subject: [PATCH] [#1315] Added drupal config dir auto-discovery during provisioning. --- .../docs/content/workflows/variables.mdx | 16 ++--- .scaffold/tests/bats/provision.bats | 63 ++++++++++--------- scripts/drevops/provision.sh | 27 +++++--- 3 files changed, 60 insertions(+), 46 deletions(-) diff --git a/.scaffold/docs/content/workflows/variables.mdx b/.scaffold/docs/content/workflows/variables.mdx index 492b8a096..806d51149 100644 --- a/.scaffold/docs/content/workflows/variables.mdx +++ b/.scaffold/docs/content/workflows/variables.mdx @@ -761,14 +761,6 @@ Default value: `${DREVOPS_CONTAINER_REGISTRY_USER}` Defined in: `scripts/drevops/download-db-container-registry.sh` -### `DREVOPS_DRUPAL_CONFIG_PATH` - -Path to configuration directory. - -Default value: `./config/default` - -Defined in: `scripts/drevops/provision.sh` - ### `DREVOPS_EXPORT_CODE_DIR` Directory to store exported code. @@ -1618,6 +1610,14 @@ Default value: `daemon` Defined in: `.env` +### `DRUPAL_CONFIG_PATH` + +Path to configuration directory relative to the project root.
Auto-discovered from site's `settings.php` file if not set. + +Default value: `UNDEFINED` + +Defined in: `scripts/drevops/provision.sh` + ### `DRUPAL_ENVIRONMENT` Override detected Drupal environment type. diff --git a/.scaffold/tests/bats/provision.bats b/.scaffold/tests/bats/provision.bats index 3c9d3e50a..39913c0cb 100644 --- a/.scaffold/tests/bats/provision.bats +++ b/.scaffold/tests/bats/provision.bats @@ -6,8 +6,8 @@ load _helper.bash -export DRUPAL_PUBLIC_FILES="./web/sites/default/files" -export DRUPAL_PRIVATE_FILES="./web/sites/default/files/private" +export DRUPAL_PUBLIC_FILES="/app/web/sites/default/files" +export DRUPAL_PRIVATE_FILES="/app/web/sites/default/files/private" export DRUPAL_TEMPORARY_FILES="/tmp" assert_provision_info() { @@ -20,11 +20,11 @@ assert_provision_info() { assert_output_contains "Started site provisioning." assert_output_contains "Webroot dir : ${webroot}" assert_output_contains "Profile : standard" - assert_output_contains "Public files directory : ./${webroot}/sites/default/files" - assert_output_contains "Private files directory : ./${webroot}/sites/default/files/private" - assert_output_contains "Temporary files directory : /tmp" - assert_output_contains "Config path : ./config/default" - assert_output_contains "DB dump file path : ./.data/db.sql" + assert_output_contains "Public files path : /app/${webroot}/sites/default/files" + assert_output_contains "Private files path : /app/${webroot}/sites/default/files/private" + assert_output_contains "Temporary files path : /tmp" + assert_output_contains "Config path : $(pwd)/config/default" + assert_output_contains "DB dump file path : $(pwd)/.data/db.sql" assert_output_contains "Drush version : mocked_drush_version" assert_output_contains "Drupal core version : mocked_core_version" @@ -38,7 +38,7 @@ assert_provision_info() { assert_output_contains "Existing site found : $(format_yes_no "${7:-0}")" } -@test "Site install: DB; no site" { +@test "Provision: DB; no site" { pushd "${LOCAL_REPO_DIR}" >/dev/null || exit 1 # Remove .env file to test in isolation. @@ -57,10 +57,11 @@ assert_provision_info() { "@drush -y --version # Drush Commandline Tool mocked_drush_version" "@drush -y status --field=drupal-version # mocked_core_version" "@drush -y status --fields=bootstrap # fail" + "@drush -y php:eval print realpath(\Drupal\Core\Site\Settings::get(\"config_sync_directory\")); # $(pwd)/config/default" # Site provisioning information. "Provisioning site from the database dump file." - "Dump file path: ./.data/db.sql" + "Dump file path: $(pwd)/.data/db.sql" "- Existing site was found when provisioning from the database dump file." "- Site content will be preserved." "- Sanitization will be skipped for an existing database." @@ -70,7 +71,7 @@ assert_provision_info() { "@drush -y sql:drop" "@drush -y sql:cli" "- Unable to import database from file." - "- Dump file ./.data/db.sql does not exist." + "- Dump file $(pwd)/.data/db.sql does not exist." "- Site content was not changed." "Imported database from the dump file." # Profile. @@ -159,7 +160,7 @@ assert_provision_info() { popd >/dev/null || exit 1 } -@test "Site install: DB; existing site" { +@test "Provision: DB; existing site" { pushd "${LOCAL_REPO_DIR}" >/dev/null || exit 1 # Remove .env file to test in isolation. @@ -177,10 +178,11 @@ assert_provision_info() { "@drush -y --version # Drush Commandline Tool mocked_drush_version" "@drush -y status --field=drupal-version # mocked_core_version" "@drush -y status --fields=bootstrap # Successful" + "@drush -y php:eval print realpath(\Drupal\Core\Site\Settings::get(\"config_sync_directory\")); # $(pwd)/config/default" # Site provisioning information. "Provisioning site from the database dump file." - "Dump file path: ./.data/db.sql" + "Dump file path: $(pwd)/.data/db.sql" "Existing site was found when provisioning from the database dump file." "Site content will be preserved." "Sanitization will be skipped for an existing database." @@ -188,7 +190,7 @@ assert_provision_info() { "- Existing site was not found when installing from the database dump file." "- Fresh site content will be imported from the database dump file." "- Unable to import database from file." - "- Dump file ./.data/db.sql does not exist." + "- Dump file $(pwd)/.data/db.sql does not exist." "- Site content was not changed." "- Imported database from the dump file." # Profile. @@ -273,7 +275,7 @@ assert_provision_info() { popd >/dev/null || exit 1 } -@test "Site install: DB; existing site; overwrite" { +@test "Provision: DB; existing site; overwrite" { pushd "${LOCAL_REPO_DIR}" >/dev/null || exit 1 # Remove .env file to test in isolation. @@ -294,10 +296,11 @@ assert_provision_info() { "@drush -y --version # Drush Commandline Tool mocked_drush_version" "@drush -y status --field=drupal-version # mocked_core_version" "@drush -y status --fields=bootstrap # Successful" + "@drush -y php:eval print realpath(\Drupal\Core\Site\Settings::get(\"config_sync_directory\")); # $(pwd)/config/default" # Site provisioning information. "Provisioning site from the database dump file." - "Dump file path: ./.data/db.sql" + "Dump file path: $(pwd)/.data/db.sql" "Existing site was found when provisioning from the database dump file." "- Site content will be preserved." "- Sanitization will be skipped for an existing database." @@ -307,7 +310,7 @@ assert_provision_info() { "@drush -y sql:drop" "@drush -y sql:cli" "- Unable to import database from file." - "- Dump file ./.data/db.sql does not exist." + "- Dump file $(pwd)/.data/db.sql does not exist." "- Site content was not changed." "Imported database from the dump file." # Profile. @@ -396,7 +399,7 @@ assert_provision_info() { popd >/dev/null || exit 1 } -@test "Site install: DB; no site, configs" { +@test "Provision: DB; no site, configs" { pushd "${LOCAL_REPO_DIR}" >/dev/null || exit 1 # Remove .env file to test in isolation. @@ -419,10 +422,11 @@ assert_provision_info() { "@drush -y --version # Drush Commandline Tool mocked_drush_version" "@drush -y status --field=drupal-version # mocked_core_version" "@drush -y status --fields=bootstrap # fail" + "@drush -y php:eval print realpath(\Drupal\Core\Site\Settings::get(\"config_sync_directory\")); # $(pwd)/config/default" # Site provisioning information. "Provisioning site from the database dump file." - "Dump file path: ./.data/db.sql" + "Dump file path: $(pwd)/.data/db.sql" "- Existing site was found when provisioning from the database dump file." "- Site content will be preserved." "- Sanitization will be skipped for an existing database." @@ -432,7 +436,7 @@ assert_provision_info() { "@drush -y sql:drop" "@drush -y sql:cli" "- Unable to import database from file." - "- Dump file ./.data/db.sql does not exist." + "- Dump file $(pwd)/.data/db.sql does not exist." "- Site content was not changed." "Imported database from the dump file." # Profile. @@ -523,7 +527,7 @@ assert_provision_info() { popd >/dev/null || exit 1 } -@test "Site install: profile; no site" { +@test "Provision: profile; no site" { pushd "${LOCAL_REPO_DIR}" >/dev/null || exit 1 # Remove .env file to test in isolation. @@ -544,10 +548,11 @@ assert_provision_info() { "@drush -y --version # Drush Commandline Tool mocked_drush_version" "@drush -y status --field=drupal-version # mocked_core_version" "@drush -y status --fields=bootstrap # fail" + "@drush -y php:eval print realpath(\Drupal\Core\Site\Settings::get(\"config_sync_directory\")); # $(pwd)/config/default" # Site provisioning information. "- Provisioning site from the database dump file." - "- Dump file path: ./.data/db.sql" + "- Dump file path: $(pwd)/.data/db.sql" "- Existing site was found when provisioning from the database dump file." "- Site content will be preserved." "- Sanitization will be skipped for an existing database." @@ -555,7 +560,7 @@ assert_provision_info() { "- Existing site was not found when installing from the database dump file." "- Fresh site content will be imported from the database dump file." "- Unable to import database from file." - "- Dump file ./.data/db.sql does not exist." + "- Dump file $(pwd)/.data/db.sql does not exist." "- Site content was not changed." "- Imported database from the dump file." # Profile. @@ -646,7 +651,7 @@ assert_provision_info() { popd >/dev/null || exit 1 } -@test "Site install: profile; existing site" { +@test "Provision: profile; existing site" { pushd "${LOCAL_REPO_DIR}" >/dev/null || exit 1 # Remove .env file to test in isolation. @@ -667,10 +672,11 @@ assert_provision_info() { "@drush -y --version # Drush Commandline Tool mocked_drush_version" "@drush -y status --field=drupal-version # mocked_core_version" "@drush -y status --fields=bootstrap # Successful" + "@drush -y php:eval print realpath(\Drupal\Core\Site\Settings::get(\"config_sync_directory\")); # $(pwd)/config/default" # Site provisioning information. "- Provisioning site from the database dump file." - "- Dump file path: ./.data/db.sql" + "- Dump file path: $(pwd)/.data/db.sql" "- Existing site was found when provisioning from the database dump file." "Site content will be preserved." "Sanitization will be skipped for an existing database." @@ -678,7 +684,7 @@ assert_provision_info() { "- Existing site was not found when installing from the database dump file." "- Fresh site content will be imported from the database dump file." "- Unable to import database from file." - "- Dump file ./.data/db.sql does not exist." + "- Dump file $(pwd)/.data/db.sql does not exist." "- Site content was not changed." "- Imported database from the dump file." # Profile. @@ -763,7 +769,7 @@ assert_provision_info() { popd >/dev/null || exit 1 } -@test "Site install: profile; existing site; overwrite" { +@test "Provision: profile; existing site; overwrite" { pushd "${LOCAL_REPO_DIR}" >/dev/null || exit 1 # Remove .env file to test in isolation. @@ -785,10 +791,11 @@ assert_provision_info() { "@drush -y --version # Drush Commandline Tool mocked_drush_version" "@drush -y status --field=drupal-version # mocked_core_version" "@drush -y status --fields=bootstrap # Successful" + "@drush -y php:eval print realpath(\Drupal\Core\Site\Settings::get(\"config_sync_directory\")); # $(pwd)/config/default" # Site provisioning information. "- Provisioning site from the database dump file." - "- Dump file path: ./.data/db.sql" + "- Dump file path: $(pwd)/.data/db.sql" "- Existing site was found when provisioning from the database dump file." "- Site content will be preserved." "- Sanitization will be skipped for an existing database." @@ -796,7 +803,7 @@ assert_provision_info() { "- Existing site was not found when installing from the database dump file." "- Fresh site content will be imported from the database dump file." "- Unable to import database from file." - "- Dump file ./.data/db.sql does not exist." + "- Dump file $(pwd)/.data/db.sql does not exist." "- Site content was not changed." "- Imported database from the dump file." # Profile. diff --git a/scripts/drevops/provision.sh b/scripts/drevops/provision.sh index f5560e037..c839af2de 100755 --- a/scripts/drevops/provision.sh +++ b/scripts/drevops/provision.sh @@ -50,8 +50,9 @@ DRUPAL_SITE_EMAIL="${DRUPAL_SITE_EMAIL:-webmaster@example.com}" # Profile machine name. DRUPAL_PROFILE="${DRUPAL_PROFILE:-standard}" -# Path to configuration directory. -DREVOPS_DRUPAL_CONFIG_PATH="${DREVOPS_DRUPAL_CONFIG_PATH:-./config/default}" +# Path to configuration directory relative to the project root. +# Auto-discovered from site's `settings.php` file if not set. +DRUPAL_CONFIG_PATH="${DRUPAL_CONFIG_PATH:-}" # Directory with database dump file. DREVOPS_DB_DIR="${DREVOPS_DB_DIR:-./.data}" @@ -76,23 +77,29 @@ info "Started site provisioning." [ "${DREVOPS_PROVISION_SKIP}" = "1" ] && pass "Skipped site provisioning as DREVOPS_PROVISION_SKIP is set to 1." && exit 0 ## Convert DB dir starting with './' to a full path. -#[ "${DREVOPS_DB_DIR#./}" != "${DREVOPS_DB_DIR}" ] && DREVOPS_DB_DIR="$(pwd)${DREVOPS_DB_DIR#.}" +[ "${DREVOPS_DB_DIR#./}" != "${DREVOPS_DB_DIR}" ] && DREVOPS_DB_DIR="$(pwd)${DREVOPS_DB_DIR#.}" drush_version="$(drush --version | cut -d' ' -f4)" drupal_core_version="$(drush status --field=drupal-version)" -site_has_config="$(test "$(ls -1 ${DREVOPS_DRUPAL_CONFIG_PATH}/*.yml 2>/dev/null | wc -l | tr -d ' ')" -gt 0 && echo "1" || echo "0")" site_is_installed="$(drush status --fields=bootstrap | grep -q "Successful" && echo "1" || echo "0")" +if [ -z "${DRUPAL_CONFIG_PATH}" ]; then + DRUPAL_CONFIG_PATH="$(drush php:eval 'print realpath(\Drupal\Core\Site\Settings::get("config_sync_directory"));')" + [ ! -d "${DRUPAL_CONFIG_PATH}" ] && fail "Config directory \"${DRUPAL_CONFIG_PATH:-}\" does not exist." && exit 1 +fi + +site_has_config="$(test "$(ls -1 ${DRUPAL_CONFIG_PATH}/*.yml 2>/dev/null | wc -l | tr -d ' ')" -gt 0 && echo "1" || echo "0")" + ################################################################################ # Print provisioning information. ################################################################################ echo note "Webroot dir : ${DREVOPS_WEBROOT}" note "Profile : ${DRUPAL_PROFILE}" -note "Public files directory : ${DRUPAL_PUBLIC_FILES-}" -note "Private files directory : ${DRUPAL_PRIVATE_FILES-}" -note "Temporary files directory : ${DRUPAL_TEMPORARY_FILES-}" -note "Config path : ${DREVOPS_DRUPAL_CONFIG_PATH}" +note "Public files path : ${DRUPAL_PUBLIC_FILES-}" +note "Private files path : ${DRUPAL_PRIVATE_FILES-}" +note "Temporary files path : ${DRUPAL_TEMPORARY_FILES-}" +note "Config path : ${DRUPAL_CONFIG_PATH}" note "DB dump file path : ${DREVOPS_DB_DIR}/${DREVOPS_DB_FILE} ($([ -f "${DREVOPS_DB_DIR}/${DREVOPS_DB_FILE}" ] && echo "present" || echo "absent"))" if [ -n "${DREVOPS_DB_IMAGE:-}" ]; then note "DB dump container image : ${DREVOPS_DB_IMAGE}" @@ -235,8 +242,8 @@ echo # Use 'drush deploy' if configuration files are present or use standalone commands otherwise. if [ "${site_has_config}" = "1" ]; then - if [ -f "${DREVOPS_DRUPAL_CONFIG_PATH}/system.site.yml" ]; then - config_uuid="$(cat "${DREVOPS_DRUPAL_CONFIG_PATH}/system.site.yml" | grep uuid | tail -c +7 | head -c 36)" + if [ -f "${DRUPAL_CONFIG_PATH}/system.site.yml" ]; then + config_uuid="$(cat "${DRUPAL_CONFIG_PATH}/system.site.yml" | grep uuid | tail -c +7 | head -c 36)" drush config-set system.site uuid "${config_uuid}" pass "Updated site UUID from the configuration with ${config_uuid}." fi