Skip to content

Commit

Permalink
Add GitLab CI / DDEV support (#339)
Browse files Browse the repository at this point in the history
  • Loading branch information
justafish committed Nov 29, 2023
1 parent 3040fbb commit 24eba25
Show file tree
Hide file tree
Showing 4 changed files with 155 additions and 5 deletions.
45 changes: 44 additions & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,47 @@
include:
- local: 'scaffold/gitlab/DDEV.gitlab-ci.yml'

variables:
DRAINPIPE_DDEV_GIT_EMAIL: [email protected]
DRAINPIPE_DDEV_GIT_NAME: Drainpipe Bot

.drainpipe_setup_drupal:
script:
- sudo apt update
- sudo apt install php-cli unzip -y
- curl -sS https://getcomposer.org/installer -o /tmp/composer-setup.php
- |
HASH=`curl -sS https://composer.github.io/installer.sig`
php -r "if (hash_file('SHA384', '/tmp/composer-setup.php') === '$HASH') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('/tmp/composer-setup.php'); } echo PHP_EOL;"
- sudo php /tmp/composer-setup.php --install-dir=/usr/local/bin --filename=composer
- mkdir drainpipe
- |
shopt -s extglob
shopt -s dotglob
mv !(drainpipe) drainpipe/
- mv drainpipe /tmp/drainpipe
- composer create-project drupal/recommended-project . --ignore-platform-reqs
- mv /tmp/drainpipe .

build:
stage: build
interruptible: true
script:
- echo "Hello, $GITLAB_USER_LOGIN!1!"
- !reference [.drainpipe_setup_drupal, script]
- !reference [.drainpipe_setup_ddev, script]
- 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
- |
ddev composer config repositories.drainpipe --json '{"type": "path", "url": "drainpipe", "options": {"symlink": false}}'
- ddev composer config minimum-stability dev
- ddev composer require lullabot/drainpipe --with-all-dependencies
- ddev restart
- test -f .gitlab/drainpipe/DDEV.gitlab-ci.yml
- ddev drush site:install minimal -y
- echo "\$settings['config_sync_directory'] = '../config';" >> web/sites/default/settings.php
- ddev drush config:export -y
- ddev task update
35 changes: 34 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,40 @@ Add the following to `composer.json` for GitLab helpers:

This will import [`scaffold/gitlab/Common.gitlab-ci.yml`](scaffold/gitlab/Common.gitlab-ci.yml),
which provides helpers that can be used in GitLab CI with [includes and
references](https://docs.gitlab.com/ee/ci/yaml/yaml_specific_features.html#reference-tags).
references](https://docs.gitlab.com/ee/ci/yaml/yaml_specific_features.html#reference-tags),
or `scaffold/gitlab/DDEV.gitlab-ci.yml` if you are using DDEV.

```
include:
- local: '.gitlab/drainpipe/DDEV.gitlab-ci.ymll'
variables:
DRAINPIPE_DDEV_GIT_EMAIL: [email protected]
DRAINPIPE_DDEV_GIT_NAME: Drainpipe Bot
build:
stage: build
interruptible: true
script:
- !reference [.drainpipe_setup_ddev, script]
- composer install
- ddev restart
- ddev drush site:install minimal -y
- echo "\$settings['config_sync_directory'] = '../config';" >> web/sites/default/settings.php
- ddev drush config:export -y
- ddev task update
```

Available variables are:

| Variable | |
|-----------------------------------|------------------------------------------------------------------------------------------------------------------------------------|
| DRAINPIPE_DDEV_SSH_PRIVATE_KEY | SSH private key used for e.g. committing to git |
| DRAINPIPE_DDEV_SSH_KNOWN_HOSTS | The result of running e.g. `ssh-keyscan -H codeserver.dev.$PANTHEON_SITE_ID.drush.in` |
| DRAINPIPE_DDEV_GIT_EMAIL | E-mail address to use for git commits |
| DRAINPIPE_DDEV_GIT_NAME | Name to use for git commits |
| DRAINPIPE_DDEV_COMPOSER_CACHE_DIR | Set to "false" to disable composer cache dir, or another value to override the default location of .ddev/.drainpipe-composer-cache |
| DRAINPIPE_DDEV_VERSION | Install a specific version of DDEV instead of the latest |

### Composer Lock Diff
Updates Merge Request descriptions with a markdown table of any changes detected
Expand Down
66 changes: 66 additions & 0 deletions scaffold/gitlab/DDEV.gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
default:
image: ghcr.io/catthehacker/ubuntu:runner-22.04
services:
- name: docker:dind
alias: docker

variables:
DRAINPIPE_DDEV_SSH_PRIVATE_KEY: ""
DRAINPIPE_DDEV_SSH_KNOWN_HOSTS: ""
DRAINPIPE_DDEV_GIT_EMAIL: [email protected]
DRAINPIPE_DDEV_GIT_NAME: Drainpipe Bot
DRAINPIPE_DDEV_COMPOSER_CACHE_DIR: ""
DRAINPIPE_DDEV_VERSION: ""
DOCKER_HOST: "tcp://docker:2375"
FF_NETWORK_PER_BUILD: 1

cache:
- key:
files:
- composer.lock
- composer.json
paths:
- .ddev/.drainpipe-composer-cache

.drainpipe_setup_ddev:
script:
- sudo chown -R runner:runner $CI_PROJECT_DIR
- |
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
- ddev exec "git config --global user.name \"$DRAINPIPE_DDEV_GIT_NAME\""
- ddev exec "git config --global user.email \"$DRAINPIPE_DDEV_GIT_EMAIL\""
14 changes: 11 additions & 3 deletions src/ScaffoldInstallerPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,12 +224,20 @@ private function installCICommands(): void
// GitLab
$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->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");
}
else {
$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");
}
foreach ($this->extra['drainpipe']['gitlab'] as $gitlab) {
$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");
}
Expand Down

0 comments on commit 24eba25

Please sign in to comment.