Skip to content

Commit

Permalink
[#1315] Added drupal config dir auto-discovery during provisioning.
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexSkrypnyk committed May 9, 2024
1 parent 604b973 commit 9b7d2df
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 46 deletions.
16 changes: 8 additions & 8 deletions .scaffold/docs/content/workflows/variables.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -1618,6 +1610,14 @@ Default value: `daemon`

Defined in: `.env`

### `DRUPAL_CONFIG_PATH`

Path to configuration directory relative to the project root.<br />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.
Expand Down
63 changes: 35 additions & 28 deletions .scaffold/tests/bats/provision.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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"
Expand All @@ -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.
Expand All @@ -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."
Expand All @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -177,18 +178,19 @@ 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."
"- Existing site content will be removed and fresh content will be imported from the database dump file."
"- 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.
Expand Down Expand Up @@ -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.
Expand All @@ -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."
Expand All @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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."
Expand All @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -544,18 +548,19 @@ 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."
"- Existing site content will be removed and fresh content will be imported from the database dump file."
"- 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.
Expand Down Expand Up @@ -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.
Expand All @@ -667,18 +672,19 @@ 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."
"- Existing site content will be removed and fresh content will be imported from the database dump file."
"- 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.
Expand Down Expand Up @@ -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.
Expand All @@ -785,18 +791,19 @@ 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."
"- Existing site content will be removed and fresh content will be imported from the database dump file."
"- 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.
Expand Down
27 changes: 17 additions & 10 deletions scripts/drevops/provision.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ DRUPAL_SITE_EMAIL="${DRUPAL_SITE_EMAIL:[email protected]}"
# 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:-}"

Check warning on line 55 in scripts/drevops/provision.sh

View check run for this annotation

Codecov / codecov/patch

scripts/drevops/provision.sh#L55

Added line #L55 was not covered by tests

# Directory with database dump file.
DREVOPS_DB_DIR="${DREVOPS_DB_DIR:-./.data}"
Expand All @@ -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#.}"

Check warning on line 80 in scripts/drevops/provision.sh

View check run for this annotation

Codecov / codecov/patch

scripts/drevops/provision.sh#L80

Added line #L80 was not covered by tests

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:-<empty>}\" does not exist." && exit 1

Check warning on line 88 in scripts/drevops/provision.sh

View check run for this annotation

Codecov / codecov/patch

scripts/drevops/provision.sh#L86-L88

Added lines #L86 - L88 were not covered by tests
fi

site_has_config="$(test "$(ls -1 ${DRUPAL_CONFIG_PATH}/*.yml 2>/dev/null | wc -l | tr -d ' ')" -gt 0 && echo "1" || echo "0")"

Check warning on line 91 in scripts/drevops/provision.sh

View check run for this annotation

Codecov / codecov/patch

scripts/drevops/provision.sh#L91

Added line #L91 was not covered by tests

################################################################################
# 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-<empty>}"
note "Private files path : ${DRUPAL_PRIVATE_FILES-<empty>}"
note "Temporary files path : ${DRUPAL_TEMPORARY_FILES-<empty>}"
note "Config path : ${DRUPAL_CONFIG_PATH}"

Check warning on line 102 in scripts/drevops/provision.sh

View check run for this annotation

Codecov / codecov/patch

scripts/drevops/provision.sh#L99-L102

Added lines #L99 - L102 were not covered by tests
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}"
Expand Down Expand Up @@ -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)"

Check warning on line 246 in scripts/drevops/provision.sh

View check run for this annotation

Codecov / codecov/patch

scripts/drevops/provision.sh#L245-L246

Added lines #L245 - L246 were not covered by tests
drush config-set system.site uuid "${config_uuid}"
pass "Updated site UUID from the configuration with ${config_uuid}."
fi
Expand Down

1 comment on commit 9b7d2df

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.