Update Docker configuration

This commit is contained in:
Oliver Davies 2023-01-21 15:50:45 +00:00
parent dba2b1004c
commit 9f398ee012
12 changed files with 224 additions and 50 deletions

4
.env.example Normal file
View file

@ -0,0 +1,4 @@
export COMPOSE_PROJECT_NAME=docker-example-drupal
export COMPOSE_PROFILES=web,php,database
export DOCKER_WEB_VOLUME=.:/app

3
.gitignore vendored
View file

@ -1,4 +1,5 @@
/.editorconfig
/.env
/.gitattributes
/vendor/
/web/.csslintrc
@ -13,6 +14,7 @@
/web/example.gitignore
/web/index.php
/web/modules/README.txt
/web/modules/contrib/
/web/profiles/README.txt
/web/robots.txt
/web/sites/*/files/
@ -27,5 +29,6 @@
/web/sites/example.sites.php
/web/sites/simpletest/
/web/themes/README.txt
/web/themes/contrib/
/web/update.php
/web/web.config

View file

@ -1,52 +1,50 @@
ARG PHP_VERSION=8.1
FROM php:8.1-fpm-bullseye AS base
FROM php:${PHP_VERSION}-fpm-bullseye AS base
COPY --from=composer:2 /usr/bin/composer /usr/bin/composer
RUN which composer && composer -V
###
WORKDIR /app
ENV PATH="${PATH}:/app/vendor/bin"
COPY composer.* ./
################################################################################
FROM base AS build
ENV PATH=${PATH}:/var/www/html/vendor/bin
RUN apt-get update -yqq \
&& apt-get install -yqq --no-install-recommends \
git libpng-dev libzip-dev mariadb-client unzip
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
RUN docker-php-ext-install gd pdo_mysql zip
WORKDIR /var/www/html
RUN useradd --create-home app \
&& chown app:app -R /var/www/html \
&& apt-get update -yqq \
&& apt-get install -yqq \
git \
libpng-dev \
mariadb-client \
unzip \
&& rm -fr /var/lib/apt/lists/* \
&& pecl install xdebug \
&& docker-php-ext-install \
gd \
opcache \
pdo_mysql \
&& docker-php-ext-enable \
xdebug
RUN composer validate
RUN composer install
COPY tools/docker/images/php/root /
COPY --chown=app:app composer.* ./
ENTRYPOINT ["/usr/local/bin/docker-entrypoint-php"]
CMD ["php-fpm"]
USER app
RUN composer install --no-dev --prefer-dist --optimize-autoloader
################################################################################
COPY --chown=app:app . .
FROM base AS test
###
COPY . .
FROM build AS test
RUN parallel-lint src --no-progress \
&& phpcs -vv \
&& phpstan \
&& phpunit --testdox
# RUN composer install \
# && phpunit
################################################################################
###
FROM nginx:1 as web
FROM build AS production
EXPOSE 8080
RUN composer install --no-dev --prefer-dist --optimize-autoloader
WORKDIR /app
COPY tools/docker/images/web/root /

52
build.yaml Normal file
View file

@ -0,0 +1,52 @@
name: docker-example-drupal
language: php
type: drupal-project
web:
type: nginx
database:
type: mariadb
version: 10
php:
version: 8.1-fpm-bullseye
phpcs:
standard: Drupal,DrupalPractice
phpstan:
level: max
docker-compose:
services:
database: ~
php:
build:
target: build
dockerfile:
stages:
build:
extends: base
packages:
- git
- libpng-dev
- libzip-dev
- mariadb-client
- unzip
extensions:
install:
- gd
- pdo_mysql
- zip
commands:
- composer validate
- composer install
test:
extends: base
commands:
- parallel-lint src --no-progress
- phpcs -vv
- phpstan
- phpunit --testdox

View file

@ -1,30 +1,70 @@
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:
image: caddy
volumes:
- ./Caddyfile:/etc/caddy/Caddyfile
- .:/var/www/html
ports:
- "${DOCKER_WEB_PORT:-127.0.0.1:80}:80"
environment:
SERVER_NAME: "${SERVER_NAME:-:80}"
php-fpm:
image: "ghcr.io/opdavies/docker-drupal-example-php-fpm:${DOCKER_TAG:-latest}"
<<: *default-app
build:
context: .
volumes:
- .:/var/www/html
target: web
depends_on:
- php
networks:
- default
- web
labels:
- "traefik.docker.network=traefik_proxy"
- "traefik.http.routers.${COMPOSE_PROJECT_NAME}.rule=Host(
`${COMPOSE_PROJECT_NAME}.localhost`,
)"
profiles: [web]
mysql:
php:
<<: *default-app
build:
context: .
target: build
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
MYSQL_DATABASE: drupal
MYSQL_RANDOM_ROOT_PASSWORD: 'true'
MYSQL_PASSWORD: drupal
MYSQL_USER: drupal
profiles: [database]
volumes:
db-data: {}
networks:
web:
name: traefik_proxy

7
phpcs.xml.dist Normal file
View file

@ -0,0 +1,7 @@
<?xml version="1.0"?>
<ruleset name="docker-example-drupal coding standards">
<description>PHPCS configuration file for docker-example-drupal.</description>
<file>src</file>
<arg value="np"/>
<rule ref="Drupal,DrupalPractice"/>
</ruleset>

5
phpstan.neon.dist Normal file
View file

@ -0,0 +1,5 @@
parameters:
level: max
paths:
- src

20
phpunit.xml.dist Normal file
View file

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd"
bootstrap="vendor/autoload.php"
cacheResultFile=".phpunit.cache/test-results"
executionOrder="depends,defects"
forceCoversAnnotation="false"
beStrictAboutCoversAnnotation="true"
beStrictAboutOutputDuringTests="false"
beStrictAboutTodoAnnotatedTests="true"
convertDeprecationsToExceptions="true"
failOnRisky="true"
failOnWarning="true"
verbose="true">
<testsuites>
<testsuite name="docker-example-drupal">
<directory>tests</directory>
</testsuite>
</testsuites>
</phpunit>

4
run
View file

@ -3,7 +3,7 @@
set -e
function cmd {
_dc php-fpm "${@}"
_dc php "${@}"
}
function composer {
@ -23,7 +23,7 @@ function help {
}
function _dc {
docker-compose run --rm "${@}"
docker compose run --rm "${@}"
}
eval "${@:-help}"

View file

@ -0,0 +1,20 @@
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;
}
}

View file

@ -0,0 +1,5 @@
#!/usr/bin/env bash
[[ -f composer.json && ! -d vendor ]] && composer install
eval "$@"

View file

@ -0,0 +1,20 @@
server {
server_name _;
root /app/docroot;
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;
}
}