From 6f7677b6abae24f0a928c2679be5c7c085ff0278 Mon Sep 17 00:00:00 2001 From: Kevin Wenger Date: Tue, 20 Aug 2024 11:41:06 +0200 Subject: [PATCH 1/2] add support for Drupal 10.4-dev using docker tag 10.3 --- .../workflows/container-structure-test.yml | 8 +- 10/10.4/Dockerfile | 55 +++++++++++ 10/10.4/Makefile | 65 +++++++++++++ 10/10.4/templates/phpunit.xml | 97 +++++++++++++++++++ 10/10.4/tests/config.yaml | 76 +++++++++++++++ 10/10.4/tests/run.sh | 33 +++++++ README.md | 3 +- 7 files changed, 334 insertions(+), 3 deletions(-) create mode 100644 10/10.4/Dockerfile create mode 100644 10/10.4/Makefile create mode 100644 10/10.4/templates/phpunit.xml create mode 100644 10/10.4/tests/config.yaml create mode 100755 10/10.4/tests/run.sh diff --git a/.github/workflows/container-structure-test.yml b/.github/workflows/container-structure-test.yml index 71460b6..6ef4072 100644 --- a/.github/workflows/container-structure-test.yml +++ b/.github/workflows/container-structure-test.yml @@ -9,7 +9,7 @@ jobs: strategy: matrix: - drupal_version: ['8.9', '9.0', '9.1', '9.2', '9.3', '9.4', '9.5', '10.0', '10.1', '10.2', '10.3', '11.0', '11.1'] + drupal_version: ['8.9', '9.0', '9.1', '9.2', '9.3', '9.4', '9.5', '10.0', '10.1', '10.2', '10.3', '10.4', '11.0', '11.1'] include: - drupal_version: '8.9' drupal_major: '8' @@ -33,6 +33,8 @@ jobs: drupal_major: '10' - drupal_version: '10.3' drupal_major: '10' + - drupal_version: '10.4' + drupal_major: '10' - drupal_version: '11.0' drupal_major: '11' - drupal_version: '11.1' @@ -58,7 +60,7 @@ jobs: ', github.ref) strategy: matrix: - drupal_version: ['8.9', '9.0', '9.1', '9.2', '9.3', '9.4', '9.5', '10.0', '10.1', '10.2', '10.3', '11.0', '11.1'] + drupal_version: ['8.9', '9.0', '9.1', '9.2', '9.3', '9.4', '9.5', '10.0', '10.1', '10.2', '10.3', '10.4', '11.0', '11.1'] include: - drupal_version: '8.9' drupal_major: '8' @@ -82,6 +84,8 @@ jobs: drupal_major: '10' - drupal_version: '10.3' drupal_major: '10' + - drupal_version: '10.4' + drupal_major: '10' - drupal_version: '11.0' drupal_major: '11' - drupal_version: '11.1' diff --git a/10/10.4/Dockerfile b/10/10.4/Dockerfile new file mode 100644 index 0000000..89b4fcb --- /dev/null +++ b/10/10.4/Dockerfile @@ -0,0 +1,55 @@ +ARG BASE_IMAGE_TAG +FROM drupal:${BASE_IMAGE_TAG}-apache + +ARG DRUPAL_VER + +ENV COMPOSER_ALLOW_SUPERUSER=1 +ENV DRUPAL_VER="${DRUPAL_VER}" + +WORKDIR /opt/drupal + +# Install git and zip library. +# Necessary for some composer operations. +RUN set -eux; \ + \ + apt-get update; \ + apt-get install -y \ + git \ + zip \ + unzip \ + ; + +# Install wait-for-it script to be able to check if services are up. +RUN curl -OL https://raw.githubusercontent.com/vishnubob/wait-for-it/master/wait-for-it.sh && \ + chmod +x wait-for-it.sh && \ + mv wait-for-it.sh /usr/local/bin/wait-for-it + +# As of Composer 2.2.0, the allow-plugins option adds a layer of security. +# Some plugin Installer must be authorized. Not allowing it may lead to an instance of Drupal +# installed into the vendor directory. +RUN composer config --no-interaction allow-plugins true + +# Install Drush. +# Drush will be heavily use to setup a working Drupal environment. +RUN COMPOSER_MEMORY_LIMIT=-1 composer require drush/drush:^12.0 + +# Prepare for Drupal 10.4 upgrade. +# @see https://www.drupal.org/docs/upgrading-drupal/upgrading-from-drupal-8-to-drupal-9-or-higher +RUN composer require drupal/core-recommended:~${DRUPAL_VER} --update-with-all-dependencies --no-update +RUN composer require drupal/core-dev:~${DRUPAL_VER} --dev --update-with-all-dependencies --no-update + +# Set the minimum stability to "dev" to allow installing unstable Drupal Core. +RUN composer config minimum-stability dev + +# Perform Drupal 10.1 installation. +RUN COMPOSER_MEMORY_LIMIT=-1 composer update --with-all-dependencies + +# Clean repository. +RUN apt-get clean && rm -rf /var/lib/apt/lists/* + +# Copy a default template for PHPUnit testing. +COPY templates/phpunit.xml /opt/drupal/web/phpunit.xml + +# Create the output directory for PHPUnit. +RUN mkdir -p /opt/drupal/web/sites/default/files/simpletest/browser_output +RUN chown www-data:www-data /opt/drupal/web/sites/default/files/simpletest/browser_output diff --git a/10/10.4/Makefile b/10/10.4/Makefile new file mode 100644 index 0000000..4d2135c --- /dev/null +++ b/10/10.4/Makefile @@ -0,0 +1,65 @@ +DRUPAL_VER ?= 10.4 +DRUPAL_VER_MAJOR ?= $(shell echo "${DRUPAL_VER}" | grep -oE '^[0-9]+\.[0-9]+') + +BASE_IMAGE_TAG = 10.3 +ARCH_TO_BUILD ?= "linux/amd64" + +REPO = wengerk/drupal-for-contrib +NAME = drupal-$(DRUPAL_VER_MAJOR) + +TAG ?= $(DRUPAL_VER_MAJOR) + +ifneq ($(BASE_IMAGE_STABILITY_TAG),) + BASE_IMAGE_TAG := $(BASE_IMAGE_TAG)-$(BASE_IMAGE_STABILITY_TAG) +endif + +ifneq ($(STABILITY_TAG),) + ifneq ($(TAG),latest) + override TAG := $(TAG)-$(STABILITY_TAG) + endif +endif + +.PHONY: build test push shell run start stop logs clean release + +default: build + +build: + docker buildx build -t $(REPO):$(TAG) \ + --platform=${ARCH_TO_BUILD} \ + --build-arg BASE_IMAGE_TAG=$(BASE_IMAGE_TAG) \ + --build-arg DRUPAL_VER=$(DRUPAL_VER) \ + ./ + +build-nc: + docker buildx build -t $(REPO):$(TAG) \ + --platform=${ARCH_TO_BUILD} \ + --build-arg BASE_IMAGE_TAG=$(BASE_IMAGE_TAG) \ + --build-arg DRUPAL_VER=$(DRUPAL_VER) \ + --no-cache --pull \ + ./ + +test: + cd ./tests && IMAGE=$(REPO):$(TAG) ./run.sh + +push: + docker push $(REPO):$(TAG) + +shell: + docker run --rm --name $(NAME) -i -t $(PORTS) $(VOLUMES) $(ENV) $(REPO):$(TAG) /bin/bash + +run: + docker run --rm --name $(NAME) $(PORTS) $(VOLUMES) $(ENV) $(REPO):$(TAG) $(CMD) + +start: + docker run -d --name $(NAME) $(PORTS) $(VOLUMES) $(ENV) $(REPO):$(TAG) + +stop: + docker stop $(NAME) + +logs: + docker logs $(NAME) + +clean: + -docker rm -f $(NAME) + +release: build push diff --git a/10/10.4/templates/phpunit.xml b/10/10.4/templates/phpunit.xml new file mode 100644 index 0000000..6b39a89 --- /dev/null +++ b/10/10.4/templates/phpunit.xml @@ -0,0 +1,97 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ./core/tests/TestSuites/UnitTestSuite.php + + + ./core/tests/TestSuites/KernelTestSuite.php + + + ./core/tests/TestSuites/FunctionalTestSuite.php + + + ./core/tests/TestSuites/FunctionalJavascriptTestSuite.php + + + ./core/tests/TestSuites/BuildTestSuite.php + + + + + + + + + + ./modules + + + ./modules/*/src/Tests + ./modules/*/tests + ./modules/*/*/src/Tests + ./modules/*/*/tests + ./modules/** + + + diff --git a/10/10.4/tests/config.yaml b/10/10.4/tests/config.yaml new file mode 100644 index 0000000..17184d8 --- /dev/null +++ b/10/10.4/tests/config.yaml @@ -0,0 +1,76 @@ +schemaVersion: '2.0.0' +metadataTest: + envVars: + - key: 'DRUPAL_VER' + value: '10.4' + workdir: '/opt/drupal' + exposedPorts: ['80'] +commandTests: + - name: 'Drupal Root location' + command: 'drush' + args: ['status'] + expectedOutput: ['Drupal root\s+:\s+/opt/drupal/web'] + - name: 'Drupal version' + command: 'drush' + args: ['status'] + expectedOutput: ['Drupal version\s+:\s+10\.4\.(x|\d+)(-(alpha|beta|dev|rc))?'] + - name: 'Drupal Core Dev version' + command: bash + args: ['-c', 'composer show drupal/core-dev'] + expectedOutput: ['versions\s+:\s\* 10\.4\.(x|\d+)(-(alpha|beta|dev|rc))?'] + - name: 'Drush location' + command: 'drush' + args: ['status'] + expectedOutput: ['Drush script\s+:\s+/opt/drupal/vendor/bin/drush'] + - name: 'Drush version' + command: 'drush' + args: ['status'] + expectedOutput: ['Drush version\s+:\s+12\.\d\.\d'] + - name: 'PHPUnit location' + command: 'which' + args: ['phpunit'] + expectedOutput: ['/opt/drupal/vendor/bin/phpunit'] + - name: 'PHPUnit version' + command: 'phpunit' + args: ['--version'] + expectedOutput: ['^PHPUnit 9\.\d\.\d'] + - name: 'PHPUnit configuration file should works' + command: 'phpunit' + args: ['-c', '/var/www/html/phpunit.xml', '--group', 'foo'] + exitCode: 0 + expectedOutput: [ 'No tests executed!' ] + excludedOutput: [ 'is not a writable directory.' ] +fileExistenceTests: + - name: 'Root' + path: '/' + shouldExist: true + permissions: 'drwxr-xr-x' + uid: 0 + gid: 0 + - name: 'PHPUnit default file' + path: '/opt/drupal/web/phpunit.xml' + shouldExist: true + - name: 'Wait-for-it script' + path: '/usr/local/bin/wait-for-it' + shouldExist: true + permissions: '-rwxr-xr-x' + uid: 0 + gid: 0 + - name: 'Drupal Root' + path: '/opt/drupal/web' + shouldExist: true + permissions: 'drwxr-xr-x' + uid: 0 + gid: 0 + - name: 'Drupal Public' + path: '/opt/drupal/web/sites/default' + shouldExist: true + permissions: 'drwxr-xr-x' + uid: 33 + gid: 33 + - name: 'Drupal PHPUnit Output' + path: '/opt/drupal/web/sites/default/files/simpletest/browser_output' + shouldExist: true + permissions: 'drwxr-xr-x' + uid: 33 + gid: 33 diff --git a/10/10.4/tests/run.sh b/10/10.4/tests/run.sh new file mode 100755 index 0000000..c6cb649 --- /dev/null +++ b/10/10.4/tests/run.sh @@ -0,0 +1,33 @@ +#!/usr/bin/env bash +set -e + +if [[ -n "${DEBUG}" ]]; then + set -x +fi + +if ! [ -x "$(command -v container-structure-test)" ]; then + echo -n "Install Google Container Structure Tests Framework for ${IMAGE} ..." + + # Check install for Linux or MacOS. + if [[ $(uname -s) == Linux ]] + then + curl -LO https://storage.googleapis.com/container-structure-test/latest/container-structure-test-linux-amd64 && chmod +x container-structure-test-linux-amd64 && sudo mv container-structure-test-linux-amd64 /usr/local/bin/container-structure-test + elif [[ $(uname -s) == Darwin ]] + then + curl -LO https://storage.googleapis.com/container-structure-test/latest/container-structure-test-darwin-amd64 && chmod +x container-structure-test-darwin-amd64 && sudo mv container-structure-test-darwin-amd64 /usr/local/bin/container-structure-test + fi +fi + +if ! [ -x "$(command -v container-structure-test)" ]; then + echo 'Error: container-structure-test is not installed.' >&2 + exit 1 +fi + +echo -n "Running tests for ${IMAGE}..." + +cid="$( + docker run -d "${IMAGE}" +)" +trap "docker rm -vf ${cid} > /dev/null" EXIT + +container-structure-test test --image ${IMAGE} --config config.yaml diff --git a/README.md b/README.md index d996275..58da437 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,8 @@ Overview: |--------------------------------------------------------------------------------------------------------------|----------| | `11.1` [_(Dockerfile)_](https://github.com/wengerk/docker-drupal-for-contrib/tree/master/11/11.1/Dockerfile) | 11.x-dev | | `11.0` [_(Dockerfile)_](https://github.com/wengerk/docker-drupal-for-contrib/tree/master/11/11.0/Dockerfile) | 11.0.x | -| `10.3` [_(Dockerfile)_](https://github.com/wengerk/docker-drupal-for-contrib/tree/master/10/10.3/Dockerfile) | 10.3.0+ | +| `10.4` [_(Dockerfile)_](https://github.com/wengerk/docker-drupal-for-contrib/tree/master/10/10.4/Dockerfile) | 10.4-dev | +| `10.3` [_(Dockerfile)_](https://github.com/wengerk/docker-drupal-for-contrib/tree/master/10/10.3/Dockerfile) | 10.3-dev | | `10.2` [_(Dockerfile)_](https://github.com/wengerk/docker-drupal-for-contrib/tree/master/10/10.2/Dockerfile) | 10.2.0+ | | `10.1` [_(Dockerfile)_](https://github.com/wengerk/docker-drupal-for-contrib/tree/master/10/10.1/Dockerfile) | 10.1.0+ | | `10.0` [_(Dockerfile)_](https://github.com/wengerk/docker-drupal-for-contrib/tree/master/10/10.0/Dockerfile) | 10.0.0+ | From b04ac74189da1e6a8ea0b071c6256b332d19562a Mon Sep 17 00:00:00 2001 From: Kevin Wenger Date: Tue, 20 Aug 2024 13:53:33 +0200 Subject: [PATCH 2/2] fix output directory for Drupal 11.x tests --- 11/11.0/Dockerfile | 4 ++++ 11/11.0/templates/phpunit.xml | 2 +- 11/11.0/tests/config.yaml | 3 +++ 11/11.1/Dockerfile | 4 ++++ 11/11.1/templates/phpunit.xml | 2 +- 11/11.1/tests/config.yaml | 2 ++ 6 files changed, 15 insertions(+), 2 deletions(-) diff --git a/11/11.0/Dockerfile b/11/11.0/Dockerfile index 2fa15cd..363dd19 100644 --- a/11/11.0/Dockerfile +++ b/11/11.0/Dockerfile @@ -41,3 +41,7 @@ RUN apt-get clean && rm -rf /var/lib/apt/lists/* # Copy a default template for PHPUnit testing. COPY templates/phpunit.xml /opt/drupal/web/phpunit.xml + +# Create the output directory for PHPUnit. +RUN mkdir -p /opt/drupal/web/sites/default/files/simpletest/browser_output +RUN chown www-data:www-data /opt/drupal/web/sites/default/files/simpletest/browser_output diff --git a/11/11.0/templates/phpunit.xml b/11/11.0/templates/phpunit.xml index abbd22f..5efb838 100644 --- a/11/11.0/templates/phpunit.xml +++ b/11/11.0/templates/phpunit.xml @@ -65,7 +65,7 @@ overridden by the value set for the "BROWSERTEST_OUTPUT_DIRECTORY" environment variable. --> - + - +