Skip to content

Commit 9d139b7

Browse files
committed
Converted the rest of the scripts and cleaned up tests.
1 parent cd52bc6 commit 9d139b7

57 files changed

Lines changed: 5159 additions & 3704 deletions

Some content is hidden

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

.vortex/CLAUDE.md

Lines changed: 3 additions & 1614 deletions
Large diffs are not rendered by default.

.vortex/tooling/CLAUDE.md

Lines changed: 0 additions & 677 deletions
Large diffs are not rendered by default.

.vortex/tooling/scripts_conversion_plan.md

Lines changed: 0 additions & 1257 deletions
This file was deleted.

.vortex/tooling/src/deploy-artifact

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -70,35 +70,23 @@ info('Started ARTIFACT deployment.');
7070
$global_git_name = trim((string) shell_exec('git config --global user.name'));
7171
if (empty($global_git_name)) {
7272
task('Configuring global git user name.');
73-
passthru(sprintf('git config --global user.name %s', escapeshellarg($deploy_git_user_name)), $exit_code);
74-
if ($exit_code !== 0) {
75-
quit($exit_code);
76-
}
73+
passthru_or_fail(sprintf('git config --global user.name %s', escapeshellarg($deploy_git_user_name)));
7774
}
7875

7976
$global_git_email = trim((string) shell_exec('git config --global user.email'));
8077
if (empty($global_git_email)) {
8178
task('Configuring global git user email.');
82-
passthru(sprintf('git config --global user.email %s', escapeshellarg($deploy_git_user_email)), $exit_code);
83-
if ($exit_code !== 0) {
84-
quit($exit_code);
85-
}
79+
passthru_or_fail(sprintf('git config --global user.email %s', escapeshellarg($deploy_git_user_email)));
8680
}
8781

8882
// Setup SSH.
8983
putenv('VORTEX_SSH_PREFIX=DEPLOY_ARTIFACT');
9084
!empty($deploy_ssh_fingerprint) && putenv('VORTEX_DEPLOY_ARTIFACT_SSH_FINGERPRINT=' . $deploy_ssh_fingerprint);
9185
!empty($deploy_ssh_file) && putenv('VORTEX_DEPLOY_ARTIFACT_SSH_FILE=' . $deploy_ssh_file);
92-
passthru(__DIR__ . '/setup-ssh', $exit_code);
93-
if ($exit_code !== 0) {
94-
quit($exit_code);
95-
}
86+
passthru_or_fail(__DIR__ . '/setup-ssh');
9687

9788
task('Installing artifact builder.');
98-
passthru('composer global require --dev -n --ansi --prefer-source --ignore-platform-reqs drevops/git-artifact:~1.2', $exit_code);
99-
if ($exit_code !== 0) {
100-
quit($exit_code);
101-
}
89+
passthru_or_fail('composer global require --dev -n --ansi --prefer-source --ignore-platform-reqs drevops/git-artifact:~1.2');
10290

10391
$deploy_artifact_root = realpath($deploy_artifact_root);
10492
$deploy_artifact_src = realpath($deploy_artifact_src);
@@ -118,20 +106,6 @@ if (file_exists($deploy_artifact_root . '/.gitignore.artifact')) {
118106
}
119107

120108
task('Running artifact builder.');
121-
$git_artifact_cmd = sprintf(
122-
'%s %s --root=%s --src=%s --branch=%s --gitignore=%s --log=%s -vvv',
123-
escapeshellarg(getenv('HOME') . '/.composer/vendor/bin/git-artifact'),
124-
escapeshellarg($deploy_git_remote),
125-
escapeshellarg($deploy_artifact_root),
126-
escapeshellarg($deploy_artifact_src),
127-
escapeshellarg($deploy_artifact_dst_branch),
128-
escapeshellarg($deploy_artifact_src . '/.gitignore.artifact'),
129-
escapeshellarg($deploy_artifact_log)
130-
);
131-
132-
passthru($git_artifact_cmd, $exit_code);
133-
if ($exit_code !== 0) {
134-
quit($exit_code);
135-
}
109+
passthru_or_fail(sprintf('%s %s --root=%s --src=%s --branch=%s --gitignore=%s --log=%s -vvv', escapeshellarg(getenv('HOME') . '/.composer/vendor/bin/git-artifact'), escapeshellarg($deploy_git_remote), escapeshellarg($deploy_artifact_root), escapeshellarg($deploy_artifact_src), escapeshellarg($deploy_artifact_dst_branch), escapeshellarg($deploy_artifact_src . '/.gitignore.artifact'), escapeshellarg($deploy_artifact_log)));
136110

137111
pass('Finished ARTIFACT deployment.');

.vortex/tooling/src/deploy-lagoon

Lines changed: 6 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,7 @@ if (empty($deploy_branch) && empty($deploy_pr)) {
106106
putenv('VORTEX_SSH_PREFIX=DEPLOY_LAGOON');
107107
!empty($ssh_fingerprint) && putenv('VORTEX_DEPLOY_LAGOON_SSH_FINGERPRINT=' . $ssh_fingerprint);
108108
!empty($ssh_file) && putenv('VORTEX_DEPLOY_LAGOON_SSH_FILE=' . $ssh_file);
109-
passthru(__DIR__ . '/setup-ssh', $ssh_exit_code);
110-
if ($ssh_exit_code !== 0) {
111-
quit($ssh_exit_code);
112-
}
109+
passthru_or_fail(__DIR__ . '/setup-ssh');
113110

114111
// Install Lagoon CLI if needed.
115112
if (!command_path('lagoon') || !empty($lagooncli_force_install)) {
@@ -118,13 +115,7 @@ if (!command_path('lagoon') || !empty($lagooncli_force_install)) {
118115
$platform = strtolower(php_uname('s'));
119116
$arch = str_replace(['x86_64', 'aarch64'], ['amd64', 'arm64'], php_uname('m'));
120117

121-
$download_url = sprintf(
122-
'https://github.com/uselagoon/lagoon-cli/releases/download/%s/lagoon-cli-%s-%s-%s',
123-
$lagooncli_version,
124-
$lagooncli_version,
125-
$platform,
126-
$arch
127-
);
118+
$download_url = sprintf('https://github.com/uselagoon/lagoon-cli/releases/download/%s/lagoon-cli-%s-%s-%s', $lagooncli_version, $lagooncli_version, $platform, $arch);
128119

129120
$lagoon_binary_path = $lagooncli_path . '/lagoon';
130121

@@ -152,20 +143,7 @@ if (!command_path('lagoon') || !empty($lagooncli_force_install)) {
152143
}
153144

154145
task('Configuring Lagoon instance.');
155-
passthru(
156-
sprintf(
157-
'%s config add --force --lagoon %s --graphql %s --hostname %s --port %s',
158-
escapeshellarg($lagoon_bin),
159-
escapeshellarg($lagoon_instance),
160-
escapeshellarg($lagoon_instance_graphql),
161-
escapeshellarg($lagoon_instance_hostname),
162-
escapeshellarg($lagoon_instance_port)
163-
),
164-
$config_exit_code
165-
);
166-
if ($config_exit_code !== 0) {
167-
quit($config_exit_code);
168-
}
146+
passthru_or_fail(sprintf('%s config add --force --lagoon %s --graphql %s --hostname %s --port %s', escapeshellarg($lagoon_bin), escapeshellarg($lagoon_instance), escapeshellarg($lagoon_instance_graphql), escapeshellarg($lagoon_instance_hostname), escapeshellarg($lagoon_instance_port)));
169147

170148
/**
171149
* Run Lagoon CLI command.
@@ -183,14 +161,7 @@ function lagoon_run_cli(string $subcommand, ?int &$subcommand_exit_code = NULL):
183161
// phpcs:ignore Drupal.NamingConventions.ValidGlobal.GlobalUnderScore
184162
global $ssh_file, $lagoon_instance, $lagoon_project, $lagoon_bin;
185163

186-
$cmd = sprintf(
187-
'%s --force --skip-update-check --ssh-key %s --lagoon %s --project %s %s 2>&1',
188-
escapeshellarg($lagoon_bin),
189-
escapeshellarg($ssh_file),
190-
escapeshellarg($lagoon_instance),
191-
escapeshellarg($lagoon_project),
192-
$subcommand
193-
);
164+
$cmd = sprintf('%s --force --skip-update-check --ssh-key %s --lagoon %s --project %s %s 2>&1', escapeshellarg($lagoon_bin), escapeshellarg($ssh_file), escapeshellarg($lagoon_instance), escapeshellarg($lagoon_project), $subcommand);
194165

195166
$subcommand_exit_code_provided = TRUE;
196167
if (is_null($subcommand_exit_code)) {
@@ -288,15 +259,7 @@ else {
288259
}
289260

290261
task(sprintf('Redeploying environment: project %s, PR: %s.', $lagoon_project, $deploy_pr));
291-
$deploy_cmd = sprintf(
292-
'deploy pullrequest --number %s --base-branch-name %s --base-branch-ref %s --head-branch-name %s --head-branch-ref %s --title %s',
293-
escapeshellarg($deploy_pr),
294-
escapeshellarg($deploy_pr_base_branch),
295-
escapeshellarg('origin/' . $deploy_pr_base_branch),
296-
escapeshellarg($deploy_branch),
297-
escapeshellarg($deploy_pr_head),
298-
escapeshellarg($deploy_pr_full)
299-
);
262+
$deploy_cmd = sprintf('deploy pullrequest --number %s --base-branch-name %s --base-branch-ref %s --head-branch-name %s --head-branch-ref %s --title %s', escapeshellarg($deploy_pr), escapeshellarg($deploy_pr_base_branch), escapeshellarg('origin/' . $deploy_pr_base_branch), escapeshellarg($deploy_branch), escapeshellarg($deploy_pr_head), escapeshellarg($deploy_pr_full));
300263
$deploy_output = lagoon_run_cli($deploy_cmd);
301264
$exit_code = lagoon_handle_environment_limit_exceeded($deploy_output);
302265

@@ -310,15 +273,7 @@ else {
310273
// Fresh deployment.
311274
else {
312275
task(sprintf('Deploying environment: project %s, PR: %s.', $lagoon_project, $deploy_pr));
313-
$deploy_cmd = sprintf(
314-
'deploy pullrequest --number %s --base-branch-name %s --base-branch-ref %s --head-branch-name %s --head-branch-ref %s --title %s',
315-
escapeshellarg($deploy_pr),
316-
escapeshellarg($deploy_pr_base_branch),
317-
escapeshellarg('origin/' . $deploy_pr_base_branch),
318-
escapeshellarg($deploy_branch),
319-
escapeshellarg($deploy_pr_head),
320-
escapeshellarg($deploy_pr_full)
321-
);
276+
$deploy_cmd = sprintf('deploy pullrequest --number %s --base-branch-name %s --base-branch-ref %s --head-branch-name %s --head-branch-ref %s --title %s', escapeshellarg($deploy_pr), escapeshellarg($deploy_pr_base_branch), escapeshellarg('origin/' . $deploy_pr_base_branch), escapeshellarg($deploy_branch), escapeshellarg($deploy_pr_head), escapeshellarg($deploy_pr_full));
322277
$deploy_output = lagoon_run_cli($deploy_cmd, $exit_code);
323278
$exit_code = lagoon_handle_environment_limit_exceeded($deploy_output);
324279
}

.vortex/tooling/src/download-db

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
/**
5+
* @file
6+
* Download database dump.
7+
*
8+
* This is a router script to call relevant scripts based on type.
9+
*
10+
* IMPORTANT! This script runs outside the container on the host system.
11+
*/
12+
13+
declare(strict_types=1);
14+
15+
namespace DrevOps\VortexTooling;
16+
17+
require_once __DIR__ . '/helpers.php';
18+
execute_override(basename(__FILE__));
19+
20+
// -----------------------------------------------------------------------------
21+
22+
// Database download source.
23+
$source = getenv_default('VORTEX_DOWNLOAD_DB_SOURCE', 'url');
24+
25+
// Force DB download even if the cache exists.
26+
$force = getenv_default('VORTEX_DOWNLOAD_DB_FORCE', '');
27+
28+
// Proceed with download.
29+
$proceed = getenv_default('VORTEX_DOWNLOAD_DB_PROCEED', '1');
30+
31+
// Database dump file name.
32+
$db_file = getenv_default('VORTEX_DOWNLOAD_DB_FILE', 'VORTEX_DB_FILE', 'db.sql');
33+
34+
// Directory with database dump file.
35+
$db_dir = getenv_default('VORTEX_DOWNLOAD_DB_DIR', 'VORTEX_DB_DIR', './.data');
36+
37+
// Semaphore file to indicate download completion.
38+
$semaphore = getenv_default('VORTEX_DOWNLOAD_DB_SEMAPHORE', '');
39+
40+
// -----------------------------------------------------------------------------
41+
42+
info('Started database download.');
43+
44+
if ($proceed !== '1') {
45+
pass('Skipping database download as DB_DOWNLOAD_PROCEED is not set to 1.');
46+
quit(0);
47+
}
48+
49+
// Check for existing dump files.
50+
$db_file_basename = pathinfo($db_file, PATHINFO_FILENAME);
51+
$found_db = '';
52+
if (is_dir($db_dir)) {
53+
$files = glob($db_dir . '/' . $db_file_basename . '.{sql,tar}', GLOB_BRACE);
54+
if ($files !== FALSE && count($files) > 0) {
55+
$found_db = implode("\n", $files);
56+
}
57+
}
58+
59+
if ($found_db !== '') {
60+
note('Found existing database dump file(s).');
61+
passthru('ls -Alh ' . escapeshellarg($db_dir) . ' 2>/dev/null || true');
62+
63+
if ($force !== '1') {
64+
note('Using existing database dump file(s).');
65+
note('Download will not proceed.');
66+
note('Remove existing database file or set VORTEX_DOWNLOAD_DB_FORCE value to 1 to force download.');
67+
quit(0);
68+
}
69+
70+
note('Will download a fresh copy of the database.');
71+
}
72+
73+
$sources = [
74+
'ftp' => __DIR__ . '/download-db-ftp',
75+
'url' => __DIR__ . '/download-db-url',
76+
'acquia' => __DIR__ . '/download-db-acquia',
77+
'lagoon' => __DIR__ . '/download-db-lagoon',
78+
'container_registry' => __DIR__ . '/download-db-container-registry',
79+
's3' => __DIR__ . '/download-db-s3',
80+
];
81+
82+
if (isset($sources[$source])) {
83+
passthru_or_fail($sources[$source], 'Failed to download database from source "%s".', $source);
84+
}
85+
86+
passthru('ls -Alh ' . escapeshellarg($db_dir) . ' || true');
87+
88+
// Create a semaphore file to indicate that the database has been downloaded.
89+
if ($semaphore !== '') {
90+
touch($semaphore);
91+
}
92+
93+
pass('Finished database download.');

0 commit comments

Comments
 (0)