feat: initial commit

This commit is contained in:
Oliver Davies 2023-08-08 12:00:00 +01:00
commit 26d450c1a4
31 changed files with 10925 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=drupal-testing-lightning-talk
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

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

@ -0,0 +1,45 @@
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: Install just
run: |
curl --proto '=https' \
--tlsv1.2 -sSf https://just.systems/install.sh | bash -s -- --to /usr/local/bin
- name: Checkout the code
uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f # v2.3.4
- name: Build and test
run: |
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
just composer install --quiet --no-progress
just _run php phpcs
just _run php phpstan analyze --no-progress --memory-limit=512M
just test --testdox --colors=always

34
.gitignore vendored Normal file
View file

@ -0,0 +1,34 @@
/.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

2
.hadolint.yaml Normal file
View file

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

62
Dockerfile Normal file
View file

@ -0,0 +1,62 @@
# 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
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 /

1
README.md Normal file
View file

@ -0,0 +1 @@
# drupal-testing-lightning-talk

44
build.yaml Normal file
View file

@ -0,0 +1,44 @@
name: drupal-testing-lightning-talk
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"
}
}

10222
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"

76
docker-compose.yaml Normal file
View file

@ -0,0 +1,76 @@
# 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]
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

72
justfile Normal file
View file

@ -0,0 +1,72 @@
# Do not edit this file. It is automatically generated by https://www.oliverdavies.uk/build-configs.
default:
@just --list
# Start the project
start:
cp -v --no-clobber .env.example .env
docker compose up -d
# Stop the project
stop:
docker compose down
composer *args:
just _exec php composer {{ args }}
alias phpunit := test
test *args:
just _exec php phpunit --colors=always {{ args }}
test-watch *args:
nodemon --ext "*" --watch "." --exec "just test || exit 1" --ignore */sites/simpletest
drush *args:
just _exec php drush {{ args }}
install *args:
just _exec php drush site:install -y {{ args }}
# Enable or disable Git hooks
git-hooks command:
#!/usr/bin/env bash
set -euo pipefail
case "{{ command }}" in
"on")
echo "Enabling Git hooks..."
git config core.hooksPath .githooks
;;
"off")
echo "Disabling Git hooks..."
git config --unset core.hooksPath
;;
*)
echo "Error: Invalid argument. Must be either 'on' or 'off'"
;;
esac
test-commit:
just _run php phpcs
just _run php phpstan analyze --no-progress --memory-limit=512M
just test --testdox --testsuite unit
just test --testdox --testsuite kernel
_exec +args:
docker compose exec -T {{ args }}
_run service command *args:
docker compose run \
--entrypoint {{ command }} \
--no-deps \
--rm \
-T \
{{ service }} {{ args }}
# vim: ft=just

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="drupal-testing-lightning-talk coding standards">
<description>PHPCS configuration file for drupal-testing-lightning-talk.</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>

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;
}
}

2
web/modules/custom/example/.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
/composer.lock
/vendor/

View file

@ -0,0 +1,5 @@
{
"require": {
"symfony/config": "^6.1"
}
}

View file

@ -0,0 +1,5 @@
name: Example module
description: TODO
type: module
core_version_requirement: ^9||^10
package: Example

View file

@ -0,0 +1,7 @@
drupal-module-template.example:
path: /@opdavies/drupal-module-template
defaults:
_controller: Drupal\example\Controller\ExamplePageController
_title: Example page
requirements:
_permission: access content

View file

@ -0,0 +1,7 @@
services:
Drupal\Core\Logger\LoggerChannelFactoryInterface:
alias: logger.factory
private: true
Drupal\example\Controller\ExamplePageController:
autowire: true

View file

@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<ruleset name="phpcs-standard">
<description>Codestyle ruleset for Drupal</description>
<rule ref="Drupal"/>
<rule ref="DrupalPractice"/>
<arg name="ignore" value="*.css,*.md,*.txt"/>
<arg name="colors"/>
<arg value="np"/>
<file>./src</file>
<rule ref="Drupal">
<exclude name="Drupal.Commenting.ClassComment.Missing"/>
<exclude name="Drupal.NamingConventions.ValidFunctionName.ScopeNotCamelCaps"/>
<exclude name="Drupal.Commenting.DataTypeNamespace.DataTypeNamespace"/>
<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.InlineComment.DocBlock"/>
<exclude name="Drupal.Commenting.VariableComment.Missing"/>
<exclude name="DrupalPractice.Objects.StrictSchemaDisabled.StrictConfigSchema"/>
</rule>
</ruleset>

View file

@ -0,0 +1,32 @@
<?php
declare(strict_types=1);
namespace Drupal\example\Controller;
use Drupal\Core\Logger\LoggerChannelFactoryInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
final class ExamplePageController {
use StringTranslationTrait;
public function __construct(
private LoggerChannelFactoryInterface $logger
) {}
/**
* @return array<string,mixed>
*/
public function __invoke(): array {
$this->logger->get('example')->info('Example page viewed.');
return [
'#markup' => $this->t(
'This is an example page from the <a href="@url">Drupal Module Template</a>.',
['@url' => 'https://github.com/opdavies/drupal-module-template']
),
];
}
}

View file

@ -0,0 +1,31 @@
<?php
namespace Drupal\Tests\example\Functional;
use Drupal\Tests\BrowserTestBase;
use Symfony\Component\HttpFoundation\Response;
final class ExamplePageTest extends BrowserTestBase {
public $defaultTheme = 'stark';
protected static $modules = [
// Core.
'node',
// Custom.
"example"
];
/** @test */
public function should_load_the_example_page_for_anonymous_users(): void {
// Arrange.
// Act.
$this->drupalGet('/@opdavies/drupal-module-template');
// Assert.
$this->assertSession()->statusCodeEquals(Response::HTTP_OK);
}
}