From 2d126630ea165bd1f700c81917d2fdbe144fb87d Mon Sep 17 00:00:00 2001 From: Sally Young Date: Wed, 29 Nov 2023 10:07:51 +0000 Subject: [PATCH] Add in features from the GitHub installer --- .gitlab-ci.yml | 2 +- scaffold/gitlab/DDEV.gitlab-ci.yml | 45 +++++++++++++++++++++++++----- src/ScaffoldInstallerPlugin.php | 10 +++++-- 3 files changed, 47 insertions(+), 10 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 7631c786c..61a09db1c 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -29,9 +29,9 @@ build: script: - !reference [.drainpipe_setup_drupal, script] - !reference [.drainpipe_setup_ddev, script] - - ddev start - ddev composer config extra.drupal-scaffold.gitignore true - ddev composer config --json extra.drupal-scaffold.allowed-packages \[\"lullabot/drainpipe\"] + - ddev composer config --json extra.drainpipe.gitlab \[] - ddev composer config --no-plugins allow-plugins.composer/installers true - ddev composer config --no-plugins allow-plugins.drupal/core-composer-scaffold true - ddev composer config --no-plugins allow-plugins.lullabot/drainpipe true diff --git a/scaffold/gitlab/DDEV.gitlab-ci.yml b/scaffold/gitlab/DDEV.gitlab-ci.yml index 4de4cfdc0..7589d2a27 100644 --- a/scaffold/gitlab/DDEV.gitlab-ci.yml +++ b/scaffold/gitlab/DDEV.gitlab-ci.yml @@ -5,21 +5,52 @@ default: alias: docker variables: - DRAINPIPE_DDEV_SSH_PRIVATE_KEY: - DRAINPIPE_DDEV_SSH_KNOWN_HOSTS: - DRAINPIPE_DDEV_GIT_EMAIL: - DRAINPIPE_DDEV_GIT_NAME: - DRAINPIPE_DDEV_COMPOSER_CACHE_DIR: - DRAINPIPE_DDEV_VERSION: + DRAINPIPE_DDEV_SSH_PRIVATE_KEY: "" + DRAINPIPE_DDEV_SSH_KNOWN_HOSTS: "" + DRAINPIPE_DDEV_GIT_EMAIL: no-reply@example.com + DRAINPIPE_DDEV_GIT_NAME: Drainpipe Bot + DRAINPIPE_DDEV_COMPOSER_CACHE_DIR: "" + DRAINPIPE_DDEV_VERSION: "" DOCKER_HOST: "tcp://docker:2375" FF_NETWORK_PER_BUILD: 1 .drainpipe_setup_ddev: script: - sudo chown -R runner:runner $CI_PROJECT_DIR - - curl -fsSL https://ddev.com/install.sh | bash + - | + mkdir -p .ddev/homeadditions/.ssh + # Copy private key + if [ "$DRAINPIPE_DDEV_SSH_PRIVATE_KEY" != "" ]; then + echo "$DRAINPIPE_DDEV_SSH_PRIVATE_KEY" > .ddev/homeadditions/.ssh/id_rsa + chmod 600 .ddev/homeadditions/.ssh/id_rsa + fi + # Copy known hosts + if [ "$DRAINPIPE_DDEV_SSH_KNOWN_HOSTS" != "" ]; then + echo "$DRAINPIPE_DDEV_SSH_KNOWN_HOSTS" > .ddev/homeadditions/.ssh/known_hosts + chmod 644 .ddev/homeadditions/.ssh/known_hosts + fi + # SSH config file + touch .ddev/homeadditions/.ssh/config + chmod 600 .ddev/homeadditions/.ssh/config + + chmod 700 .ddev/homeadditions/.ssh + - | + if [ "$DRAINPIPE_DDEV_VERSION" != "" ]; then + curl -fsSL https://ddev.com/install.sh | bash -s "v$DRAINPIPE_DDEV_VERSION" + else + curl -fsSL https://ddev.com/install.sh | bash + fi - ddev config global --no-bind-mounts - if [ ! -f ".ddev/config.yaml" ]; then ddev config --auto; fi + - | + if [ "$DRAINPIPE_DDEV_COMPOSER_CACHE_DIR" != "false" ]; then + # @todo Replace /var/www/html with an environment variable. + CACHE_DIR=".ddev/.drainpipe-composer-cache" + if [ "$DRAINPIPE_DDEV_COMPOSER_CACHE_DIR" != "" ]; then + CACHE_DIR="$DRAINPIPE_DDEV_COMPOSER_CACHE_DIR" + fi + ddev config --web-environment-add="COMPOSER_CACHE_DIR=/var/www/html/$CACHE_DIR" + fi - ddev start - ddev describe # Copy git credentials diff --git a/src/ScaffoldInstallerPlugin.php b/src/ScaffoldInstallerPlugin.php index 5837c5173..fad53790b 100644 --- a/src/ScaffoldInstallerPlugin.php +++ b/src/ScaffoldInstallerPlugin.php @@ -225,8 +225,14 @@ private function installCICommands(): void $fs->removeDirectory('./.drainpipe/gitlab'); if (isset($this->extra['drainpipe']['gitlab']) && is_array($this->extra['drainpipe']['gitlab'])) { $fs->ensureDirectoryExists('./.drainpipe/gitlab'); - $fs->copy("$scaffoldPath/gitlab/Common.gitlab-ci.yml", ".drainpipe/gitlab/Common.gitlab-ci.yml"); - $this->io->write("🪠 [Drainpipe] .drainpipe/gitlab/Common.gitlab-ci.yml installed"); + if (file_exists('./.ddev/config.yaml')) { + $fs->copy("$scaffoldPath/gitlab/DDEV.gitlab-ci.yml", ".drainpipe/gitlab/DDEV.gitlab-ci.yml"); + $this->io->write("🪠 [Drainpipe] .drainpipe/gitlab/DDEV.gitlab-ci.yml installed"); + } + else { + $fs->copy("$scaffoldPath/gitlab/Common.gitlab-ci.yml", ".drainpipe/gitlab/Common.gitlab-ci.yml"); + $this->io->write("🪠 [Drainpipe] .drainpipe/gitlab/Common.gitlab-ci.yml installed"); + } foreach ($this->extra['drainpipe']['gitlab'] as $gitlab) { $file = "gitlab/$gitlab.gitlab-ci.yml"; if (file_exists("$scaffoldPath/$file")) {