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

Support a config.overrides.yml file for Tugboat #441

Merged
merged 19 commits into from
Feb 23, 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
10 changes: 10 additions & 0 deletions .github/workflows/TestTugboat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ jobs:
ddev composer config repositories.drainpipe --json '{"type": "path", "url": "drainpipe", "options": {"symlink": false}}'
ddev composer config minimum-stability dev
ddev composer config extra.drainpipe --json '{"tugboat": {}}'
mkdir -p .tugboat
echo "php:" > .tugboat/config.drainpipe-override.yml
echo " aliases:" >> .tugboat/config.drainpipe-override.yml
echo " - foo" >> .tugboat/config.drainpipe-override.yml
echo " urls:" >> .tugboat/config.drainpipe-override.yml
echo " - /" >> .tugboat/config.drainpipe-override.yml
echo " screenshot:" >> .tugboat/config.drainpipe-override.yml
echo " timeout: 45" >> .tugboat/config.drainpipe-override.yml
echo " visualdiff:" >> .tugboat/config.drainpipe-override.yml
echo " fullPage: false" >> .tugboat/config.drainpipe-override.yml
ddev composer require lullabot/drainpipe --with-all-dependencies

# Compare the generated files to the ones used to build this repository
Expand Down
9 changes: 9 additions & 0 deletions .tugboat/config.drainpipe-override.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
php:
aliases:
- foo
urls:
- /
screenshot:
timeout: 45
visualdiff:
fullPage: false
18 changes: 17 additions & 1 deletion .tugboat/config.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# DO NOT EDIT THIS FILE
# This file is controlled by Drainpipe, run composer install to apply pending
# updates.
# updates. You can add values to the php service using .tugboat/config.override.yml.
#
# Example config.drainpipe-override.yml
# php:
# aliases:
# urls:
# screenshot:
# visualdiff:
services:
php:
http: false
Expand All @@ -16,6 +23,15 @@ services:
update: ./.tugboat/steps/2-update.sh
build: ./.tugboat/steps/3-build.sh

aliases:
- foo
urls:
- /
screenshot:
timeout: 45
visualdiff:
fullPage: false

mariadb:
image: tugboatqa/mariadb:10.4

Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -601,3 +601,14 @@ tugboat:php:init:
- apt-get install -y libldap2-dev
- docker-php-ext-install ldap
```

Drainpipe will fully manage your `.tugboat/config.yml` file, you should not edit
it. The following keys can be added to your `config.yml` via a
`.tugboat/config.drainppipe-override.yml` file:
```
php:
aliases:
urls:
screenshot:
visualdiff:
```
13 changes: 12 additions & 1 deletion scaffold/tugboat/config.yml.twig
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# DO NOT EDIT THIS FILE
# This file is controlled by Drainpipe, run composer install to apply pending
# updates.
# updates. You can add values to the php service using .tugboat/config.override.yml.
#
# Example config.drainpipe-override.yml
# php:
# aliases:
# urls:
# screenshot:
# visualdiff:
services:
php:
http: false
Expand All @@ -17,6 +24,10 @@ services:
init: ./.tugboat/steps/1-init.sh
update: ./.tugboat/steps/2-update.sh
build: ./.tugboat/steps/3-build.sh
{% if overrides.php|length > 0 %}

{{ overrides.php }}
{% endif %}

{{ database_type }}:
image: tugboatqa/{{ database_type }}:{{ database_version }}
Expand Down
33 changes: 32 additions & 1 deletion src/ScaffoldInstallerPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -302,10 +302,19 @@ private function installCICommands(): void

// Tugboat
if (isset($this->extra['drainpipe']['tugboat'])) {
// Look for a config override file before we wipe the directory.
$tugboatConfigOverride = [];
$tugboatConfigOverridePath = './.tugboat/config.drainpipe-override.yml';
if (file_exists($tugboatConfigOverridePath)) {
$tugboatConfigOverride = Yaml::parseFile($tugboatConfigOverridePath);
$tugboatConfigOverrideFile = file_get_contents($tugboatConfigOverridePath);
}

// Wipe the Tugboat directory and define base config.
$fs->removeDirectory('./.tugboat');
$binaryInstallerPlugin = new BinaryInstallerPlugin();
$tugboatConfig = [
'nodejs_version' => '18',
'nodejs_version' => '18',
'webserver_image' => 'tugboatqa/php-nginx:8.1-fpm',
'database_type' => 'mariadb',
'database_version' => '10.6',
Expand All @@ -316,8 +325,10 @@ private function installCICommands(): void
'init' => [],
'task_version' => $binaryInstallerPlugin->getBinaryVersion('task'),
'pantheon' => isset($this->extra['drainpipe']['tugboat']['pantheon']),
'overrides' => ['php' => ''],
];

// Read DDEV config.
if (file_exists('./.ddev/config.yaml')) {
$ddevConfig = Yaml::parseFile('./.ddev/config.yaml');
$tugboatConfig['database_type'] = $ddevConfig['database']['type'];
Expand All @@ -332,20 +343,35 @@ private function installCICommands(): void
}
}

// Filter out unsupported config overrides.
if (!empty($tugboatConfigOverride['php']) && is_array($tugboatConfigOverride['php'])) {
$tugboatConfigOverride['php'] = array_filter($tugboatConfigOverride['php'], function($key) {
return in_array($key, ['aliases', 'urls', 'visualdiff', 'screenshot']);
}, ARRAY_FILTER_USE_KEY);
$overrideOutput = [];
foreach (explode(PHP_EOL, Yaml::dump($tugboatConfigOverride['php'], 2, 2)) as $line) {
$overrideOutput[] = str_repeat(' ', 4) . $line;
}
$tugboatConfig['overrides']['php'] = rtrim(implode("\n", $overrideOutput));
}

// Add Redis service.
if (file_exists('./.ddev/docker-compose.redis.yaml')) {
$redisConfig = Yaml::parseFile('.ddev/docker-compose.redis.yaml');
$redisImage = explode(':', $redisConfig['services']['redis']['image']);
$tugboatConfig['memory_cache_type'] = 'redis';
$tugboatConfig['memory_cache_version'] = array_pop($redisImage);
}

// Add Elasticsearch service.
if (file_exists('./.ddev/docker-compose.elasticsearch.yaml')) {
$esConfig = Yaml::parseFile('.ddev/docker-compose.elasticsearch.yaml');
$esImage = explode(':', $esConfig['services']['elasticsearch']['image']);
$tugboatConfig['search_type'] = 'elasticsearch';
$tugboatConfig['search_version'] = array_pop($esImage);
}

// Add commands to Task.
if (file_exists('Taskfile.yml')) {
// Get steps out of the Taskfile.
$taskfile = Yaml::parseFile('./Taskfile.yml');
Expand All @@ -372,11 +398,16 @@ private function installCICommands(): void
}
}

// Write the config.yml and settings.tugboat.php files.
if (count($tugboatConfig) > 0) {
$fs->ensureDirectoryExists('./.tugboat');
$fs->ensureDirectoryExists('./.tugboat/steps');
$loader = new FilesystemLoader(__DIR__ . '/../scaffold/tugboat');
$twig = new Environment($loader);
// Reinstate the override file.
if (isset($tugboatConfigOverrideFile)) {
file_put_contents('./.tugboat/config.drainpipe-override.yml', $tugboatConfigOverrideFile);
}
file_put_contents('./.tugboat/config.yml', $twig->render('config.yml.twig', $tugboatConfig));
file_put_contents('./.tugboat/steps/1-init.sh', $twig->render('steps/1-init.sh.twig', $tugboatConfig));
file_put_contents('./.tugboat/steps/2-update.sh', $twig->render('steps/2-update.sh.twig', $tugboatConfig));
Expand Down
Loading