feat: add Drupal files
Some checks are pending
CI / Build and test (push) Waiting to run

This commit is contained in:
Oliver Davies 2023-10-12 22:53:25 +01:00
parent 3917f60cd2
commit cc2e182cad
21 changed files with 11185 additions and 0 deletions

2
.dockerignore Normal file
View file

@ -0,0 +1,2 @@
/README.md
/.github/

12
.env.example Normal file
View file

@ -0,0 +1,12 @@
# Do not edit this file. It is automatically generated by https://www.oliverdavies.uk/build-configs.
export DOCKER_UID=1000
export COMPOSE_PROJECT_NAME=oliverdavies-uk
export COMPOSE_PROFILES=web,php,database
export DOCKER_WEB_VOLUME=.:/app
export MYSQL_DATABASE=app
export MYSQL_PASSWORD=app
export MYSQL_USER=app

7
.githooks/pre-push Executable file
View file

@ -0,0 +1,7 @@
#!/usr/bin/env bash
# Do not edit this file. It is automatically generated by https://www.oliverdavies.uk/build-configs.
set -euo pipefail
just test-commit

25
.githooks/prepare-commit-msg Executable file
View file

@ -0,0 +1,25 @@
#!/usr/bin/env bash
# Do not edit this file. It is automatically generated by https://www.oliverdavies.uk/build-configs.
# Load the issue ID from an `.issue-id` file within the project and replace the
# `ISSUE_ID` placeholder within a Git commit message.
#
# For example, running `echo "OD-123" > .issue-id` will add `Refs: OD-123` to
# the commit message.
#
# This also works with multiple issue IDs in the same string, e.g.
# "OD-123 OD-456", or IDs on multiple lines.
set -euo pipefail
PROJECT_DIR=$(git rev-parse --show-toplevel)
ISSUE_FILE="$PROJECT_DIR/.issue-id"
if [ -f "${ISSUE_FILE}" ]; then
ISSUE_IDS=$(cat "${ISSUE_FILE}" | tr '\n' ',' | tr ' ' ',' | sed 's/,$//' | sed 's/,/, /g')
if [ -n "${ISSUE_IDS}" ]; then
sed -i.bak "s/# Refs:/Refs: $ISSUE_IDS/" "$1"
fi
fi

25
.github/workflows/ci.yml vendored Normal file
View file

@ -0,0 +1,25 @@
name: CI
on:
pull_request:
push:
workflow_dispatch:
env:
COMPOSE_DOCKER_CLI_BUILD: 1
DOCKER_BUILDKIT: 1
DOCKER_UID: 1001
jobs:
build_and_test:
name: Build and test
runs-on: ubuntu-latest
steps:
- name: Checkout the code
uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f # v2.3.4
- name: Build and test
run: |
./run ci:test

44
.gitignore vendored Normal file
View file

@ -0,0 +1,44 @@
# Do not edit this file. It is automatically generated by https://www.oliverdavies.uk/build-configs.
.editorconfig
.env
.gitattributes
vendor/
web/.csslintrc
web/.eslintignore
web/.eslintrc.json
web/.ht.router.php
web/.htaccess
web/INSTALL.txt
web/README.md
web/autoload.php
web/core/
web/example.gitignore
web/index.php
web/modules/README.txt
web/modules/contrib/
web/profiles/README.txt
web/robots.txt
web/sites/*/files/
web/sites/*/private/
web/sites/*/services*.yml
web/sites/*/settings*.php
web/sites/README.txt
web/sites/default/default.services.yml
web/sites/default/default.settings.php
web/sites/development.services.yml
web/sites/example.settings.local.php
web/sites/example.sites.php
web/sites/simpletest/
web/themes/README.txt
web/themes/contrib/
web/update.php
web/web.config
# Databases.
*.sql
*.sql.*
# Docker.
.env
docker-compose.override.yaml

2
.hadolint.yaml Normal file
View file

@ -0,0 +1,2 @@
ignore:
- DL3059

64
Dockerfile Normal file
View file

@ -0,0 +1,64 @@
# Do not edit this file. It is automatically generated by https://www.oliverdavies.uk/build-configs.
FROM php:8.1-fpm-bullseye AS base
COPY --from=composer:2 /usr/bin/composer /usr/bin/composer
RUN which composer && composer -V
ARG DOCKER_UID=1000
ENV DOCKER_UID="${DOCKER_UID}"
WORKDIR /app
RUN adduser --disabled-password --uid "${DOCKER_UID}" app \
&& chown app:app -R /app
USER app
ENV PATH="${PATH}:/app/bin:/app/vendor/bin"
COPY --chown=app:app composer.* ./
################################################################################
FROM base AS build
USER root
RUN apt-get update -yqq \
&& apt-get install -yqq --no-install-recommends \
git libpng-dev libjpeg-dev libzip-dev mariadb-client unzip \
&& rm -rf /var/lib/apt/lists/* /usr/share/doc /usr/share/man \
&& apt-get clean
RUN docker-php-ext-configure gd --with-jpeg
RUN docker-php-ext-install gd pdo_mysql zip
COPY --chown=app:app phpunit.xml* ./
USER app
RUN composer validate
RUN composer install
COPY --chown=app:app tools/docker/images/php/root /
ENTRYPOINT ["/usr/local/bin/docker-entrypoint-php"]
CMD ["php-fpm"]
################################################################################
FROM nginx:1 as web
EXPOSE 8080
WORKDIR /app
COPY tools/docker/images/web/root /

44
build.yaml Normal file
View file

@ -0,0 +1,44 @@
name: docker-example-drupal
language: php
type: drupal
web:
type: nginx
database:
type: mariadb
version: 10
php:
version: 8.1-fpm-bullseye
phpcs:
paths:
- web/modules/custom
standards:
- Drupal
- DrupalPractice
phpstan:
level: max
paths:
- web/modules/custom
drupal:
docroot: web
docker-compose:
services:
- database
- php
- web
dockerfile:
stages:
build:
commands:
- composer validate
- composer install
experimental:
createGitHubActionsConfiguration: true
runGitHooksBeforePush: true
useNewDatabaseCredentials: true

101
composer.json Normal file
View file

@ -0,0 +1,101 @@
{
"name": "drupal/recommended-project",
"description": "Project template for Drupal 9 projects with a relocated document root",
"type": "project",
"license": "GPL-2.0-or-later",
"homepage": "https://www.drupal.org/project/drupal",
"support": {
"docs": "https://www.drupal.org/docs/user_guide/en/index.html",
"chat": "https://www.drupal.org/node/314178"
},
"repositories": [
{
"type": "composer",
"url": "https://packages.drupal.org/8"
}
],
"require": {
"composer/installers": "^1.9",
"drupal/core-composer-scaffold": "^10",
"drupal/core-project-message": "^10",
"drupal/core-recommended": "^10",
"drupal/examples": "^4.0",
"drush/drush": "^11.0"
},
"conflict": {
"drupal/drupal": "*"
},
"minimum-stability": "stable",
"prefer-stable": true,
"config": {
"sort-packages": true,
"allow-plugins": {
"composer/installers": true,
"drupal/core-composer-scaffold": true,
"drupal/core-project-message": true,
"dealerdirect/phpcodesniffer-composer-installer": true,
"phpstan/extension-installer": true
}
},
"extra": {
"drupal-scaffold": {
"locations": {
"web-root": "web/"
}
},
"installer-paths": {
"web/core": [
"type:drupal-core"
],
"web/libraries/{$name}": [
"type:drupal-library"
],
"web/modules/contrib/{$name}": [
"type:drupal-module"
],
"web/profiles/contrib/{$name}": [
"type:drupal-profile"
],
"web/themes/contrib/{$name}": [
"type:drupal-theme"
],
"drush/Commands/contrib/{$name}": [
"type:drupal-drush"
],
"web/modules/custom/{$name}": [
"type:drupal-custom-module"
],
"web/profiles/custom/{$name}": [
"type:drupal-custom-profile"
],
"web/themes/custom/{$name}": [
"type:drupal-custom-theme"
]
},
"drupal-core-project-message": {
"include-keys": [
"homepage",
"support"
],
"post-create-project-cmd-message": [
"<bg=blue;fg=white> </>",
"<bg=blue;fg=white> Congratulations, youve installed the Drupal codebase </>",
"<bg=blue;fg=white> from the drupal/recommended-project template! </>",
"<bg=blue;fg=white> </>",
"",
"<bg=yellow;fg=black>Next steps</>:",
" * Install the site: https://www.drupal.org/docs/8/install",
" * Read the user guide: https://www.drupal.org/docs/user_guide/en/index.html",
" * Get support: https://www.drupal.org/support",
" * Get involved with the Drupal community:",
" https://www.drupal.org/getting-involved",
" * Remove the plugin that prints this message:",
" composer remove drupal/core-project-message"
]
}
},
"require-dev": {
"drupal/core-dev": "^10",
"phpspec/prophecy-phpunit": "^2"
}
}

10533
composer.lock generated Normal file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,8 @@
services:
php-fpm:
extra_hosts:
- "host.docker.internal:host-gateway"
web:
ports:
- "80:80"

79
docker-compose.yaml Normal file
View file

@ -0,0 +1,79 @@
# Do not edit this file. It is automatically generated by https://www.oliverdavies.uk/build-configs.
x-proxy: &default-proxy
networks:
- default
- web
labels:
- "traefik.docker.network=traefik_proxy"
- "traefik.http.routers.${COMPOSE_PROJECT_NAME}.rule=Host(
`${COMPOSE_PROJECT_NAME}.localhost`,
)"
x-app: &default-app
volumes:
- "${DOCKER_WEB_VOLUME:-./web:/app/web}"
env_file:
- .env
restart: "${DOCKER_RESTART_POLICY:-unless-stopped}"
networks:
- default
deploy:
resources:
limits:
cpus: "${DOCKER_MYSQL_CPUS:-0}"
memory: "${DOCKER_MYSQL_MEMORY:-0}"
labels:
- "traefik.enabled=false"
tty: true
services:
web:
<<: [*default-proxy, *default-app]
build:
context: .
target: web
depends_on:
- php
profiles: [web]
ports:
- 81:80
php:
<<: [*default-app]
build:
context: .
target: build
args:
- "DOCKER_UID=${DOCKER_UID:-1000}"
volumes:
- .:/app
depends_on:
- database
profiles: [php]
database:
image: mariadb:10
deploy:
resources:
limits:
cpus: "${DOCKER_MYSQL_CPUS:-0}"
memory: "${DOCKER_MYSQL_MEMORY:-0}"
volumes:
- db-data:/var/lib/mysql
env_file:
- .env
labels:
- "traefik.enabled=false"
environment:
MYSQL_RANDOM_ROOT_PASSWORD: true
profiles: [database]
volumes:
db-data: {}
networks:
web:
external: true
name: traefik_proxy

32
phpcs.xml.dist Normal file
View file

@ -0,0 +1,32 @@
<?xml version="1.0"?>
<!-- Do not edit this file. It is automatically generated by https://www.oliverdavies.uk/build-configs. -->
<ruleset name="docker-example-drupal coding standards">
<description>PHPCS configuration file for docker-example-drupal.</description>
<file>web/modules/custom</file>
<arg value="np"/>
<rule ref="DrupalPractice"/>
<rule ref="Drupal">
<exclude name="Drupal.Commenting.ClassComment.Missing"/>
<exclude name="Drupal.Commenting.DataTypeNamespace.DataTypeNamespace"/>
<exclude name="Drupal.Commenting.Deprecated"/>
<exclude name="Drupal.Commenting.DocComment.ContentAfterOpen"/>
<exclude name="Drupal.Commenting.DocComment.MissingShort"/>
<exclude name="Drupal.Commenting.FunctionComment.IncorrectParamVarName"/>
<exclude name="Drupal.Commenting.FunctionComment.IncorrectTypeHint"/>
<exclude name="Drupal.Commenting.FunctionComment.InvalidReturn"/>
<exclude name="Drupal.Commenting.FunctionComment.Missing"/>
<exclude name="Drupal.Commenting.FunctionComment.MissingParamComment"/>
<exclude name="Drupal.Commenting.FunctionComment.MissingReturnComment"/>
<exclude name="Drupal.Commenting.FunctionComment.ParamTypeSpaces"/>
<exclude name="Drupal.Commenting.FunctionComment.TypeHintMissing"/>
<exclude name="Drupal.Commenting.InlineComment.DocBlock"/>
<exclude name="Drupal.Commenting.VariableComment.Missing"/>
<exclude name="Drupal.NamingConventions.ValidFunctionName.ScopeNotCamelCaps"/>
<exclude name="DrupalPractice.Objects.StrictSchemaDisabled.StrictConfigSchema"/>
</rule>
</ruleset>

9
phpstan.neon.dist Normal file
View file

@ -0,0 +1,9 @@
# Do not edit this file. It is automatically generated by https://www.oliverdavies.uk/build-configs.
parameters:
level: max
excludePaths:
- *Test.php
- *TestBase.php
paths:
- web/modules/custom

37
phpunit.xml.dist Normal file
View file

@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Do not edit this file. It is automatically generated by https://www.oliverdavies.uk/build-configs. -->
<phpunit
beStrictAboutChangesToGlobalState="true"
beStrictAboutOutputDuringTests="false"
beStrictAboutTestsThatDoNotTestAnything="true"
bootstrap="web/core/tests/bootstrap.php"
cacheResult="false"
colors="true"
failOnWarning="true"
printerClass="\Drupal\Tests\Listeners\HtmlOutputPrinter"
>
<php>
<env name="BROWSERTEST_OUTPUT_BASE_URL" value=""/>
<env name="BROWSERTEST_OUTPUT_DIRECTORY" value=""/>
<env name="MINK_DRIVER_ARGS" value=''/>
<env name="MINK_DRIVER_ARGS_WEBDRIVER" value=''/>
<env name="MINK_DRIVER_CLASS" value=''/>
<env name="SIMPLETEST_BASE_URL" value="http://web"/>
<env name="SIMPLETEST_DB" value="sqlite://localhost//dev/shm/test.sqlite"/>
<ini name="error_reporting" value="32767"/>
<ini name="memory_limit" value="-1"/>
</php>
<testsuites>
<testsuite name="functional">
<directory>./web/modules/custom/**/tests/**/Functional</directory>
</testsuite>
<testsuite name="kernel">
<directory>./web/modules/custom/**/tests/**/Kernel</directory>
</testsuite>
<testsuite name="unit">
<directory>./web/modules/custom/**/tests/**/Unit</directory>
</testsuite>
</testsuites>
</phpunit>

122
run Executable file
View file

@ -0,0 +1,122 @@
#!/usr/bin/env bash
# Do not edit this file. It is automatically generated by https://www.oliverdavies.uk/build-configs.
set -eu
# Run automated tests as part of the Continuous Integration (CI) pipeline.
function ci:test {
lint:dockerfile
docker compose version
docker network create traefik_proxy
cp --no-clobber .env.example .env
docker compose build --progress plain
docker compose up --detach
docker compose logs
composer install --quiet --no-progress
test --testdox
quality
}
# Run a command within the php container.
function cmd {
docker compose exec php "${@}"
}
function coding-standards {
cmd phpcs "${@}"
}
function composer {
_exec php composer "${@}"
}
function drush {
_exec php drush "${@}"
}
function git-hooks:off {
git config --unset core.hooksPath
}
function git-hooks:on {
git config core.hooksPath .githooks
}
# Display a list of all available commands.
function help {
printf "%s <task> [args]\n\nTasks:\n" "${0}"
compgen -A function | grep -v "^_" | cat -n
printf "\nExtended help:\n Each task has comments for general usage\n"
}
function drupal:install {
drush site:install -y --account-pass=admin123 "${@}"
}
function lint:dockerfile {
docker container run --rm -i \
hadolint/hadolint hadolint --ignore DL3008 --ignore DL3059 -t style "${@}" - < Dockerfile
}
function quality {
coding-standards
static-analysis
}
function start {
cp -v --no-clobber .env.example .env
docker compose up -d
}
function static-analysis {
cmd phpstan --memory-limit=-1 --no-progress "${@}"
}
function stop {
docker compose down
}
function test {
_exec php phpunit --colors=always "${@}"
}
function test:commit {
test --testdox --testsuite functional
test --testdox --testsuite kernel
test --testdox --testsuite unit
quality
}
function _exec {
docker compose exec -T "${@}"
}
function _run {
local service="${1}"
local command="${2}"
docker compose run \
--entrypoint "${command}" \
--no-deps \
--rm \
-T \
"${service}" "${@}"
}
TIMEFORMAT=$'\nTask completed in %3lR'
time "${@:-help}"
# vim: ft=bash

View file

@ -0,0 +1,7 @@
#!/usr/bin/env bash
# Do not edit this file. It is automatically generated by https://www.oliverdavies.uk/build-configs.
[[ -f composer.json && ! -d vendor ]] && composer install
eval "$@"

View file

@ -0,0 +1,6 @@
xdebug.mode=develop,debug
xdebug.client_host=host.docker.internal
xdebug.discover_client_host=0
xdebug.output_dir=/tmp/xdebug
xdebug.log=/tmp/xdebug/xdebug-docker-drupal-example.log
xdebug.start_with_request=yes

View file

@ -0,0 +1,4 @@
# Do not edit this file. It is automatically generated by https://www.oliverdavies.uk/build-configs.
max_vars_input = 1000
memory_limit = 128M

View file

@ -0,0 +1,22 @@
# Do not edit this file. It is automatically generated by https://www.oliverdavies.uk/build-configs.
server {
server_name _;
root /app/web;
location / {
try_files $uri /index.php?$query_string;
}
location ~ \.php(/|$) {
fastcgi_split_path_info ^(.+?\.php)(|/.*)$;
try_files $fastcgi_script_name =404;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param QUERY_STRING $query_string;
fastcgi_intercept_errors on;
fastcgi_pass php:9000;
}
}