Skip to content

Commit c34d01f

Browse files
committed
[#1967] Added support for Hosting project name.
1 parent c99b335 commit c34d01f

205 files changed

Lines changed: 6994 additions & 231 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.vortex/docs/static/img/installer.json

Lines changed: 123 additions & 229 deletions
Large diffs are not rendered by default.

.vortex/docs/static/img/installer.svg

Lines changed: 1 addition & 1 deletion
Loading
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace DrevOps\VortexInstaller\Prompts\Handlers;
6+
7+
use DrevOps\VortexInstaller\Utils\Converter;
8+
use DrevOps\VortexInstaller\Utils\Env;
9+
use DrevOps\VortexInstaller\Utils\File;
10+
11+
class HostingProjectName extends AbstractHandler {
12+
13+
/**
14+
* {@inheritdoc}
15+
*/
16+
public function label(): string {
17+
return 'Hosting project name';
18+
}
19+
20+
/**
21+
* {@inheritdoc}
22+
*/
23+
public function hint(array $responses): ?string {
24+
return 'Name as found in the hosting configuration. Usually the same as the site machine name.';
25+
}
26+
27+
/**
28+
* {@inheritdoc}
29+
*/
30+
public function placeholder(array $responses): ?string {
31+
return 'E.g. my_site';
32+
}
33+
34+
/**
35+
* {@inheritdoc}
36+
*/
37+
public function isRequired(): bool {
38+
return TRUE;
39+
}
40+
41+
/**
42+
* {@inheritdoc}
43+
*/
44+
public function shouldRun(array $responses): bool {
45+
return isset($responses[HostingProvider::id()]) &&
46+
(
47+
$responses[HostingProvider::id()] === HostingProvider::LAGOON ||
48+
$responses[HostingProvider::id()] === HostingProvider::ACQUIA
49+
);
50+
}
51+
52+
/**
53+
* {@inheritdoc}
54+
*/
55+
public function default(array $responses): null|string|bool|array {
56+
if (isset($responses[MachineName::id()]) && !empty($responses[MachineName::id()])) {
57+
return $responses[MachineName::id()];
58+
}
59+
60+
return NULL;
61+
}
62+
63+
/**
64+
* {@inheritdoc}
65+
*/
66+
public function discover(): null|string|bool|array {
67+
// Try Acquia.
68+
$v = Env::getFromDotenv('VORTEX_ACQUIA_APP_NAME', $this->dstDir);
69+
if (!empty($v)) {
70+
return $v;
71+
}
72+
73+
// Try to discover from settings.acquia.php.
74+
$acquia_settings_file = $this->dstDir . sprintf('/%s/sites/default/includes/providers/settings.acquia.php', $this->webroot);
75+
if (file_exists($acquia_settings_file)) {
76+
$content = file_get_contents($acquia_settings_file);
77+
// Require '/var/www/site-php/your_site/your_site-settings.inc';.
78+
if ($content !== FALSE && preg_match('/require\s+[\'"]\/var\/www\/site-php\/([a-z0-9_]+)\/[a-z0-9_]+-settings\.inc[\'"]\s*;/', $content, $matches) && !empty($matches[1])) {
79+
return $matches[1];
80+
}
81+
}
82+
83+
// Try Lagoon.
84+
$v = Env::getFromDotenv('LAGOON_PROJECT', $this->dstDir);
85+
if (!empty($v)) {
86+
return $v;
87+
}
88+
89+
// Try to discover from drush/sites/lagoon.site.yml.
90+
$lagoon_site_file = $this->dstDir . '/drush/sites/lagoon.site.yml';
91+
if (file_exists($lagoon_site_file)) {
92+
$content = file_get_contents($lagoon_site_file);
93+
if ($content !== FALSE && preg_match('/user:\s*([a-z0-9_]+)-/', $content, $matches) && (!empty($matches[1]) && $matches[1] !== 'your_site')) {
94+
return $matches[1];
95+
}
96+
}
97+
98+
return NULL;
99+
}
100+
101+
/**
102+
* {@inheritdoc}
103+
*/
104+
public function validate(): ?callable {
105+
return fn($v): ?string => Converter::phpPackageName($v) !== $v ? 'Please enter a valid machine name: only lowercase letters, numbers, hyphens and underscores are allowed.' : NULL;
106+
}
107+
108+
/**
109+
* {@inheritdoc}
110+
*/
111+
public function transform(): ?callable {
112+
return fn(string $v): string => trim($v);
113+
}
114+
115+
/**
116+
* {@inheritdoc}
117+
*/
118+
public function process(): void {
119+
$v = $this->getResponseAsString();
120+
$t = $this->tmpDir;
121+
$w = $this->webroot;
122+
123+
Env::writeValueDotenv('VORTEX_ACQUIA_APP_NAME', $v, $t . '/.env');
124+
File::replaceContentInFile($t . '/' . $w . '/sites/default/includes/providers/settings.acquia.php', 'your_site', $v);
125+
126+
Env::writeValueDotenv('LAGOON_PROJECT', $v, $t . '/.env');
127+
File::replaceContentInFile($t . '/drush/sites/lagoon.site.yml', 'your_site-${env-name}', $v . '-${env-name}');
128+
File::replaceContentInFile($t . '/drush/sites/lagoon.site.yml', '.your_site.au2.amazee.io', '.' . $v . '.au2.amazee.io');
129+
}
130+
131+
}

.vortex/installer/src/Prompts/PromptManager.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use DrevOps\VortexInstaller\Prompts\Handlers\Domain;
1717
use DrevOps\VortexInstaller\Prompts\Handlers\Dotenv;
1818
use DrevOps\VortexInstaller\Prompts\Handlers\HandlerInterface;
19+
use DrevOps\VortexInstaller\Prompts\Handlers\HostingProjectName;
1920
use DrevOps\VortexInstaller\Prompts\Handlers\HostingProvider;
2021
use DrevOps\VortexInstaller\Prompts\Handlers\Internal;
2122
use DrevOps\VortexInstaller\Prompts\Handlers\LabelMergeConflictsPr;
@@ -62,7 +63,7 @@ class PromptManager {
6263
*
6364
* Used to display the progress of the prompts.
6465
*/
65-
const TOTAL_RESPONSES = 25;
66+
const TOTAL_RESPONSES = 26;
6667

6768
/**
6869
* Array of responses.
@@ -158,6 +159,11 @@ function (array $r, $pr, $n): string {
158159

159160
->intro('Hosting')
160161
->add(fn($r, $pr, $n): int|string => select(...$this->args(HostingProvider::class)), HostingProvider::id())
162+
->addIf(
163+
fn($r): bool => $this->handlers[HostingProjectName::id()]->shouldRun($r),
164+
fn($r, $pr, $n): string => text(...$this->args(HostingProjectName::class, NULL, $r)),
165+
HostingProjectName::id()
166+
)
161167
->add(
162168
function (array $r, $pr, $n): string {
163169
return $this->resolveOrPrompt(Webroot::id(), $r, fn(): string => text(...$this->args(Webroot::class, NULL, $r)));
@@ -278,6 +284,7 @@ public function runProcessors(): void {
278284
ProfileCustom::id(),
279285
Profile::id(),
280286
Domain::id(),
287+
HostingProjectName::id(),
281288
ModulePrefix::id(),
282289
ThemeCustom::id(),
283290
Theme::id(),
@@ -379,6 +386,9 @@ public function getResponsesSummary(): array {
379386

380387
$values['Hosting'] = Tui::LIST_SECTION_TITLE;
381388
$values['Hosting provider'] = $responses[HostingProvider::id()];
389+
if ($responses[HostingProvider::id()] == HostingProvider::LAGOON) {
390+
$values['Lagoon project name'] = $responses[HostingProjectName::id()];
391+
}
382392

383393
$values['Deployment'] = Tui::LIST_SECTION_TITLE;
384394
$values['Deployment types'] = Converter::toList($responses[DeployType::id()]);
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
@@ -16,7 +16,7 @@
2+
ARG LAGOON_PR_HEAD_SHA=""
3+
ENV LAGOON_PR_HEAD_SHA=${LAGOON_PR_HEAD_SHA}
4+
5+
-ARG WEBROOT=web
6+
+ARG WEBROOT=docroot
7+
ENV WEBROOT=${WEBROOT}
8+
9+
# Token is used to access private repositories. Not exposed as an environment
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
@@ -14,7 +14,7 @@
2+
FROM uselagoon/nginx-drupal:__VERSION__
3+
4+
# Webroot is used for Nginx web root configuration.
5+
-ARG WEBROOT=web
6+
+ARG WEBROOT=docroot
7+
ENV WEBROOT=${WEBROOT}
8+
9+
RUN apk add --no-cache tzdata
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
@@ -8,17 +8,17 @@
2+
*
3+
4+
# Do not ignore web.
5+
-!web
6+
+!docroot
7+
8+
# Do not ignore config.
9+
!config
10+
11+
# But still ignore Drupal directories generated by Composer.
12+
-web/core
13+
-web/modules/contrib
14+
-web/themes/contrib
15+
-web/profiles/contrib
16+
-web/libraries
17+
+docroot/core
18+
+docroot/modules/contrib
19+
+docroot/themes/contrib
20+
+docroot/profiles/contrib
21+
+docroot/libraries
22+
!drush
23+
drush/contrib/
24+
25+
@@ -51,3 +51,5 @@
26+
!rector.php
27+
!scripts
28+
!tests
29+
+
30+
+!hooks
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
@@ -29,7 +29,7 @@
2+
VORTEX_PROJECT=star_wars
3+
4+
# Name of the web root directory containing a Drupal codebase.
5+
-WEBROOT=web
6+
+WEBROOT=docroot
7+
8+
# The timezone used within the containers.
9+
TZ=UTC
10+
@@ -120,6 +120,13 @@
11+
VORTEX_PROVISION_USE_MAINTENANCE_MODE=1
12+
13+
################################################################################
14+
+# HOSTING #
15+
+################################################################################
16+
+
17+
+# Acquia application name.
18+
+VORTEX_ACQUIA_APP_NAME=my_custom_acquia-project
19+
+
20+
+################################################################################
21+
# DATABASE SOURCE #
22+
################################################################################
23+
24+
@@ -142,13 +149,8 @@
25+
VORTEX_DB_FILE=db.sql
26+
27+
# Database download source.
28+
-VORTEX_DB_DOWNLOAD_SOURCE=url
29+
+VORTEX_DB_DOWNLOAD_SOURCE=acquia
30+
31+
-# Database dump file sourced from a URL.
32+
-#
33+
-# HTTP Basic Authentication credentials should be embedded into the value.
34+
-VORTEX_DB_DOWNLOAD_URL=
35+
-
36+
# Environment to download the database from.
37+
#
38+
# Applies to hosting environments.
39+
@@ -156,6 +158,9 @@
40+
# a branch name or an environment name.
41+
VORTEX_DB_DOWNLOAD_ENVIRONMENT=prod
42+
43+
+# Acquia database name to download the database from.
44+
+VORTEX_DB_DOWNLOAD_ACQUIA_DB_NAME=star_wars
45+
+
46+
################################################################################
47+
# DEPLOYMENT #
48+
################################################################################
49+
@@ -162,7 +167,7 @@
50+
51+
# Deployment occurs when tests pass in the CI environment.
52+
# @see https://www.vortextemplate.com/docs/workflows/deployment
53+
-VORTEX_DEPLOY_TYPES=webhook
54+
+VORTEX_DEPLOY_TYPES=artifact
55+
56+
################################################################################
57+
# NOTIFICATIONS #
58+
@@ -179,7 +184,7 @@
59+
# An email address to send notifications from.
60+
#
61+
# Applies to email notifications.
62+
-VORTEX_NOTIFY_EMAIL_FROM=webmaster@star-wars.com
63+
+VORTEX_NOTIFY_EMAIL_FROM=docrootmaster@star-wars.com
64+
65+
# Email address(es) to send notifications to.
66+
#
67+
@@ -189,17 +194,3 @@
68+
# with optional names in the format "email|name".
69+
# Example: "to1@example.com|Jane Doe, to2@example.com|John Doe"
70+
VORTEX_NOTIFY_EMAIL_RECIPIENTS="webmaster@star-wars.com|Webmaster"
71+
-
72+
-################################################################################
73+
-# DEMO #
74+
-################################################################################
75+
-# #
76+
-# Override project-specific values for demonstration purposes. #
77+
-# Used to showcase Vortex without asking users to perform additional steps. #
78+
-# #
79+
-# Remove this section after completing database download integration. #
80+
-# #
81+
-################################################################################
82+
-
83+
-# URL of the database used for demonstration with URL database download type.
84+
-VORTEX_DB_DOWNLOAD_URL=https://github.com/drevops/vortex/releases/download/25.4.0/db_d11.demo.sql
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
@@ -32,3 +32,11 @@
2+
3+
# Always override existing downloaded DB dump.
4+
VORTEX_DB_DOWNLOAD_FORCE=1
5+
+
6+
+# Database dump file sourced from Acquia.
7+
+# Acquia Cloud API token: Acquia Cloud UI -> Account -> API tokens -> Create Token
8+
+
9+
+# Acquia Cloud API key.
10+
+VORTEX_ACQUIA_KEY=
11+
+# Acquia Cloud API secret.
12+
+VORTEX_ACQUIA_SECRET=
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
@@ -32,3 +32,11 @@
2+
3+
# Always override existing downloaded DB dump.
4+
VORTEX_DB_DOWNLOAD_FORCE=1
5+
+
6+
+# Database dump file sourced from Acquia.
7+
+# Acquia Cloud API token: Acquia Cloud UI -> Account -> API tokens -> Create Token
8+
+
9+
+# Acquia Cloud API key.
10+
+VORTEX_ACQUIA_KEY=
11+
+# Acquia Cloud API secret.
12+
+VORTEX_ACQUIA_SECRET=

0 commit comments

Comments
 (0)