Skip to content

Commit

Permalink
Merge pull request #52 from WengerK/feature/drupal-10.3-dev
Browse files Browse the repository at this point in the history
add support for Drupal 10.3.0-dev using docker tag 10.3
  • Loading branch information
WengerK authored Mar 12, 2024
2 parents aec08f7 + 82de02e commit 06b7db8
Show file tree
Hide file tree
Showing 7 changed files with 339 additions and 3 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/container-structure-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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', '11.0']
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']
include:
- drupal_version: '8.9'
drupal_major: '8'
Expand All @@ -31,6 +31,8 @@ jobs:
drupal_major: '10'
- drupal_version: '10.2'
drupal_major: '10'
- drupal_version: '10.3'
drupal_major: '10'
- drupal_version: '11.0'
drupal_major: '11'
steps:
Expand All @@ -54,7 +56,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', '11.0']
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']
include:
- drupal_version: '8.9'
drupal_major: '8'
Expand All @@ -76,6 +78,8 @@ jobs:
drupal_major: '10'
- drupal_version: '10.2'
drupal_major: '10'
- drupal_version: '10.3'
drupal_major: '10'
- drupal_version: '11.0'
drupal_major: '11'
steps:
Expand Down
51 changes: 51 additions & 0 deletions 10/10.3/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
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.3 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
65 changes: 65 additions & 0 deletions 10/10.3/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
DRUPAL_VER ?= 10.3
DRUPAL_VER_MAJOR ?= $(shell echo "${DRUPAL_VER}" | grep -oE '^[0-9]+\.[0-9]+')

BASE_IMAGE_TAG = 10.2
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
118 changes: 118 additions & 0 deletions 10/10.3/templates/phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
<?xml version="1.0" encoding="UTF-8"?>

<!-- For how to customize PHPUnit configuration, see core/tests/README.md. -->
<!-- TODO set checkForUnintentionallyCoveredCode="true" once https://www.drupal.org/node/2626832 is resolved. -->
<!-- PHPUnit expects functional tests to be run with either a privileged user
or your current system user. See core/tests/README.md and
https://www.drupal.org/node/2116263 for details.
-->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
bootstrap="core/tests/bootstrap.php" colors="true"
beStrictAboutTestsThatDoNotTestAnything="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutChangesToGlobalState="true"
failOnWarning="true"
printerClass="\Drupal\Tests\Listeners\HtmlOutputPrinter"
cacheResult="false"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<php>
<!-- Set error reporting to E_ALL. -->
<ini name="error_reporting" value="32767"/>
<!-- Do not limit the amount of memory tests take to run. -->
<ini name="memory_limit" value="-1"/>
<!-- Example SIMPLETEST_BASE_URL value: http://localhost -->
<env name="SIMPLETEST_BASE_URL" value="http://drupal"/>
<!-- Example SIMPLETEST_DB value: mysql://username:password@localhost/databasename#table_prefix -->
<env name="SIMPLETEST_DB" value="mysql://drupal:drupal@db/drupal"/>
<!-- Example BROWSERTEST_OUTPUT_DIRECTORY value: /path/to/webroot/sites/simpletest/browser_output -->
<env name="BROWSERTEST_OUTPUT_DIRECTORY" value="/opt/drupal/web/sites/default/files/simpletest/browser_output"/>
<!-- To have browsertest output use an alternative base URL. For example if
SIMPLETEST_BASE_URL is an internal DDEV URL, you can set this to the
external DDev URL so you can follow the links directly.
-->
<env name="BROWSERTEST_OUTPUT_BASE_URL" value=""/>

<!-- Deprecation testing is managed through Symfony's PHPUnit Bridge.
The environment variable SYMFONY_DEPRECATIONS_HELPER is used to configure
the behaviour of the deprecation tests.
See https://symfony.com/doc/current/components/phpunit_bridge.html#configuration
Drupal core's testing framework is setting this variable to its defaults.
Projects with their own requirements need to manage this variable
explicitly.
-->
<!-- To disable deprecation testing completely uncomment the next line. -->
<!-- <env name="SYMFONY_DEPRECATIONS_HELPER" value="disabled"/> -->
<!-- Deprecation errors can be selectively ignored by specifying a file of
regular expression patterns for exclusion.
See https://symfony.com/doc/current/components/phpunit_bridge.html#ignoring-deprecations
Uncomment the line below to specify a custom deprecations ignore file.
NOTE: it may be required to specify the full path to the file to run tests
correctly.
-->
<!-- <env name="SYMFONY_DEPRECATIONS_HELPER" value="ignoreFile=.deprecation-ignore.txt"/> -->

<!-- To disable deprecation testing completely uncomment the next line. -->
<!-- <env name="SYMFONY_DEPRECATIONS_HELPER" value="disabled"/> -->
<!-- Example for changing the driver class for mink tests MINK_DRIVER_CLASS value: 'Drupal\FunctionalJavascriptTests\DrupalSelenium2Driver' -->
<env name="MINK_DRIVER_CLASS" value=''/>
<!-- Example for changing the driver args to mink tests MINK_DRIVER_ARGS value: '["http://127.0.0.1:8510"]' -->
<env name="MINK_DRIVER_ARGS" value=''/>
<!-- Example for changing the driver args to webdriver tests MINK_DRIVER_ARGS_WEBDRIVER value: '["chrome", { "chromeOptions": { "w3c": false } }, "http://localhost:4444/wd/hub"]' For using the Firefox browser, replace "chrome" with "firefox" -->
<env name="MINK_DRIVER_ARGS_WEBDRIVER" value='["chrome", {"browserName":"chrome","chromeOptions":{"args":["--disable-gpu","--headless", "--no-sandbox", "--disable-dev-shm-usage"]}}, "http://chrome:9515"]'/>
</php>
<testsuites>
<testsuite name="unit">
<file>./core/tests/TestSuites/UnitTestSuite.php</file>
</testsuite>
<testsuite name="kernel">
<file>./core/tests/TestSuites/KernelTestSuite.php</file>
</testsuite>
<testsuite name="functional">
<file>./core/tests/TestSuites/FunctionalTestSuite.php</file>
</testsuite>
<testsuite name="functional-javascript">
<file>./core/tests/TestSuites/FunctionalJavascriptTestSuite.php</file>
</testsuite>
<testsuite name="build">
<file>./core/tests/TestSuites/BuildTestSuite.php</file>
</testsuite>
</testsuites>
<listeners>
<listener class="\Drupal\Tests\Listeners\DrupalListener">
</listener>
<!-- The Symfony deprecation listener has to come after the Drupal listener -->
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener">
</listener>
</listeners>
<!-- Filter for coverage reports. -->
<filter>
<whitelist>
<directory>./core/includes</directory>
<directory>./core/lib</directory>
<directory>./core/modules</directory>
<!-- Extensions can have their own test directories, so exclude those. -->
<exclude>
<directory>./core/modules/*/src/Tests</directory>
<directory>./core/modules/*/tests</directory>
</exclude>
<directory>./modules</directory>
<exclude>
<directory>./modules/*/src/Tests</directory>
<directory>./modules/*/tests</directory>
<directory>./modules/*/*/src/Tests</directory>
<directory>./modules/*/*/tests</directory>
</exclude>
<directory>./sites</directory>
<!-- By definition test classes have no tests. -->
<exclude>
<directory suffix="Test.php">./</directory>
<directory suffix="TestBase.php">./</directory>
</exclude>
</whitelist>
</filter>
<!-- Logging for coverage reports. -->
<logging>
<log type="coverage-clover" target="./build/logs/clover.xml"/>
<log type="coverage-html" target="./build/logs/coverage-html"/>
</logging>
</phpunit>
64 changes: 64 additions & 0 deletions 10/10.3/tests/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
schemaVersion: '2.0.0'
metadataTest:
envVars:
- key: 'DRUPAL_VER'
value: '10.3'
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\.3\.(alpha|beta|dev|rc|\d+)']
- name: 'Drupal Core Dev version'
command: bash
args: ['-c', 'composer show drupal/core-dev']
expectedOutput: ['versions\s+:\s\* 10\.3\.(x|0)(-(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']
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
33 changes: 33 additions & 0 deletions 10/10.3/tests/run.sh
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ All of those images serve the same purpose, **integrate Docker into a complete D

This image is way different as we don't want to solve the Docker integration with Drupal but give a **solution to setup a Docker on Contributions modules or themes**.

I see way too many developers creating awesome modules and struggling to test them by having to bootstrap a complete clean Drupal 8/9 environment and symlinks the custom modules/themes inside it.
I see way too many developers creating awesome modules and struggling to test them by having to bootstrap a complete clean Drupal 8/9/10/11 environment and symlinks the custom modules/themes inside it.
With this Docker image, I want to highly simplify this process by having a containerized Drupal 8/9 used for manual or automated testing of modules/themes Contributions projects.

## Docker Images
Expand All @@ -25,6 +25,7 @@ Overview:
| Supported tags and respective `Dockerfile` links | Drupal |
|------------------------------------------------------------------------------------------------------------------|----------|
| `11.x-dev` [_(Dockerfile)_](https://github.com/wengerk/docker-drupal-for-contrib/tree/master/11/11.0/Dockerfile) | 11.0-dev |
| `10.3` [_(Dockerfile)_](https://github.com/wengerk/docker-drupal-for-contrib/tree/master/10/10.3/Dockerfile) | 10.3.0+ |
| `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+ |
Expand Down

0 comments on commit 06b7db8

Please sign in to comment.