Skip to content

Commit

Permalink
[#1746] Fixed domain URL replacements in the installer.
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexSkrypnyk committed Jan 19, 2025
1 parent df49e80 commit 28ecd03
Show file tree
Hide file tree
Showing 12 changed files with 60 additions and 89 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ aliases:
#;< SCAFFOLD_DEV
- &renovatebot_git_author 'Renovate Self Hosted <[email protected]>'
#;> SCAFFOLD_DEV
##### - &renovatebot_git_author 'RenovateBot Self Hosted <renovatebot@your-site-url.example>'
##### - &renovatebot_git_author 'RenovateBot Self Hosted <renovatebot@your-site-domain.example>'
# The schedule to run RenovateBot on. Defaults to running twice a day.
- &renovatebot_schedule "5 11,23 * * *"
#;> RENOVATEBOT
Expand Down
8 changes: 4 additions & 4 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ DRUPAL_THEME=your_site_theme
#
# If using Shield, the HTTP authentication credentials will be automatically
# added to the origin URL.
DRUPAL_STAGE_FILE_PROXY_ORIGIN=https://www.your-site-url.example/
DRUPAL_STAGE_FILE_PROXY_ORIGIN=https://www.your-site-domain.example/

# Shield message.
DRUPAL_SHIELD_PRINT="Restricted access."
Expand Down Expand Up @@ -99,7 +99,7 @@ VORTEX_PROVISION_SANITIZE_DB_SKIP=0
#
# Applied if database sanitization is enabled.
# @see https://vortex.drevops.com/workflows/build#sanitization
VORTEX_PROVISION_SANITIZE_DB_EMAIL="user_%uid@your-site-url.example"
VORTEX_PROVISION_SANITIZE_DB_EMAIL="user_%uid@your-site-domain.example"

# Put the site into a maintenance mode during site provisioning.
VORTEX_PROVISION_USE_MAINTENANCE_MODE=1
Expand Down Expand Up @@ -222,14 +222,14 @@ VORTEX_DEPLOY_TYPES=artifact
VORTEX_NOTIFY_CHANNELS=email

# Email to send notifications from.
VORTEX_NOTIFY_EMAIL_FROM="webmaster@your-site-url.example"
VORTEX_NOTIFY_EMAIL_FROM="webmaster@your-site-domain.example"

# Email address(es) to send notifications to.
#
# Multiple names can be specified as a comma-separated list of email addresses
# with optional names in the format "email|name".
# Example: "[email protected]|Jane Doe, [email protected]|John Doe"
VORTEX_NOTIFY_EMAIL_RECIPIENTS="webmaster@your-site-url.example"
VORTEX_NOTIFY_EMAIL_RECIPIENTS="webmaster@your-site-domain.example"
#;> NOTIFICATIONS

#;< DEMO
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/renovate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ jobs:
RENOVATE_DEPENDENCY_DASHBOARD_TITLE: 'Renovate Dependency Dashboard (self-hosted) by GitHub Actions'
RENOVATE_DEPENDENCY_DASHBOARD: ${{ vars.RENOVATE_DEPENDENCY_DASHBOARD || 'false' }}
RENOVATE_DRY_RUN: ${{ vars.RENOVATE_DRY_RUN || 'false' }}
RENOVATE_GIT_AUTHOR: ${{ vars.RENOVATE_GIT_AUTHOR || 'Renovate Self Hosted <renovatebot@your-site-url.example>' }}
RENOVATE_GIT_AUTHOR: ${{ vars.RENOVATE_GIT_AUTHOR || 'Renovate Self Hosted <renovatebot@your-site-domain.example>' }}
8 changes: 4 additions & 4 deletions .lagoon.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,10 @@ environments:
# By default, Lagoon installs Let's Encrypt certificates for all environments.
# routes:
# - nginx-php:
# - www.your-site-url.example:
# - www.your-site-domain.example:
# tls-acme: 'false'
monitoring_urls:
- www.your-site-url.example
- www.your-site-domain.example
# Branch name that represents development environment.
develop:
cronjobs:
Expand All @@ -124,10 +124,10 @@ environments:
# By default, Lagoon installs Let's Encrypt certificates for all environments.
# routes:
# - nginx-php:
# - dev.your-site-url.example:
# - dev.your-site-domain.example:
# tls-acme: 'false'
monitoring_urls:
- dev.your-site-url.example
- dev.your-site-domain.example

routes:
insecure: Redirect
4 changes: 2 additions & 2 deletions .vortex/docs/.utils/variables/extra/.env.variables.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ VORTEX_DB_IMAGE=
VORTEX_DB_IMAGE_BASE=

# Drupal admin email. May need to be reset if database was sanitized.
DRUPAL_ADMIN_EMAIL="webmaster@your-site-url.example"
DRUPAL_ADMIN_EMAIL="webmaster@your-site-domain.example"

# Password replacement used for sanitised database.
VORTEX_PROVISION_SANITIZE_DB_PASSWORD="<RANDOM STRING>"
Expand All @@ -42,7 +42,7 @@ DRUPAL_SITE_NAME="${VORTEX_PROJECT}"

# Drupal site email.
# Used only when installing from profile.
DRUPAL_SITE_EMAIL="webmaster@your-site-url.example"
DRUPAL_SITE_EMAIL="webmaster@your-site-domain.example"

# Print output from Composer install.
VORTEX_COMPOSER_VERBOSE=1
Expand Down
2 changes: 1 addition & 1 deletion .vortex/docs/.utils/variables/extra/ci.variables.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,4 @@ RENOVATE_DEPENDENCY_DASHBOARD=false
RENOVATE_DRY_RUN=false

# Commit author for self-hosted Renovate bot.
RENOVATE_GIT_AUTHOR='Renovate Self Hosted <renovatebot@your-site-url.example>'
RENOVATE_GIT_AUTHOR='Renovate Self Hosted <renovatebot@your-site-domain.example>'
14 changes: 7 additions & 7 deletions .vortex/docs/content/workflows/variables.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ Defined in: `docker-compose.yml`, `scripts/vortex/info.sh`

Drupal admin email. May need to be reset if database was sanitized.

Default value: `webmaster@your-site-url.example`
Default value: `webmaster@your-site-domain.example`

Defined in: `.env`

Expand Down Expand Up @@ -172,7 +172,7 @@ Defined in: `.env`

Drupal site email.<br/>Used only when installing from profile.

Default value: `webmaster@your-site-url.example`
Default value: `webmaster@your-site-domain.example`

Defined in: `.env`, `scripts/vortex/provision.sh`

Expand All @@ -190,7 +190,7 @@ Stage file proxy origin.

If using Shield, the HTTP authentication credentials will be automatically<br/>added to the origin URL.

Default value: `https://www.your-site-url.example/`
Default value: `https://www.your-site-domain.example/`

Defined in: `.env`

Expand Down Expand Up @@ -274,7 +274,7 @@ Defined in: `CI config`

Commit author for self-hosted Renovate bot.

Default value: `'Renovate Self Hosted <renovatebot@your-site-url.example>'`
Default value: `'Renovate Self Hosted <renovatebot@your-site-domain.example>'`

Defined in: `CI config`

Expand Down Expand Up @@ -1242,7 +1242,7 @@ Defined in: `scripts/vortex/notify-email.sh`

Email to send notifications from.

Default value: `webmaster@your-site-url.example`
Default value: `webmaster@your-site-domain.example`

Defined in: `.env`, `scripts/vortex/notify-email.sh`

Expand All @@ -1260,7 +1260,7 @@ Email address(es) to send notifications to.

Multiple names can be specified as a comma-separated list of email addresses<br/>with optional names in the format "email|name".<br/>Example: "[email protected]|Jane Doe, [email protected]|John Doe"

Default value: `webmaster@your-site-url.example`
Default value: `webmaster@your-site-domain.example`

Defined in: `.env`, `scripts/vortex/notify-email.sh`

Expand Down Expand Up @@ -1580,7 +1580,7 @@ Sanitization email pattern.

Applied if database sanitization is enabled.<br/>@see https://vortex.drevops.com/workflows/build#sanitization

Default value: `user_%uid@your-site-url.example`
Default value: `user_%uid@your-site-domain.example`

Defined in: `.env`, `scripts/vortex/provision-sanitize-db.sh`

Expand Down
2 changes: 1 addition & 1 deletion .vortex/installer/src/Command/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ protected function collectAnswers(): void {
$this->askForAnswer('module_prefix', 'What is your project-specific module prefix?');
$this->askForAnswer('profile', 'What is your custom profile machine name (leave empty to use "standard" profile)?');
$this->askForAnswer('theme', 'What is your theme machine name?');
$this->askForAnswer('url', 'What is your site public URL?');
$this->askForAnswer('domain', 'What is your site public domain?');
$this->askForAnswer('webroot', 'Web root (web, docroot)?');

$this->askForAnswer('provision_use_profile', 'Do you want to install from profile (leave empty or "n" for using database?');
Expand Down
101 changes: 36 additions & 65 deletions .vortex/installer/src/Traits/PromptsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ protected function getDefaultValueTheme(): mixed {
return $this->getAnswer('machine_name');
}

protected function getDefaultValueUrl(): string {
protected function getDefaultValueDomain(): string {
$value = $this->getAnswer('machine_name');
$value = str_replace('_', '-', $value);

Expand Down Expand Up @@ -537,35 +537,8 @@ protected function discoverValueTheme(): ?string {
return str_replace(['.info.yml', '.info'], '', $name);
}

protected function discoverValueUrl(): ?string {
$webroot = $this->getAnswer('webroot');

$origin = NULL;
$path = $this->config->getDstDir() . sprintf('/%s/sites/default/settings.php', $webroot);

if (!is_readable($path)) {
return NULL;
}

$contents = file_get_contents($path);
if (!$contents) {
return NULL;
}

// Drupal 8 and 9.
if (preg_match('/\$config\s*\[\'stage_file_proxy.settings\'\]\s*\[\'origin\'\]\s*=\s*[\'"]([^\'"]+)[\'"];/', $contents, $matches)) {
$origin = $matches[1];
}
// Drupal 7.
elseif (preg_match('/\$conf\s*\[\'stage_file_proxy_origin\'\]\s*=\s*[\'"]([^\'"]+)[\'"];/', $contents, $matches)) {
$origin = $matches[1];
}

if ($origin) {
$origin = parse_url($origin, PHP_URL_HOST);
}

return empty($origin) ? NULL : $origin;
protected function discoverValueDomain(): ?string {
return $this->getValueFromDstDotenv('DRUPAL_STAGE_FILE_PROXY_ORIGIN');
}

protected function discoverValueWebroot(): ?string {
Expand Down Expand Up @@ -718,10 +691,13 @@ protected function normaliseAnswerTheme(string $value): string {
return Converter::toMachineName($value);
}

protected function normaliseAnswerUrl(string $url): string {
$url = trim($url);
protected function normaliseAnswerDomain(string $value): string {
$value = trim($value);
$value = rtrim($value, '/');
$value = str_replace([' ', '_'], '-', $value);
$value = preg_replace('/^https?:\/\//', '', $value);

return str_replace([' ', '_'], '-', $url);
return preg_replace('/^www\./', '', $value);
}

protected function normaliseAnswerWebroot(string $value): string {
Expand Down Expand Up @@ -904,43 +880,38 @@ protected function processStringTokens(string $dir): void {
$module_prefix_uppercase = strtoupper($module_prefix_camel_cased);
$theme_camel_cased = Converter::toCamelCase($this->getAnswer('theme'), TRUE);
$vortex_version_urlencoded = str_replace('-', '--', (string) $this->config->get('VORTEX_VERSION'));
$url = $this->getAnswer('url');
$host = parse_url($url, PHP_URL_HOST);
$domain = $host ?: $url;
$domain_non_www = str_starts_with((string) $domain, "www.") ? substr((string) $domain, 4) : $domain;
$webroot = $this->getAnswer('webroot');

// @formatter:off
// phpcs:disable Generic.Functions.FunctionCallArgumentSpacing.TooMuchSpaceAfterComma
// phpcs:disable Drupal.WhiteSpace.Comma.TooManySpaces
File::dirReplaceContent('your_site_theme', $this->getAnswer('theme'), $dir);
File::dirReplaceContent('YourSiteTheme', $theme_camel_cased, $dir);
File::dirReplaceContent('your_org', $this->getAnswer('org_machine_name'), $dir);
File::dirReplaceContent('YOURORG', $this->getAnswer('org'), $dir);
File::dirReplaceContent('www.your-site-url.example', $domain, $dir);
File::dirReplaceContent('your-site-url.example', $domain_non_www, $dir);
File::dirReplaceContent('ys_core', $this->getAnswer('module_prefix') . '_core', $dir . sprintf('/%s/modules/custom', $webroot));
File::dirReplaceContent('ys_search', $this->getAnswer('module_prefix') . '_search', $dir . sprintf('/%s/modules/custom', $webroot));
File::dirReplaceContent('ys_core', $this->getAnswer('module_prefix') . '_core', $dir . sprintf('/%s/themes/custom', $webroot));
File::dirReplaceContent('ys_core', $this->getAnswer('module_prefix') . '_core', $dir . '/scripts/custom');
File::dirReplaceContent('ys_search', $this->getAnswer('module_prefix') . '_search', $dir . '/scripts/custom');
File::dirReplaceContent('YsCore', $module_prefix_camel_cased . 'Core', $dir . sprintf('/%s/modules/custom', $webroot));
File::dirReplaceContent('YsSearch', $module_prefix_camel_cased . 'Search', $dir . sprintf('/%s/modules/custom', $webroot));
File::dirReplaceContent('YSCODE', $module_prefix_uppercase, $dir);
File::dirReplaceContent('YSSEARCH', $module_prefix_uppercase, $dir);
File::dirReplaceContent('your-site', $machine_name_hyphenated, $dir);
File::dirReplaceContent('your_site', $this->getAnswer('machine_name'), $dir);
File::dirReplaceContent('YOURSITE', $this->getAnswer('name'), $dir);
File::dirReplaceContent('YourSite', $machine_name_camel_cased, $dir);

File::replaceStringFilename('YourSiteTheme', $theme_camel_cased, $dir);
File::replaceStringFilename('your_site_theme', $this->getAnswer('theme'), $dir);
File::replaceStringFilename('YourSite', $machine_name_camel_cased, $dir);
File::replaceStringFilename('ys_core', $this->getAnswer('module_prefix') . '_core', $dir . sprintf('/%s/modules/custom', $webroot));
File::replaceStringFilename('ys_search', $this->getAnswer('module_prefix') . '_search', $dir . sprintf('/%s/modules/custom', $webroot));
File::replaceStringFilename('YsCore', $module_prefix_camel_cased . 'Core', $dir . sprintf('/%s/modules/custom', $webroot));
File::replaceStringFilename('your_org', $this->getAnswer('org_machine_name'), $dir);
File::replaceStringFilename('your_site', $this->getAnswer('machine_name'), $dir);
File::dirReplaceContent('your_site_theme', $this->getAnswer('theme'), $dir);
File::dirReplaceContent('YourSiteTheme', $theme_camel_cased, $dir);
File::dirReplaceContent('your_org', $this->getAnswer('org_machine_name'), $dir);
File::dirReplaceContent('YOURORG', $this->getAnswer('org'), $dir);
File::dirReplaceContent('your-site-domain.example', $this->getAnswer('domain'), $dir);
File::dirReplaceContent('ys_core', $this->getAnswer('module_prefix') . '_core', $dir . sprintf('/%s/modules/custom', $webroot));
File::dirReplaceContent('ys_search', $this->getAnswer('module_prefix') . '_search', $dir . sprintf('/%s/modules/custom', $webroot));
File::dirReplaceContent('ys_core', $this->getAnswer('module_prefix') . '_core', $dir . sprintf('/%s/themes/custom', $webroot));
File::dirReplaceContent('ys_core', $this->getAnswer('module_prefix') . '_core', $dir . '/scripts/custom');
File::dirReplaceContent('ys_search', $this->getAnswer('module_prefix') . '_search', $dir . '/scripts/custom');
File::dirReplaceContent('YsCore', $module_prefix_camel_cased . 'Core', $dir . sprintf('/%s/modules/custom', $webroot));
File::dirReplaceContent('YsSearch', $module_prefix_camel_cased . 'Search', $dir . sprintf('/%s/modules/custom', $webroot));
File::dirReplaceContent('YSCODE', $module_prefix_uppercase, $dir);
File::dirReplaceContent('YSSEARCH', $module_prefix_uppercase, $dir);
File::dirReplaceContent('your-site', $machine_name_hyphenated, $dir);
File::dirReplaceContent('your_site', $this->getAnswer('machine_name'), $dir);
File::dirReplaceContent('YOURSITE', $this->getAnswer('name'), $dir);
File::dirReplaceContent('YourSite', $machine_name_camel_cased, $dir);

File::replaceStringFilename('YourSiteTheme', $theme_camel_cased, $dir);
File::replaceStringFilename('your_site_theme', $this->getAnswer('theme'), $dir);
File::replaceStringFilename('YourSite', $machine_name_camel_cased, $dir);
File::replaceStringFilename('ys_core', $this->getAnswer('module_prefix') . '_core', $dir . sprintf('/%s/modules/custom', $webroot));
File::replaceStringFilename('ys_search', $this->getAnswer('module_prefix') . '_search', $dir . sprintf('/%s/modules/custom', $webroot));
File::replaceStringFilename('YsCore', $module_prefix_camel_cased . 'Core', $dir . sprintf('/%s/modules/custom', $webroot));
File::replaceStringFilename('your_org', $this->getAnswer('org_machine_name'), $dir);
File::replaceStringFilename('your_site', $this->getAnswer('machine_name'), $dir);

File::dirReplaceContent('VORTEX_VERSION_URLENCODED', $vortex_version_urlencoded, $dir);
File::dirReplaceContent('VORTEX_VERSION', $this->config->get('VORTEX_VERSION'), $dir);
Expand Down
2 changes: 1 addition & 1 deletion .vortex/installer/src/Traits/TuiTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ protected function printSummary(): void {
$values['Module prefix'] = $this->getAnswer('module_prefix');
$values['Profile'] = $this->getAnswer('profile');
$values['Theme name'] = $this->getAnswer('theme');
$values['URL'] = $this->getAnswer('url');
$values['Domain'] = $this->getAnswer('domain');
$values['Web root'] = $this->getAnswer('webroot');

$values['Install from profile'] = $this->formatYesNo($this->getAnswer('provision_use_profile'));
Expand Down
2 changes: 1 addition & 1 deletion .vortex/tests/bats/_helper.bash
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ assert_files_present_drupal() {
assert_dir_not_contains_string "${dir}" "your_site_theme"
assert_dir_not_contains_string "${dir}" "your_org"
assert_dir_not_contains_string "${dir}" "YOURORG"
assert_dir_not_contains_string "${dir}" "www.your-site-url.example"
assert_dir_not_contains_string "${dir}" "www.your-site-domain.example"
# Assert all special comments were removed.
assert_dir_not_contains_string "${dir}" "#;"
assert_dir_not_contains_string "${dir}" "#;<"
Expand Down
2 changes: 1 addition & 1 deletion hooks/library/domains.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
$TARGET_ENV_REMAP.your-site-url.example
$TARGET_ENV_REMAP.your-site-domain.example

1 comment on commit 28ecd03

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