From 7cf4ffd5398b9e90b54f6f914e28eae309443580 Mon Sep 17 00:00:00 2001 From: Andrew Berry Date: Thu, 11 Aug 2022 15:03:54 -0400 Subject: [PATCH 1/7] Extract GitLab and GitHub actions into new methods --- src/ScaffoldInstallerPlugin.php | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/ScaffoldInstallerPlugin.php b/src/ScaffoldInstallerPlugin.php index b16bcaf8..836a87c2 100644 --- a/src/ScaffoldInstallerPlugin.php +++ b/src/ScaffoldInstallerPlugin.php @@ -220,8 +220,17 @@ private function installDdevCommand(): void private function installCICommands(): void { $scaffoldPath = $this->config->get('vendor-dir') . '/lullabot/drainpipe/scaffold'; + $this->installGitlabCI($scaffoldPath); + $this->installGitHubActions($scaffoldPath); + } + + /** + * Install GitLab CI configuration if defined in composer.json + * + * @param string $scaffoldPath The path to the scaffold files to copy in. + */ + private function installGitlabCI(string $scaffoldPath): void { $fs = new Filesystem(); - // GitLab $fs->removeDirectory('./.drainpipe/gitlab'); if (isset($this->extra['drainpipe']['gitlab']) && is_array($this->extra['drainpipe']['gitlab'])) { if (file_exists('./.ddev/config.yaml')) { @@ -276,7 +285,15 @@ private function installCICommands(): void $fs->copy("$scaffoldPath/gitlab/gitlab-ci.example.yml", './.gitlab-ci.yml'); } } - // GitHub + } + + /** + * Install GitLab CI configuration if defined in composer.json + * + * @param string $scaffoldPath The path to the scaffold files to copy in. + */ + private function installGitHubActions(string $scaffoldPath): void { + $fs = new Filesystem(); $fs->removeDirectory('./.github/actions/drainpipe'); if (isset($this->extra['drainpipe']['github']) && is_array($this->extra['drainpipe']['github'])) { $fs->ensureDirectoryExists('./.github/actions'); From 9e2163365ef2a4dfd29112923f1578ee54e9dc32 Mon Sep 17 00:00:00 2001 From: Andrew Berry Date: Thu, 11 Aug 2022 15:05:23 -0400 Subject: [PATCH 2/7] Use an early return to reduce if nesting --- src/ScaffoldInstallerPlugin.php | 112 +++++++++++++++++--------------- 1 file changed, 59 insertions(+), 53 deletions(-) diff --git a/src/ScaffoldInstallerPlugin.php b/src/ScaffoldInstallerPlugin.php index 836a87c2..9cdb9f41 100644 --- a/src/ScaffoldInstallerPlugin.php +++ b/src/ScaffoldInstallerPlugin.php @@ -227,13 +227,17 @@ private function installCICommands(): void /** * Install GitLab CI configuration if defined in composer.json * - * @param string $scaffoldPath The path to the scaffold files to copy in. + * @param string $scaffoldPath The path to the scaffold files to copy from. */ private function installGitlabCI(string $scaffoldPath): void { $fs = new Filesystem(); $fs->removeDirectory('./.drainpipe/gitlab'); - if (isset($this->extra['drainpipe']['gitlab']) && is_array($this->extra['drainpipe']['gitlab'])) { - if (file_exists('./.ddev/config.yaml')) { + + if (!isset($this->extra['drainpipe']['gitlab']) || !is_array($this->extra['drainpipe']['gitlab'])) { + return; + } + + if (file_exists('./.ddev/config.yaml')) { $fs->ensureDirectoryExists('.gitlab/drainpipe'); $fs->copy("$scaffoldPath/gitlab/DDEV.gitlab-ci.yml", ".gitlab/drainpipe/DDEV.gitlab-ci.yml"); $this->io->write("🪠 [Drainpipe] .gitlab/drainpipe/DDEV.gitlab-ci.yml installed"); @@ -247,74 +251,76 @@ private function installGitlabCI(string $scaffoldPath): void { $file = "gitlab/$gitlab.gitlab-ci.yml"; if (file_exists("$scaffoldPath/$file")) { $fs->ensureDirectoryExists('./.drainpipe/gitlab'); - $fs->copy("$scaffoldPath/$file", ".drainpipe/$file"); - $this->io->write("🪠 [Drainpipe] .drainpipe/$file installed"); + $fs->copy("$scaffoldPath/$file", ".drainpipe/$file"); + $this->io->write("🪠 [Drainpipe] .drainpipe/$file installed"); + } + else { + $this->io->warning("🪠 [Drainpipe] $scaffoldPath/$file does not exist"); + } + + if ($gitlab === 'Pantheon') { + // @TODO this isn't really specific to GitLab + // .drainpipeignore + if (!file_exists('.drainpipeignore')) { + $fs->copy("$scaffoldPath/pantheon/.drainpipeignore", '.drainpipeignore'); } else { - $this->io->warning("🪠 [Drainpipe] $scaffoldPath/$file does not exist"); - } - - if ($gitlab === 'Pantheon') { - // @TODO this isn't really specific to GitLab - // .drainpipeignore - if (!file_exists('.drainpipeignore')) { - $fs->copy("$scaffoldPath/pantheon/.drainpipeignore", '.drainpipeignore'); - } - else { - $contents = file_get_contents('./.drainpipeignore'); - if (strpos($contents, '/web/sites/default/files') === false) { - $this->io->warning( - sprintf( - '.gitignore does not contain drainpipe ignores. Compare .drainpipeignore in the root of your repository with %s and update as needed.', - "$scaffoldPath/pantheon/.drainpipeignore" - ) - ); - } - } - // pantheon.yml - if (!file_exists('./pantheon.yml')) { - $fs->copy("$scaffoldPath/pantheon/pantheon.yml", './pantheon.yml'); - } - // settings.pantheon.php - if (!file_exists('./web/sites/default/settings.pantheon.php')) { - $fs->copy("$scaffoldPath/pantheon/settings.pantheon.php", './web/sites/default/settings.pantheon.php'); + $contents = file_get_contents('./.drainpipeignore'); + if (strpos($contents, '/web/sites/default/files') === false) { + $this->io->warning( + sprintf( + '.gitignore does not contain drainpipe ignores. Compare .drainpipeignore in the root of your repository with %s and update as needed.', + "$scaffoldPath/pantheon/.drainpipeignore" + ) + ); } } + // pantheon.yml + if (!file_exists('./pantheon.yml')) { + $fs->copy("$scaffoldPath/pantheon/pantheon.yml", './pantheon.yml'); + } + // settings.pantheon.php + if (!file_exists('./web/sites/default/settings.pantheon.php')) { + $fs->copy("$scaffoldPath/pantheon/settings.pantheon.php", './web/sites/default/settings.pantheon.php'); + } } - if (!file_exists('./.gitlab-ci.yml')) { - $fs->copy("$scaffoldPath/gitlab/gitlab-ci.example.yml", './.gitlab-ci.yml'); - } + } + if (!file_exists('./.gitlab-ci.yml')) { + $fs->copy("$scaffoldPath/gitlab/gitlab-ci.example.yml", './.gitlab-ci.yml'); } } /** * Install GitLab CI configuration if defined in composer.json * - * @param string $scaffoldPath The path to the scaffold files to copy in. + * @param string $scaffoldPath The path to the scaffold files to copy from. */ private function installGitHubActions(string $scaffoldPath): void { $fs = new Filesystem(); $fs->removeDirectory('./.github/actions/drainpipe'); - if (isset($this->extra['drainpipe']['github']) && is_array($this->extra['drainpipe']['github'])) { - $fs->ensureDirectoryExists('./.github/actions'); - $fs->copy("$scaffoldPath/github/actions/common", './.github/actions/drainpipe'); - foreach ($this->extra['drainpipe']['github'] as $github) { - if ($github === 'PantheonReviewApps') { - $fs->ensureDirectoryExists('./.github/actions/drainpipe/pantheon'); - $fs->ensureDirectoryExists('./.github/workflows'); - $fs->copy("$scaffoldPath/github/actions/pantheon", './.github/actions/drainpipe/pantheon'); - if (file_exists('./.ddev/config.yaml')) { - $fs->copy("$scaffoldPath/github/workflows/PantheonReviewAppsDDEV.yml", './.github/workflows/PantheonReviewApps.yml'); - } - else { - $fs->copy("$scaffoldPath/github/workflows/PantheonReviewApps.yml", './.github/workflows/PantheonReviewApps.yml'); - } + + if (!isset($this->extra['drainpipe']['github']) || is_array($this->extra['drainpipe']['github'])) { + return; + } + + $fs->ensureDirectoryExists('./.github/actions'); + $fs->copy("$scaffoldPath/github/actions/common", './.github/actions/drainpipe'); + foreach ($this->extra['drainpipe']['github'] as $github) { + if ($github === 'PantheonReviewApps') { + $fs->ensureDirectoryExists('./.github/actions/drainpipe/pantheon'); + $fs->ensureDirectoryExists('./.github/workflows'); + $fs->copy("$scaffoldPath/github/actions/pantheon", './.github/actions/drainpipe/pantheon'); + if (file_exists('./.ddev/config.yaml')) { + $fs->copy("$scaffoldPath/github/workflows/PantheonReviewAppsDDEV.yml", './.github/workflows/PantheonReviewApps.yml'); } - else if ($github === 'ComposerLockDiff') { - $fs->ensureDirectoryExists('./.github/workflows'); - $fs->copy("$scaffoldPath/github/workflows/ComposerLockDiff.yml", './.github/workflows/ComposerLockDiff.yml'); + else { + $fs->copy("$scaffoldPath/github/workflows/PantheonReviewApps.yml", './.github/workflows/PantheonReviewApps.yml'); } } + else if ($github === 'ComposerLockDiff') { + $fs->ensureDirectoryExists('./.github/workflows'); + $fs->copy("$scaffoldPath/github/workflows/ComposerLockDiff.yml", './.github/workflows/ComposerLockDiff.yml'); + } } // Tugboat From 57b7ef5473fc3f03ebd0e4eba89eb45995b16250 Mon Sep 17 00:00:00 2001 From: Sally Young Date: Wed, 17 Apr 2024 11:48:04 +0100 Subject: [PATCH 3/7] Fix Tugboat config --- .github/workflows/TestTugboat.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/TestTugboat.yml b/.github/workflows/TestTugboat.yml index 9ee6839d..1a6b7c39 100644 --- a/.github/workflows/TestTugboat.yml +++ b/.github/workflows/TestTugboat.yml @@ -36,7 +36,7 @@ jobs: ddev config --auto ddev config --php-version "8.1" ddev config --nodejs-version "18" - ddev config --database=mariadb:10.4 + ddev config --database "mariadb:10.4" ddev get ddev/ddev-redis --version v1.2.0 ddev get ddev/ddev-elasticsearch --version v0.3.2 ddev start @@ -122,7 +122,7 @@ jobs: ddev config --auto ddev config --php-version "8.1" ddev config --nodejs-version "16" - ddev config --database=mariadb:10.4 + ddev config --database "mariadb:10.4" ddev start ddev composer config extra.drupal-scaffold.gitignore true ddev composer config --json extra.drupal-scaffold.allowed-packages \[\"lullabot/drainpipe\"] From b575bb20617671ba6846347deb10ff7d87b052e3 Mon Sep 17 00:00:00 2001 From: Sally Young Date: Wed, 17 Apr 2024 12:26:13 +0100 Subject: [PATCH 4/7] Switch to mariadb 10.11 --- .github/workflows/TestGitHubActions.yml | 2 +- .github/workflows/TestTugboat.yml | 6 ++---- .tugboat/config.yml | 2 +- scaffold/pantheon/pantheon.yml | 2 +- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/.github/workflows/TestGitHubActions.yml b/.github/workflows/TestGitHubActions.yml index 9e00afbc..95b6f2d7 100644 --- a/.github/workflows/TestGitHubActions.yml +++ b/.github/workflows/TestGitHubActions.yml @@ -61,7 +61,7 @@ jobs: echo "php_version: 8.1" >> pantheon.yml echo "drush_version: 10" >> pantheon.yml echo "database:" >> pantheon.yml - echo " version: 10.4" >> pantheon.yml + echo " version: 10.11" >> pantheon.yml echo "enforce_https: full+subdomains" >> pantheon.yml echo "build_step: false" >> pantheon.yml diff --git a/.github/workflows/TestTugboat.yml b/.github/workflows/TestTugboat.yml index 1a6b7c39..0022b72e 100644 --- a/.github/workflows/TestTugboat.yml +++ b/.github/workflows/TestTugboat.yml @@ -36,10 +36,9 @@ jobs: ddev config --auto ddev config --php-version "8.1" ddev config --nodejs-version "18" - ddev config --database "mariadb:10.4" ddev get ddev/ddev-redis --version v1.2.0 ddev get ddev/ddev-elasticsearch --version v0.3.2 - ddev start + ddev restart ddev composer config extra.drupal-scaffold.gitignore true ddev composer config --json extra.drupal-scaffold.allowed-packages \[\"lullabot/drainpipe\"] ddev composer config --no-plugins allow-plugins.composer/installers true @@ -122,8 +121,7 @@ jobs: ddev config --auto ddev config --php-version "8.1" ddev config --nodejs-version "16" - ddev config --database "mariadb:10.4" - ddev start + ddev restart ddev composer config extra.drupal-scaffold.gitignore true ddev composer config --json extra.drupal-scaffold.allowed-packages \[\"lullabot/drainpipe\"] ddev composer config --no-plugins allow-plugins.composer/installers true diff --git a/.tugboat/config.yml b/.tugboat/config.yml index 0d3688e7..6073e6b7 100644 --- a/.tugboat/config.yml +++ b/.tugboat/config.yml @@ -34,7 +34,7 @@ services: fullPage: false mariadb: - image: tugboatqa/mariadb:10.4 + image: tugboatqa/mariadb:10.11 redis: image: tugboatqa/redis:6-bullseye diff --git a/scaffold/pantheon/pantheon.yml b/scaffold/pantheon/pantheon.yml index 5a09a29f..b4a55501 100644 --- a/scaffold/pantheon/pantheon.yml +++ b/scaffold/pantheon/pantheon.yml @@ -2,6 +2,6 @@ api_version: 1 web_docroot: true php_version: 8.0 database: - version: 10.4 + version: 10.11 drush_version: 11 build_step: false From dfb01dcbab5dab47fcdaf72d7b90434328343e3b Mon Sep 17 00:00:00 2001 From: Sally Young Date: Wed, 1 May 2024 12:43:14 +0100 Subject: [PATCH 5/7] restore DB versions --- .github/workflows/TestGitHubActions.yml | 2 +- scaffold/pantheon/pantheon.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/TestGitHubActions.yml b/.github/workflows/TestGitHubActions.yml index 95b6f2d7..9e00afbc 100644 --- a/.github/workflows/TestGitHubActions.yml +++ b/.github/workflows/TestGitHubActions.yml @@ -61,7 +61,7 @@ jobs: echo "php_version: 8.1" >> pantheon.yml echo "drush_version: 10" >> pantheon.yml echo "database:" >> pantheon.yml - echo " version: 10.11" >> pantheon.yml + echo " version: 10.4" >> pantheon.yml echo "enforce_https: full+subdomains" >> pantheon.yml echo "build_step: false" >> pantheon.yml diff --git a/scaffold/pantheon/pantheon.yml b/scaffold/pantheon/pantheon.yml index b4a55501..5a09a29f 100644 --- a/scaffold/pantheon/pantheon.yml +++ b/scaffold/pantheon/pantheon.yml @@ -2,6 +2,6 @@ api_version: 1 web_docroot: true php_version: 8.0 database: - version: 10.11 + version: 10.4 drush_version: 11 build_step: false From 3e84f0c450063e30ee1ab29c42eb6a4aa3d83d68 Mon Sep 17 00:00:00 2001 From: Andrew Berry Date: Fri, 19 Jul 2024 08:08:21 -0400 Subject: [PATCH 6/7] Fix Tugboat installation after merge from main --- src/ScaffoldInstallerPlugin.php | 278 ++++++++++++++++++-------------- 1 file changed, 154 insertions(+), 124 deletions(-) diff --git a/src/ScaffoldInstallerPlugin.php b/src/ScaffoldInstallerPlugin.php index 866539e7..637e854e 100644 --- a/src/ScaffoldInstallerPlugin.php +++ b/src/ScaffoldInstallerPlugin.php @@ -234,6 +234,7 @@ private function installCICommands(): void $scaffoldPath = $this->config->get('vendor-dir') . '/lullabot/drainpipe/scaffold'; $this->installGitlabCI($scaffoldPath); $this->installGitHubActions($scaffoldPath); + $this->installTugboat($scaffoldPath); } /** @@ -334,147 +335,176 @@ private function installGitHubActions(string $scaffoldPath): void { $fs->copy("$scaffoldPath/github/workflows/ComposerLockDiff.yml", './.github/workflows/ComposerLockDiff.yml'); } } + } - // 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); - } + /** + * Installs Tugboat if defined in composer.json. + * + * @param string $scaffoldPath + */ + private function installTugboat(string $scaffoldPath): void { + $fs = new Filesystem(); - // Wipe the Tugboat directory and define base config. - $fs->removeDirectory('./.tugboat'); - $binaryInstallerPlugin = new BinaryInstallerPlugin(); - $tugboatConfig = [ - 'nodejs_version' => '18', - 'webserver_image' => 'tugboatqa/php-nginx:8.1-fpm', - 'database_type' => 'mariadb', - 'database_version' => '10.11', - 'php_version' => '8.1', - 'sync_command' => 'sync', - 'build_command' => 'build', - 'update_command' => 'drupal:update', - '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']; - $tugboatConfig['database_version'] = $ddevConfig['database']['version']; - $tugboatConfig['webserver_image'] = 'tugboatqa/php-nginx:' . $ddevConfig['php_version'] . '-fpm'; + if (!isset($this->extra['drainpipe']['tugboat']) || is_array($this->extra['drainpipe']['tugboat'])) { + return; + } - if (!empty($ddevConfig['nodejs_version'])) { - $tugboatConfig['nodejs_version'] = $ddevConfig['nodejs_version']; - } - if (!empty($ddevConfig['webserver_type']) && $ddevConfig['webserver_type'] === 'apache-fpm') { - $tugboatConfig['webserver_image'] = 'tugboatqa/php:' . $ddevConfig['php_version'] . '-apache'; - } - } + // 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); + } - // 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)); - } + // Wipe the Tugboat directory and define base config. + $fs->removeDirectory('./.tugboat'); + $binaryInstallerPlugin = new BinaryInstallerPlugin(); + $tugboatConfig = [ + 'nodejs_version' => '18', + 'webserver_image' => 'tugboatqa/php-nginx:8.1-fpm', + 'database_type' => 'mariadb', + 'database_version' => '10.11', + 'php_version' => '8.1', + 'sync_command' => 'sync', + 'build_command' => 'build', + 'update_command' => 'drupal:update', + 'init' => [], + 'task_version' => $binaryInstallerPlugin->getBinaryVersion('task'), + 'pantheon' => isset($this->extra['drainpipe']['tugboat']['pantheon']), + 'overrides' => ['php' => ''], + ]; - // 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); + // Read DDEV config. + if (file_exists('./.ddev/config.yaml')) { + $ddevConfig = Yaml::parseFile('./.ddev/config.yaml'); + $tugboatConfig['database_type'] = $ddevConfig['database']['type']; + $tugboatConfig['database_version'] = $ddevConfig['database']['version']; + $tugboatConfig['webserver_image'] = 'tugboatqa/php-nginx:' . $ddevConfig['php_version'] . '-fpm'; + + if (!empty($ddevConfig['nodejs_version'])) { + $tugboatConfig['nodejs_version'] = $ddevConfig['nodejs_version']; + } + if (!empty($ddevConfig['webserver_type']) && $ddevConfig['webserver_type'] === 'apache-fpm') { + $tugboatConfig['webserver_image'] = 'tugboatqa/php:' . $ddevConfig['php_version'] . '-apache'; } + } - // 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); + // 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 commands to Task. - if (file_exists('Taskfile.yml')) { - // Get steps out of the Taskfile. - $taskfile = Yaml::parseFile('./Taskfile.yml'); - if (isset($taskfile['tasks']['sync:tugboat'])) { - $tugboatConfig['sync_command'] = 'sync:tugboat'; - } - if (isset($taskfile['tasks']['build:tugboat'])) { - $tugboatConfig['build_command'] = 'build:tugboat'; - } - if (isset($taskfile['tasks']['update'])) { - $tugboatConfig['update_command'] = 'update'; - } - if (isset($taskfile['tasks']['update:tugboat'])) { - $tugboatConfig['update_command'] = 'update:tugboat'; - } - if (isset($taskfile['tasks']['online:tugboat'])) { - $tugboatConfig['online_command'] = 'online:tugboat'; - } - if (isset($taskfile['tasks']['tugboat:php:init'])) { - $tugboatConfig['init']['php'] = true; - } - if (isset($taskfile['tasks']['tugboat:mysql:init'])) { - $tugboatConfig['init']['mysql'] = true; - } - if (isset($taskfile['tasks']['tugboat:redis:init'])) { - $tugboatConfig['init']['redis'] = true; - } + // 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'); + if (isset($taskfile['tasks']['sync:tugboat'])) { + $tugboatConfig['sync_command'] = 'sync:tugboat'; + } + if (isset($taskfile['tasks']['build:tugboat'])) { + $tugboatConfig['build_command'] = 'build:tugboat'; + } + if (isset($taskfile['tasks']['update'])) { + $tugboatConfig['update_command'] = 'update'; + } + if (isset($taskfile['tasks']['update:tugboat'])) { + $tugboatConfig['update_command'] = 'update:tugboat'; + } + if (isset($taskfile['tasks']['online:tugboat'])) { + $tugboatConfig['online_command'] = 'online:tugboat'; + } + if (isset($taskfile['tasks']['tugboat:php:init'])) { + $tugboatConfig['init']['php'] = TRUE; } + if (isset($taskfile['tasks']['tugboat:mysql:init'])) { + $tugboatConfig['init']['mysql'] = TRUE; + } + if (isset($taskfile['tasks']['tugboat:redis:init'])) { + $tugboatConfig['init']['redis'] = TRUE; + } + } - // 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)); - file_put_contents('./.tugboat/steps/3-build.sh', $twig->render('steps/3-build.sh.twig', $tugboatConfig)); - chmod('./.tugboat/steps/1-init.sh', 0755); - chmod('./.tugboat/steps/2-update.sh', 0755); - chmod('./.tugboat/steps/3-build.sh', 0755); - if (!empty($tugboatConfig['online_command'])) { - file_put_contents('./.tugboat/steps/4-online.sh', $twig->render('steps/4-online.sh.twig', $tugboatConfig)); - chmod('./.tugboat/steps/4-online.sh', 0755); - } + // 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)); + file_put_contents('./.tugboat/steps/3-build.sh', + $twig->render('steps/3-build.sh.twig', $tugboatConfig)); + chmod('./.tugboat/steps/1-init.sh', 0755); + chmod('./.tugboat/steps/2-update.sh', 0755); + chmod('./.tugboat/steps/3-build.sh', 0755); + if (!empty($tugboatConfig['online_command'])) { + file_put_contents('./.tugboat/steps/4-online.sh', + $twig->render('steps/4-online.sh.twig', + $tugboatConfig)); + chmod('./.tugboat/steps/4-online.sh', 0755); + } - if ($tugboatConfig['database_type'] === 'mysql') { - $fs->ensureDirectoryExists('./.tugboat/scripts'); - $fs->copy("$scaffoldPath/tugboat/scripts/install-mysql-client.sh", './.tugboat/scripts/install-mysql-client.sh'); - chmod('./.tugboat/scripts/install-mysql-client.sh', 0755); - } + if ($tugboatConfig['database_type'] === 'mysql') { + $fs->ensureDirectoryExists('./.tugboat/scripts'); + $fs->copy("$scaffoldPath/tugboat/scripts/install-mysql-client.sh", + './.tugboat/scripts/install-mysql-client.sh'); + chmod('./.tugboat/scripts/install-mysql-client.sh', 0755); + } - file_put_contents('./web/sites/default/settings.tugboat.php', $twig->render('settings.tugboat.php.twig', $tugboatConfig)); - if (file_exists('./web/sites/default/settings.php')) { - $settings = file_get_contents('./web/sites/default/settings.php'); - if (strpos($settings, 'settings.tugboat.php') === false) { - $include = <<<'EOT' + file_put_contents('./web/sites/default/settings.tugboat.php', + $twig->render('settings.tugboat.php.twig', $tugboatConfig)); + if (file_exists('./web/sites/default/settings.php')) { + $settings = file_get_contents('./web/sites/default/settings.php'); + if (strpos($settings, 'settings.tugboat.php') === FALSE) { + $include = <<<'EOT' include __DIR__ . "/settings.tugboat.php"; EOT; - file_put_contents('./web/sites/default/settings.php', $include . PHP_EOL, FILE_APPEND); - } + file_put_contents('./web/sites/default/settings.php', + $include . PHP_EOL, + FILE_APPEND); } } } } + } From 9697ddd2f5d4add8064a9aefe831057e042e159d Mon Sep 17 00:00:00 2001 From: Andrew Berry Date: Fri, 19 Jul 2024 08:12:59 -0400 Subject: [PATCH 7/7] Fix inverted conditional --- src/ScaffoldInstallerPlugin.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ScaffoldInstallerPlugin.php b/src/ScaffoldInstallerPlugin.php index 637e854e..340bfdae 100644 --- a/src/ScaffoldInstallerPlugin.php +++ b/src/ScaffoldInstallerPlugin.php @@ -312,7 +312,7 @@ private function installGitHubActions(string $scaffoldPath): void { $fs = new Filesystem(); $fs->removeDirectory('./.github/actions/drainpipe'); - if (!isset($this->extra['drainpipe']['github']) || is_array($this->extra['drainpipe']['github'])) { + if (!isset($this->extra['drainpipe']['github']) || !is_array($this->extra['drainpipe']['github'])) { return; } @@ -345,7 +345,7 @@ private function installGitHubActions(string $scaffoldPath): void { private function installTugboat(string $scaffoldPath): void { $fs = new Filesystem(); - if (!isset($this->extra['drainpipe']['tugboat']) || is_array($this->extra['drainpipe']['tugboat'])) { + if (!isset($this->extra['drainpipe']['tugboat']) || !is_array($this->extra['drainpipe']['tugboat'])) { return; }