From 31cc3a141c9d0411bb7ea317d6d3a0474bb2e507 Mon Sep 17 00:00:00 2001 From: Eliot <72140926+eliot488995568@users.noreply.github.com> Date: Wed, 4 Dec 2024 16:25:03 +0100 Subject: [PATCH] feat: Added frankenphp (#25) First implementation of frankenphp to remove in future varnish and nginx, --- .env | 3 +- Dockerfile | 92 +++++++++++++++++++++++-- README.md | 11 +++ compose.override.yml.dist | 46 ++++++++++++- composer.json | 1 + docker/frankenphp/Caddyfile | 27 ++++++++ docker/frankenphp/conf.d/app.dev.ini | 34 +++++++++ docker/frankenphp/conf.d/app.ini | 13 ++++ docker/frankenphp/docker-entrypoint.dev | 4 ++ docker/frankenphp/worker.Caddyfile | 4 ++ 10 files changed, 227 insertions(+), 8 deletions(-) create mode 100644 docker/frankenphp/Caddyfile create mode 100644 docker/frankenphp/conf.d/app.dev.ini create mode 100644 docker/frankenphp/conf.d/app.ini create mode 100644 docker/frankenphp/docker-entrypoint.dev create mode 100644 docker/frankenphp/worker.Caddyfile diff --git a/.env b/.env index 71b55c7d..58ef6d26 100644 --- a/.env +++ b/.env @@ -30,6 +30,7 @@ SOLR_CORE_NAME=roadiz PUBLIC_APP_PORT=8681 PUBLIC_VARNISH_PORT=8682 +PUBLIC_APP_HTTPS_PORT=4431 PUBLIC_PMA_PORT=8686 PUBLIC_SOLR_PORT=8684 PUBLIC_MAILER_PORT=8625 @@ -86,7 +87,7 @@ REDIS_DSN=redis://redis # # DATABASE_URL="sqlite:///%kernel.project_dir%/var/data.db" # DATABASE_URL="mysql://db_user:db_password@127.0.0.1:3306/db_name?serverVersion=5.7&charset=utf8mb4" -DATABASE_URL="mysql://db_user:db_password@db/db_name?serverVersion=8.0.38&charset=utf8mb4" +DATABASE_URL="mysql://db_user:db_password@db/db_name?serverVersion=8.0.40&charset=utf8mb4" #DATABASE_URL="postgresql://db_user:db_password@127.0.0.1:5432/db_name?serverVersion=13&charset=utf8" ###< doctrine/doctrine-bundle ### diff --git a/Dockerfile b/Dockerfile index efcf7705..233445ac 100644 --- a/Dockerfile +++ b/Dockerfile @@ -71,7 +71,6 @@ usermod -u ${UID} mysql groupmod -g ${GID} mysql EOF - ########### # Varnish # ########### @@ -82,7 +81,6 @@ LABEL org.opencontainers.image.authors="ambroise@rezo-zero.com" COPY --link docker/varnish/default.vcl /etc/varnish/ - ####### # PHP # ####### @@ -145,6 +143,94 @@ EOF WORKDIR /app +#################### +# PHP - FRANKENPHP # +#################### + +FROM dunglas/frankenphp:php${PHP_VERSION}-bookworm AS php-franken + +LABEL org.opencontainers.image.authors="ambroise@rezo-zero.com, eliot@rezo-zero.com" + +ARG UID +ARG GID + +ARG COMPOSER_VERSION=2.8.1 +ARG PHP_EXTENSION_INSTALLER_VERSION=2.6.0 +ARG PHP_EXTENSION_REDIS_VERSION=6.1.0 + +SHELL ["/bin/bash", "-e", "-o", "pipefail", "-c"] + +ENV APP_FFMPEG_PATH=/usr/bin/ffmpeg +ENV APP_RUNTIME=Runtime\\FrankenPhpSymfony\\Runtime +ENV FRANKENPHP_CONFIG="worker ./public/index.php" + +RUN < /etc/sudoers.d/php + +# App +install --verbose --owner php --group php --mode 0755 --directory /app + +# Php extensions +install-php-extensions \ + @composer-${COMPOSER_VERSION} \ + fileinfo \ + gd \ + imagick \ + iconv \ + intl \ + json \ + mbstring \ + opcache \ + openssl \ + pcntl \ + pdo_mysql \ + simplexml \ + xsl \ + zip \ + redis-${PHP_EXTENSION_REDIS_VERSION} + +setcap CAP_NET_BIND_SERVICE=+eip /usr/local/bin/frankenphp + +chown --recursive ${UID}:${GID} /data/caddy /config/caddy + +EOF + +COPY --link docker/frankenphp/conf.d/app.ini ${PHP_INI_DIR}/conf.d/ +COPY --link --chmod=755 docker/frankenphp/docker-entrypoint.dev /usr/local/bin/docker-entrypoint +COPY --link docker/frankenphp/Caddyfile /etc/caddy/Caddyfile + +ENTRYPOINT ["docker-entrypoint"] + +WORKDIR /app + +####################### +# Php - franken - Dev # +####################### + +FROM php-franken AS php-dev-franken + +ENV XDEBUG_MODE=off + +RUN mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini" + +COPY --link docker/frankenphp/conf.d/app.dev.ini ${PHP_INI_DIR}/conf.d/ + +CMD [ "frankenphp", "run", "--config", "/etc/caddy/Caddyfile", "--watch" ] + +USER php ############# # Php - Dev # @@ -164,7 +250,6 @@ CMD ["php-fpm"] USER php - ############## # Cron - Dev # ############## @@ -190,7 +275,6 @@ ENTRYPOINT ["docker-entrypoint"] USER root - ######### # Nginx # ######### diff --git a/README.md b/README.md index ada7efab..9d1a3be1 100644 --- a/README.md +++ b/README.md @@ -63,3 +63,14 @@ Roadiz development env uses: https://github.com/symplify/monorepo-builder - `vendor/bin/monorepo-builder merge`: Makes sure all your packages deps are in development repository and - `vendor/bin/monorepo-builder validate`: Make sure all your packages use the same version - `vendor/bin/monorepo-builder release patch --dry-run`: List all steps to do when release a new tag (do not actually perform this when using GitFlow) + + +### Use Frankenphp + +Roadiz can be run with [*frankenphp*](https://frankenphp.dev) instead of PHP-FPM + Nginx. If you want to give it a try, override services `app`, `nginx` and `varnish` in your `compose.override.yml` + +Use the target `php-dev-franken` instead of `php-dev`. + +We use [`dunglas/frankenphp`](https://hub.docker.com/r/dunglas/frankenphp) image with the tag of your PHP version and Debian Bookworm. + +Using frankenphp allows you to remove `docker/varnish` and `docker/nginx` folders in your project. diff --git a/compose.override.yml.dist b/compose.override.yml.dist index ad95d381..e39540bc 100644 --- a/compose.override.yml.dist +++ b/compose.override.yml.dist @@ -8,10 +8,50 @@ services: solr: ports: - "${PUBLIC_SOLR_PORT}:8983/tcp" - nginx: - ports: - - ${PUBLIC_APP_PORT}:80/tcp + + # Override app service if you use frankenphp +# app: +# build: +# target: php-dev-franken +# args: +# UID: ${UID:-1000} +# ports: +# - ${PUBLIC_APP_PORT}:80/tcp +# tty: true +# volumes: +# - ./:/app +# - ./docker/frankenphp/Caddyfile:/etc/caddy/Caddyfile:ro +# - ./docker/frankenphp/conf.d/app.dev.ini:/usr/local/etc/php/conf.d/app.dev.ini:ro +# - caddy_data:/data +# - caddy_config:/config +# environment: +# PHP_CS_FIXER_IGNORE_ENV: 1 +# TRUSTED_PROXIES: ${TRUSTED_PROXIES} +# UID: ${UID} +# DEFAULT_GATEWAY: ${DEFAULT_GATEWAY} +# DATABASE_URL: ${DATABASE_URL} +# SERVER_NAME: :80 + + # Uncomment next line if you use Frankenphp +# varnish: +# entrypoint: ["echo", "Service varnish disabled"] + +# nginx: + # Uncomment ports if you use nginx +# ports: +# - ${PUBLIC_APP_PORT}:80/tcp + # Comment ports and uncomment next line if you use Frankenphp +# entrypoint: ["echo", "Service nginx disabled"] + + mailer: ports: - ${PUBLIC_MAILER_PORT}:8025/tcp - ${SMTP_MAILER_PORT}:1025/tcp + +volumes: + redis: + solr_data: + # Declare caddy_data and caddy_config volumes if you use Frankenphp +# caddy_data: +# caddy_config: diff --git a/composer.json b/composer.json index fb7d5176..60094da2 100644 --- a/composer.json +++ b/composer.json @@ -147,6 +147,7 @@ "phpstan/phpstan-symfony": "^1.1.8", "phpunit/phpunit": "^9.5", "rector/rector": "^0.14.5", + "runtime/frankenphp-symfony": "^0.2.0", "symfony/browser-kit": "6.4.*", "symfony/debug-bundle": "6.4.*", "symfony/http-client-contracts": "^3.5", diff --git a/docker/frankenphp/Caddyfile b/docker/frankenphp/Caddyfile new file mode 100644 index 00000000..5789364c --- /dev/null +++ b/docker/frankenphp/Caddyfile @@ -0,0 +1,27 @@ +{ + {$CADDY_GLOBAL_OPTIONS} + + servers { + trusted_proxies static 0.0.0.0/0 + } + + frankenphp { + {$FRANKENPHP_CONFIG} + } +} + +{$SERVER_NAME:localhost} { + log { + # Redact the authorization query parameter that can be set by Mercure + format filter { + request>uri query { + replace authorization REDACTED + } + } + } + + root * /app/public + encode zstd br gzip + + php_server +} diff --git a/docker/frankenphp/conf.d/app.dev.ini b/docker/frankenphp/conf.d/app.dev.ini new file mode 100644 index 00000000..d13f7cad --- /dev/null +++ b/docker/frankenphp/conf.d/app.dev.ini @@ -0,0 +1,34 @@ +; See https://docs.docker.com/desktop/networking/#i-want-to-connect-from-a-container-to-a-service-on-the-host +; See https://github.com/docker/for-linux/issues/264 +; The `client_host` below may optionally be replaced with `discover_client_host=yes` +; Add `start_with_request=yes` to start debug session on each request +xdebug.client_host = xdebug://gateway + +date.timezone = Europe/Paris +session.auto_start = Off +; Session ID cannot be passed through URLs +session.use_only_cookies = On +; Uses a secure connection (HTTPS) if possible +; session.cookie_secure = On +; Do not accept uninitialized session ID +session.use_strict_mode = On +; Do not make session cookie available to JS +session.cookie_httponly = On +short_open_tag = Off + +; http://symfony.com/doc/current/performance.html +; Configure OPcache for Maximum Performance +opcache.revalidate_freq = 0 +opcache.memory_consumption = 256 +opcache.max_accelerated_files = 20000 +opcache.interned_strings_buffer = 16 + +; Configure the PHP realpath Cache +realpath_cache_size = 4096K +realpath_cache_ttl = 600 + +memory_limit = 512M +post_max_size = 128M +upload_max_filesize = 64M +expose_php = On +display_errors = On diff --git a/docker/frankenphp/conf.d/app.ini b/docker/frankenphp/conf.d/app.ini new file mode 100644 index 00000000..ab11e97c --- /dev/null +++ b/docker/frankenphp/conf.d/app.ini @@ -0,0 +1,13 @@ +expose_php = 0 +date.timezone = Europe/Paris +apc.enable_cli = 1 +session.use_strict_mode = 1 +zend.detect_unicode = 0 + +; https://symfony.com/doc/current/performance.html +realpath_cache_size = 4096K +realpath_cache_ttl = 600 +opcache.interned_strings_buffer = 16 +opcache.max_accelerated_files = 20000 +opcache.memory_consumption = 256 +opcache.enable_file_override = 1 diff --git a/docker/frankenphp/docker-entrypoint.dev b/docker/frankenphp/docker-entrypoint.dev new file mode 100644 index 00000000..692e4e59 --- /dev/null +++ b/docker/frankenphp/docker-entrypoint.dev @@ -0,0 +1,4 @@ +#!/bin/sh +set -e + +exec docker-php-entrypoint "$@" diff --git a/docker/frankenphp/worker.Caddyfile b/docker/frankenphp/worker.Caddyfile new file mode 100644 index 00000000..d384ae4c --- /dev/null +++ b/docker/frankenphp/worker.Caddyfile @@ -0,0 +1,4 @@ +worker { + file ./public/index.php + env APP_RUNTIME Runtime\FrankenPhpSymfony\Runtime +}