Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#1236] Moved provider settings in their own files. #1268

Merged
merged 1 commit into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .scaffold/tests/bats/_helper.bash
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,7 @@ assert_files_present_integration_acquia() {
assert_symlink_exists "hooks/prod/post-code-update"
assert_symlink_not_exists "hooks/prod/post-db-copy"

assert_file_contains "${webroot}/sites/default/settings.php" "if (file_exists('/var/www/site-php"
assert_file_exists "${webroot}/sites/default/includes/providers/settings.acquia.php"
assert_file_contains "${webroot}/.htaccess" "RewriteCond %{ENV:AH_SITE_ENVIRONMENT} prod [NC]"

if [ "${include_scripts:-}" -eq 1 ]; then
Expand All @@ -751,7 +751,7 @@ assert_files_present_no_integration_acquia() {

assert_dir_not_exists "hooks"
assert_dir_not_exists "hooks/library"
assert_file_not_contains "${webroot}/sites/default/settings.php" "if (file_exists('/var/www/site-php')) {"
assert_file_not_exists "${webroot}sites/default/includes/providers/settings.acquia.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_DB_NAME="
Expand All @@ -770,6 +770,7 @@ assert_files_present_integration_lagoon() {

pushd "${dir}" >/dev/null || exit 1

assert_file_exists "${webroot}/sites/default/includes/providers/settings.lagoon.php"
assert_file_exists ".lagoon.yml"
assert_file_exists "drush/sites/lagoon.site.yml"
assert_file_exists ".github/workflows/close-pull-request.yml"
Expand All @@ -793,6 +794,7 @@ assert_files_present_no_integration_lagoon() {

pushd "${dir}" >/dev/null || exit 1

assert_file_not_exists "${webroot}/sites/default/includes/providers/settings.lagoon.php"
assert_file_not_exists ".lagoon.yml"
assert_file_not_exists "drush/sites/lagoon.site.yml"
assert_file_not_exists ".github/workflows/close-pull-request.yml"
Expand Down
38 changes: 38 additions & 0 deletions web/sites/default/includes/providers/settings.acquia.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

/**
* @file
* Acquia hosting provider settings.
*
* @see https://docs.acquia.com/acquia-cloud/develop/env-variable
*/

if (!empty(getenv('AH_SITE_ENVIRONMENT'))) {
// Delay the initial database connection.
$config['acquia_hosting_settings_autoconnect'] = FALSE;

// Include Acquia environment settings.
if (file_exists('/var/www/site-php/your_site/your_site-settings.inc')) {
// @codeCoverageIgnoreStart
require '/var/www/site-php/your_site/your_site-settings.inc';
$settings['config_sync_directory'] = $settings['config_vcs_directory'];
// @codeCoverageIgnoreEnd
}

// Default all environments to 'dev', including ODE environments.
$settings['environment'] = ENVIRONMENT_DEV;

// Do not put any Acquia-specific settings in this code block. It is used
// to explicitly map Acquia environments to $settings['environment']
// variable only.
// Instead, use 'PER-ENVIRONMENT SETTINGS' section below.
switch (getenv('AH_SITE_ENVIRONMENT')) {
case 'prod':
$settings['environment'] = ENVIRONMENT_PROD;
break;

case 'test':
$settings['environment'] = ENVIRONMENT_TEST;
break;
}
}
64 changes: 64 additions & 0 deletions web/sites/default/includes/providers/settings.lagoon.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

/**
* @file
* Lagoon hosting provider settings.
*/

if (getenv('LAGOON') && getenv('LAGOON_ENVIRONMENT_TYPE') == 'production' || getenv('LAGOON_ENVIRONMENT_TYPE') == 'development') {
// Do not put any Lagoon-specific settings in this code block. It is used
// to explicitly map Lagoon environments to $settings['environment']
// variable only.
// Instead, use 'PER-ENVIRONMENT SETTINGS' section below.
//
// Environment is marked as 'production' in Lagoon.
if (getenv('LAGOON_ENVIRONMENT_TYPE') == 'production') {
$settings['environment'] = ENVIRONMENT_PROD;
}
// All other environments running in Lagoon are considered 'development'.
else {
// Any other environment is considered 'development' in Lagoon.
$settings['environment'] = ENVIRONMENT_DEV;

// But try to identify production environment using a branch name for
// the cases when 'production' Lagoon environment is not provisioned yet.
if (!empty(getenv('LAGOON_GIT_BRANCH')) && !empty(getenv('DREVOPS_LAGOON_PRODUCTION_BRANCH')) && getenv('LAGOON_GIT_BRANCH') === getenv('DREVOPS_LAGOON_PRODUCTION_BRANCH')) {
$settings['environment'] = ENVIRONMENT_PROD;
}
// Dedicated test environment based on a branch name.
elseif (getenv('LAGOON_GIT_BRANCH') == 'master') {
$settings['environment'] = ENVIRONMENT_TEST;
}
// Test environment based on a branch prefix for release and
// hotfix branches.
elseif (!empty(getenv('LAGOON_GIT_BRANCH')) && (str_starts_with(getenv('LAGOON_GIT_BRANCH'), 'release/') || str_starts_with(getenv('LAGOON_GIT_BRANCH'), 'hotfix/'))) {
$settings['environment'] = ENVIRONMENT_TEST;
}
}

// Lagoon version.
if (!defined('LAGOON_VERSION')) {
define('LAGOON_VERSION', '1');
}

// Lagoon reverse proxy settings.
$settings['reverse_proxy'] = TRUE;
// Reverse proxy settings.
$settings['reverse_proxy_header'] = 'HTTP_TRUE_CLIENT_IP';

// Cache prefix.
$settings['cache_prefix']['default'] = (getenv('LAGOON_PROJECT') ?: getenv('DREVOPS_PROJECT')) . '_' . (getenv('LAGOON_GIT_SAFE_BRANCH') ?: getenv('DREVOPS_LAGOON_PRODUCTION_BRANCH'));

// Trusted host patterns for Lagoon internal routes.
// URL when accessed from PHP processes in Lagoon.
$settings['trusted_host_patterns'][] = '^nginx\-php$';
// Lagoon URL.
$settings['trusted_host_patterns'][] = '^.+\.au\.amazee\.io$';
// Lagoon routes.
if (getenv('LAGOON_ROUTES')) {
$patterns = str_replace(['.', 'https://', 'http://', ','], [
'\.', '', '', '|',
], getenv('LAGOON_ROUTES'));
$settings['trusted_host_patterns'][] = '^' . $patterns . '$';
}
}
105 changes: 11 additions & 94 deletions web/sites/default/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* The structure of this file:
* - Environment constants definitions.
* - Site-specific settings.
* - Environment variable initialisation.
* - Inclusion of hosting providers settings.
* - Per-environment overrides.
* - Inclusion of local settings.
*
Expand Down Expand Up @@ -124,109 +124,26 @@
];

////////////////////////////////////////////////////////////////////////////////
/// ENVIRONMENT-SPECIFIC SETTINGS ///
/// ENVIRONMENT DETECTION ///
////////////////////////////////////////////////////////////////////////////////

// #;< ACQUIA
// Initialise environment type in Acquia environment.
// @see https://docs.acquia.com/acquia-cloud/develop/env-variable
if (!empty(getenv('AH_SITE_ENVIRONMENT'))) {
// Delay the initial database connection.
$config['acquia_hosting_settings_autoconnect'] = FALSE;
// Include Acquia environment settings.
if (file_exists('/var/www/site-php/your_site/your_site-settings.inc')) {
// @codeCoverageIgnoreStart
require '/var/www/site-php/your_site/your_site-settings.inc';
$settings['config_sync_directory'] = $settings['config_vcs_directory'];
// @codeCoverageIgnoreEnd
}
// Default all environments to 'dev', including ODE environments.
$settings['environment'] = ENVIRONMENT_DEV;

// Do not put any Acquia-specific settings in this code block. It is used
// to explicitly map Acquia environments to $settings['environment']
// variable only.
// Instead, use 'PER-ENVIRONMENT SETTINGS' section below.
switch (getenv('AH_SITE_ENVIRONMENT')) {
case 'prod':
$settings['environment'] = ENVIRONMENT_PROD;
break;

case 'test':
$settings['environment'] = ENVIRONMENT_TEST;
break;
}
}
// #;> ACQUIA

// #;< LAGOON
// Initialise environment type in Lagoon environment.
if (getenv('LAGOON') && getenv('LAGOON_ENVIRONMENT_TYPE') == 'production' || getenv('LAGOON_ENVIRONMENT_TYPE') == 'development') {
// Do not put any Lagoon-specific settings in this code block. It is used
// to explicitly map Lagoon environments to $settings['environment']
// variable only.
// Instead, use 'PER-ENVIRONMENT SETTINGS' section below.
//
// Environment is marked as 'production' in Lagoon.
if (getenv('LAGOON_ENVIRONMENT_TYPE') == 'production') {
$settings['environment'] = ENVIRONMENT_PROD;
}
// All other environments running in Lagoon are considered 'development'.
else {
// Any other environment is considered 'development' in Lagoon.
$settings['environment'] = ENVIRONMENT_DEV;

// But try to identify production environment using a branch name for
// the cases when 'production' Lagoon environment is not provisioned yet.
if (!empty(getenv('LAGOON_GIT_BRANCH')) && !empty(getenv('DREVOPS_LAGOON_PRODUCTION_BRANCH')) && getenv('LAGOON_GIT_BRANCH') === getenv('DREVOPS_LAGOON_PRODUCTION_BRANCH')) {
$settings['environment'] = ENVIRONMENT_PROD;
}
// Dedicated test environment based on a branch name.
elseif (getenv('LAGOON_GIT_BRANCH') == 'master') {
$settings['environment'] = ENVIRONMENT_TEST;
}
// Test environment based on a branch prefix for release and
// hotfix branches.
elseif (!empty(getenv('LAGOON_GIT_BRANCH')) && (str_starts_with(getenv('LAGOON_GIT_BRANCH'), 'release/') || str_starts_with(getenv('LAGOON_GIT_BRANCH'), 'hotfix/'))) {
$settings['environment'] = ENVIRONMENT_TEST;
// Load environment-specific settings.
if (file_exists($app_root . '/' . $site_path . '/includes/providers')) {
$files = glob($app_root . '/' . $site_path . '/includes/providers/settings.*.php');
if ($files) {
foreach ($files as $filename) {
require $filename;
}
}

// Lagoon version.
if (!defined('LAGOON_VERSION')) {
define('LAGOON_VERSION', '1');
}

// Lagoon reverse proxy settings.
$settings['reverse_proxy'] = TRUE;
// Reverse proxy settings.
$settings['reverse_proxy_header'] = 'HTTP_TRUE_CLIENT_IP';

// Cache prefix.
$settings['cache_prefix']['default'] = (getenv('LAGOON_PROJECT') ?: getenv('DREVOPS_PROJECT')) . '_' . (getenv('LAGOON_GIT_SAFE_BRANCH') ?: getenv('DREVOPS_LAGOON_PRODUCTION_BRANCH'));

// Trusted host patterns for Lagoon internal routes.
// URL when accessed from PHP processes in Lagoon.
$settings['trusted_host_patterns'][] = '^nginx\-php$';
// Lagoon URL.
$settings['trusted_host_patterns'][] = '^.+\.au\.amazee\.io$';
// Lagoon routes.
if (getenv('LAGOON_ROUTES')) {
$patterns = str_replace(['.', 'https://', 'http://', ','], [
'\.', '', '', '|',
], getenv('LAGOON_ROUTES'));
$settings['trusted_host_patterns'][] = '^' . $patterns . '$';
}
}
// #;> LAGOON

// Allow overriding of an environment type.
if (!empty(getenv('DRUPAL_ENVIRONMENT'))) {
$settings['environment'] = getenv('DRUPAL_ENVIRONMENT');
}

////////////////////////////////////////////////////////////////////////////////
/// ENVIRONMENT DETECTION ///
/// ENVIRONMENT-SPECIFIC SETTINGS ///
////////////////////////////////////////////////////////////////////////////////

if ($settings['environment'] == ENVIRONMENT_CI) {
Expand Down Expand Up @@ -255,8 +172,8 @@
/// PER-MODULE SETTINGS ///
////////////////////////////////////////////////////////////////////////////////

if (file_exists($app_root . '/' . $site_path . '/includes')) {
$files = glob($app_root . '/' . $site_path . '/includes/settings.*.php');
if (file_exists($app_root . '/' . $site_path . '/includes/modules')) {
$files = glob($app_root . '/' . $site_path . '/includes/modules/settings.*.php');
if ($files) {
foreach ($files as $filename) {
require $filename;
Expand Down
Loading