Skip to content

Commit

Permalink
Updated output from provision script to be more structural.
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexSkrypnyk committed May 9, 2024
1 parent 2a9f552 commit ab9122d
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 77 deletions.
93 changes: 47 additions & 46 deletions .scaffold/tests/bats/provision.bats
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,26 @@ assert_provision_info() {
[ "${1}" == "1" ] && echo "Yes" || echo "No"
}

assert_output_contains "Drupal core version : mocked_core_version"
assert_output_contains "Drush version : mocked_drush_version"

assert_output_contains "Started site provisioning."
assert_output_contains "Webroot dir : ${webroot}"
assert_output_contains "Profile : standard"
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"

assert_output_contains "Install from profile : $(format_yes_no "${1:-0}")"
assert_output_contains "Overwrite existing DB : $(format_yes_no "${2:-0}")"
assert_output_contains "Skip sanitization : $(format_yes_no "${3:-0}")"
assert_output_contains "Use maintenance mode : $(format_yes_no "${4:-1}")"
assert_output_contains "Skip post-install operations : $(format_yes_no "${5:-0}")"
assert_output_contains "Configuration files present : $(format_yes_no "${6:-0}")"
assert_output_contains "Existing site found : $(format_yes_no "${7:-0}")"
assert_output_contains "Webroot path : $(pwd)/${webroot}"
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 files path : $(pwd)/config/default"
assert_output_contains "DB dump file path : $(pwd)/.data/db.sql"

assert_output_contains "Profile : standard"
assert_output_contains "Configuration files present : $(format_yes_no "${6:-0}")"
assert_output_contains "Existing site found : $(format_yes_no "${7:-0}")"

assert_output_contains "Install from profile : $(format_yes_no "${1:-0}")"
assert_output_contains "Overwrite existing DB : $(format_yes_no "${2:-0}")"
assert_output_contains "Skip DB sanitization : $(format_yes_no "${3:-0}")"
assert_output_contains "Skip post-provision operations : $(format_yes_no "${5:-0}")"
assert_output_contains "Use maintenance mode : $(format_yes_no "${4:-1}")"
}

@test "Provision: DB; no site" {
Expand Down Expand Up @@ -82,8 +83,8 @@ assert_provision_info() {
"- Existing site was not found when provisioning from the profile."
"- Fresh site content will be created from the profile."

# Post-install operations.
"- Skipped running of post-install operations as DREVOPS_PROVISION_POST_OPERATIONS_SKIP is set to 1."
# Post-provision operations.
"- Skipped running of post-provision operations as DREVOPS_PROVISION_POST_OPERATIONS_SKIP is set to 1."

# Maintenance mode.
"Enabling maintenance mode."
Expand Down Expand Up @@ -134,8 +135,8 @@ assert_provision_info() {
"@drush -y deploy:hook"
"Executing example operations in non-production environment."
# Assert that DREVOPS_PROVISION_OVERRIDE_DB is correctly passed to the script.
"Fresh database detected. Performing additional operations."
"- Existing database detected. Skipping additional operations."
"Fresh database detected. Performing additional example operations."
"- Existing database detected. Performing additional example operations."
"Completed running of custom post-install script './scripts/custom/provision-10-example.sh'."

# Disabling maintenance mode.
Expand Down Expand Up @@ -201,8 +202,8 @@ assert_provision_info() {
"- Existing site was not found when provisioning from the profile."
"- Fresh site content will be created from the profile."

# Post-install operations.
"- Skipped running of post-install operations as DREVOPS_PROVISION_POST_OPERATIONS_SKIP is set to 1."
# Post-provision operations.
"- Skipped running of post-provision operations as DREVOPS_PROVISION_POST_OPERATIONS_SKIP is set to 1."

# Maintenance mode.
"Enabling maintenance mode."
Expand Down Expand Up @@ -249,8 +250,8 @@ assert_provision_info() {
"@drush -y deploy:hook"
"Executing example operations in non-production environment."
# Assert that DREVOPS_PROVISION_OVERRIDE_DB is correctly passed to the script.
"- Fresh database detected. Performing additional operations."
"Existing database detected. Skipping additional operations."
"- Fresh database detected. Performing additional example operations."
"Existing database detected. Performing additional example operations."
"Completed running of custom post-install script './scripts/custom/provision-10-example.sh'."

# Disabling maintenance mode.
Expand Down Expand Up @@ -321,8 +322,8 @@ assert_provision_info() {
"- Existing site was not found when provisioning from the profile."
"- Fresh site content will be created from the profile."

# Post-install operations.
"- Skipped running of post-install operations as DREVOPS_PROVISION_POST_OPERATIONS_SKIP is set to 1."
# Post-provision operations.
"- Skipped running of post-provision operations as DREVOPS_PROVISION_POST_OPERATIONS_SKIP is set to 1."

# Maintenance mode.
"Enabling maintenance mode."
Expand Down Expand Up @@ -373,8 +374,8 @@ assert_provision_info() {
"@drush -y deploy:hook"
"Executing example operations in non-production environment."
# Assert that DREVOPS_PROVISION_OVERRIDE_DB is correctly passed to the script.
"Fresh database detected. Performing additional operations."
"- Existing database detected. Skipping additional operations."
"Fresh database detected. Performing additional example operations."
"- Existing database detected. Performing additional example operations."
"Completed running of custom post-install script './scripts/custom/provision-10-example.sh'."

# Disabling maintenance mode.
Expand Down Expand Up @@ -447,8 +448,8 @@ assert_provision_info() {
"- Existing site was not found when provisioning from the profile."
"- Fresh site content will be created from the profile."

# Post-install operations.
"- Skipped running of post-install operations as DREVOPS_PROVISION_POST_OPERATIONS_SKIP is set to 1."
# Post-provision operations.
"- Skipped running of post-provision operations as DREVOPS_PROVISION_POST_OPERATIONS_SKIP is set to 1."

# Maintenance mode.
"Enabling maintenance mode."
Expand Down Expand Up @@ -501,8 +502,8 @@ assert_provision_info() {
"@drush -y deploy:hook"
"Executing example operations in non-production environment."
# Assert that DREVOPS_PROVISION_OVERRIDE_DB is correctly passed to the script.
"Fresh database detected. Performing additional operations."
"- Existing database detected. Skipping additional operations."
"Fresh database detected. Performing additional example operations."
"- Existing database detected. Performing additional example operations."
"Completed running of custom post-install script './scripts/custom/provision-10-example.sh'."

# Disabling maintenance mode.
Expand Down Expand Up @@ -573,8 +574,8 @@ assert_provision_info() {
"Existing site was not found when provisioning from the profile."
"Fresh site content will be created from the profile."

# Post-install operations.
"- Skipped running of post-install operations as DREVOPS_PROVISION_POST_OPERATIONS_SKIP is set to 1."
# Post-provision operations.
"- Skipped running of post-provision operations as DREVOPS_PROVISION_POST_OPERATIONS_SKIP is set to 1."

# Maintenance mode.
"Enabling maintenance mode."
Expand Down Expand Up @@ -625,8 +626,8 @@ assert_provision_info() {
"@drush -y deploy:hook"
"Executing example operations in non-production environment."
# Assert that DREVOPS_PROVISION_OVERRIDE_DB is correctly passed to the script.
"Fresh database detected. Performing additional operations."
"- Existing database detected. Skipping additional operations."
"Fresh database detected. Performing additional example operations."
"- Existing database detected. Performing additional example operations."
"Completed running of custom post-install script './scripts/custom/provision-10-example.sh'."

# Disabling maintenance mode.
Expand Down Expand Up @@ -695,8 +696,8 @@ assert_provision_info() {
"- Existing site was not found when provisioning from the profile."
"- Fresh site content will be created from the profile."

# Post-install operations.
"- Skipped running of post-install operations as DREVOPS_PROVISION_POST_OPERATIONS_SKIP is set to 1."
# Post-provision operations.
"- Skipped running of post-provision operations as DREVOPS_PROVISION_POST_OPERATIONS_SKIP is set to 1."

# Maintenance mode.
"Enabling maintenance mode."
Expand Down Expand Up @@ -743,8 +744,8 @@ assert_provision_info() {
"@drush -y deploy:hook"
"Executing example operations in non-production environment."
# Assert that DREVOPS_PROVISION_OVERRIDE_DB is correctly passed to the script.
"- Fresh database detected. Performing additional operations."
"Existing database detected. Skipping additional operations."
"- Fresh database detected. Performing additional example operations."
"Existing database detected. Performing additional example operations."
"Completed running of custom post-install script './scripts/custom/provision-10-example.sh'."

# Disabling maintenance mode.
Expand Down Expand Up @@ -816,8 +817,8 @@ assert_provision_info() {
"- Existing site was not found when provisioning from the profile."
"- Fresh site content will be created from the profile."

# Post-install operations.
"- Skipped running of post-install operations as DREVOPS_PROVISION_POST_OPERATIONS_SKIP is set to 1."
# Post-provision operations.
"- Skipped running of post-provision operations as DREVOPS_PROVISION_POST_OPERATIONS_SKIP is set to 1."

# Maintenance mode.
"Enabling maintenance mode."
Expand Down Expand Up @@ -868,8 +869,8 @@ assert_provision_info() {
"@drush -y deploy:hook"
"Executing example operations in non-production environment."
# Assert that DREVOPS_PROVISION_OVERRIDE_DB is correctly passed to the script.
"Fresh database detected. Performing additional operations."
"- Existing database detected. Skipping additional operations."
"Fresh database detected. Performing additional example operations."
"- Existing database detected. Performing additional example operations."
"Completed running of custom post-install script './scripts/custom/provision-10-example.sh'."

# Disabling maintenance mode.
Expand Down
11 changes: 6 additions & 5 deletions scripts/custom/provision-10-example.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
#
# For ordering multiple commands, use a two-digit suffix for clarity and consistency.
# This approach ensures a clear sequence and avoids potential ordering issues.
# Examples:
#
# Example:
# - provision-10-example.sh
# - provision-20-example.sh
# - provision-30-example.sh
Expand All @@ -22,7 +23,7 @@ drush() { ./vendor/bin/drush -y "$@"; }

# Perform operations based on the current environment.
if echo "${DREVOPS_PROVISION_ENVIRONMENT:-}" | grep -q -e dev -e test -e ci -e local; then
echo "[INFO] Executing example operations in non-production environment."
echo "==> Executing example operations in non-production environment."

# Below are examples of running operations.

Expand All @@ -44,10 +45,10 @@ if echo "${DREVOPS_PROVISION_ENVIRONMENT:-}" | grep -q -e dev -e test -e ci -e l

# Conditionally perform an action if this is a "fresh" database.
if [ "${DREVOPS_PROVISION_OVERRIDE_DB:-0}" = "1" ]; then
echo " > Fresh database detected. Performing additional operations."
echo " > Fresh database detected. Performing additional example operations."
else
echo " > Existing database detected. Skipping additional operations."
echo " > Existing database detected. Performing additional example operations."
fi

echo "[ OK ] Finished executing example operations in non-production environment."
echo "==> Finished executing example operations in non-production environment."
fi
53 changes: 29 additions & 24 deletions scripts/drevops/provision.sh
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,10 @@ pass() { [ "${TERM:-}" != "dumb" ] && tput colors >/dev/null 2>&1 && printf "\03
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

yesno() { [ "${1}" = "1" ] && echo "Yes" || echo "No"; }
drush() { ./vendor/bin/drush -y "$@"; }
yesno() { [ "${1}" = "1" ] && echo "Yes" || echo "No"; }

# ------------------------------------------------------------------------------

info "Started site provisioning."

Expand All @@ -80,9 +82,10 @@ info "Started site provisioning."
[ "${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)"
drupal_version="$(drush status --field=drupal-version)"
site_is_installed="$(drush status --fields=bootstrap | grep -q "Successful" && echo "1" || echo "0")"

# Discover the configuration directory path if not set.
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
Expand All @@ -94,27 +97,28 @@ site_has_config="$(test "$(ls -1 ${DRUPAL_CONFIG_PATH}/*.yml 2>/dev/null | wc -l
# Print provisioning information.
################################################################################
echo
note "Webroot dir : ${DREVOPS_WEBROOT}"
note "Profile : ${DRUPAL_PROFILE}"
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}"
note "DB dump file path : ${DREVOPS_DB_DIR}/${DREVOPS_DB_FILE} ($([ -f "${DREVOPS_DB_DIR}/${DREVOPS_DB_FILE}" ] && echo "present" || echo "absent"))"
note "Drupal core version : ${drupal_version}"
note "Drush version : ${drush_version}"
echo
note "Webroot path : $(pwd)/${DREVOPS_WEBROOT}"
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 files 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}"
note "DB dump container image : ${DREVOPS_DB_IMAGE}"
fi
echo
note "Drush version : ${drush_version}"
note "Drupal core version : ${drupal_core_version}"
note "Profile : ${DRUPAL_PROFILE}"
note "Configuration files present : $(yesno "${site_has_config}")"
note "Existing site found : $(yesno "${site_is_installed}")"
echo
note "Install from profile : $(yesno "${DREVOPS_PROVISION_USE_PROFILE}")"
note "Overwrite existing DB : $(yesno "${DREVOPS_PROVISION_OVERRIDE_DB}")"
note "Skip sanitization : $(yesno "${DREVOPS_PROVISION_SANITIZE_DB_SKIP}")"
note "Use maintenance mode : $(yesno "${DREVOPS_PROVISION_USE_MAINTENANCE_MODE}")"
note "Skip post-install operations : $(yesno "${DREVOPS_PROVISION_POST_OPERATIONS_SKIP}")"
note "Configuration files present : $(yesno "${site_has_config}")"
note "Existing site found : $(yesno "${site_is_installed}")"
note "Install from profile : $(yesno "${DREVOPS_PROVISION_USE_PROFILE}")"
note "Overwrite existing DB : $(yesno "${DREVOPS_PROVISION_OVERRIDE_DB}")"
note "Skip DB sanitization : $(yesno "${DREVOPS_PROVISION_SANITIZE_DB_SKIP}")"
note "Skip post-provision operations : $(yesno "${DREVOPS_PROVISION_POST_OPERATIONS_SKIP}")"
note "Use maintenance mode : $(yesno "${DREVOPS_PROVISION_USE_MAINTENANCE_MODE}")"
echo
################################################################################

Expand Down Expand Up @@ -169,8 +173,6 @@ provision_from_profile() {
# The code block below has explicit if-else conditions and verbose output to
# ensure that this significant operation is executed correctly and has
# sufficient output for debugging.
echo

if [ "${DREVOPS_PROVISION_USE_PROFILE}" != "1" ]; then
info "Provisioning site from the database dump file."
note "Dump file path: ${DREVOPS_DB_DIR}/${DREVOPS_DB_FILE}"
Expand Down Expand Up @@ -221,7 +223,7 @@ fi
echo

if [ "${DREVOPS_PROVISION_POST_OPERATIONS_SKIP}" = "1" ]; then
info "Skipped running of post-install operations as DREVOPS_PROVISION_POST_OPERATIONS_SKIP is set to 1."
info "Skipped running of post-provision operations as DREVOPS_PROVISION_POST_OPERATIONS_SKIP is set to 1."
echo
info "Finished site provisioning."
exit 0
Expand All @@ -237,20 +239,22 @@ fi
# Get the current environment and export it for the downstream scripts.
DREVOPS_PROVISION_ENVIRONMENT="$(drush php:eval "print \Drupal\core\Site\Settings::get('environment');")"
info "Current Drupal environment: ${DREVOPS_PROVISION_ENVIRONMENT}"
export DREVOPS_PROVISION_ENVIRONMENT
echo
export DREVOPS_PROVISION_ENVIRONMENT

# Use 'drush deploy' if configuration files are present or use standalone commands otherwise.
if [ "${site_has_config}" = "1" ]; then
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}."
echo
fi

info "Running deployment operations via 'drush deploy'."
drush deploy
pass "Completed deployment operations via 'drush deploy'."
echo

# Import config_split configuration if the module is installed.
# Drush deploy does not import config_split configuration on the first run.
Expand All @@ -260,6 +264,7 @@ if [ "${site_has_config}" = "1" ]; then
info "Importing config_split configuration."
drush config:import
pass "Completed config_split configuration import."
echo
fi
else
info "Running database updates."
Expand All @@ -275,6 +280,7 @@ else
info "Running deployment operations via 'drush deploy:hook'."
drush deploy:hook
pass "Completed deployment operations via 'drush deploy:hook'."
echo
fi

# Sanitize database.
Expand All @@ -291,7 +297,6 @@ fi
if [ -d "./scripts/custom" ]; then
for file in ./scripts/custom/provision-*.sh; do
if [ -f "${file}" ]; then
echo
info "Running custom post-install script '${file}'."
echo
. "${file}"
Expand Down
4 changes: 2 additions & 2 deletions web/sites/default/default.settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@
*
* WARNING: The above defaults are designed for database portability. Changing
* them may cause unexpected behavior, including potential data loss. See
* https://www.drupal.org/developing/api/database/configuration for more
* information on these defaults and the potential issues.
* https://www.drupal.org/docs/8/api/database-api/database-configuration for
* more information on these defaults and the potential issues.
*
* More details can be found in the constructor methods for each driver:
* - \Drupal\mysql\Driver\Database\mysql\Connection::__construct()
Expand Down

1 comment on commit ab9122d

@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.