Skip to content

Commit

Permalink
feat: Added frankenphp (#25)
Browse files Browse the repository at this point in the history
First implementation of frankenphp to remove in future varnish and
nginx,
  • Loading branch information
eliot488995568 authored Dec 4, 2024
1 parent 41085f9 commit 31cc3a1
Show file tree
Hide file tree
Showing 10 changed files with 227 additions and 8 deletions.
3 changes: 2 additions & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -86,7 +87,7 @@ REDIS_DSN=redis://redis
#
# DATABASE_URL="sqlite:///%kernel.project_dir%/var/data.db"
# DATABASE_URL="mysql://db_user:[email protected]: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:[email protected]:5432/db_name?serverVersion=13&charset=utf8"
###< doctrine/doctrine-bundle ###

Expand Down
92 changes: 88 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ usermod -u ${UID} mysql
groupmod -g ${GID} mysql
EOF


###########
# Varnish #
###########
Expand All @@ -82,7 +81,6 @@ LABEL org.opencontainers.image.authors="[email protected]"

COPY --link docker/varnish/default.vcl /etc/varnish/


#######
# PHP #
#######
Expand Down Expand Up @@ -145,6 +143,94 @@ EOF

WORKDIR /app

####################
# PHP - FRANKENPHP #
####################

FROM dunglas/frankenphp:php${PHP_VERSION}-bookworm AS php-franken

LABEL org.opencontainers.image.authors="[email protected], [email protected]"

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 <<EOF
apt-get --quiet update
apt-get --quiet --yes --purge --autoremove upgrade
# Packages - System
apt-get --quiet --yes --no-install-recommends --verbose-versions install \
acl \
less \
sudo \
ffmpeg
rm -rf /var/lib/apt/lists/*

# User
addgroup --gid ${UID} php
adduser --home /home/php --shell /bin/bash --uid ${GID} --gecos php --ingroup php --disabled-password php
echo "php ALL=(ALL) NOPASSWD:ALL" > /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 #
Expand All @@ -164,7 +250,6 @@ CMD ["php-fpm"]

USER php


##############
# Cron - Dev #
##############
Expand All @@ -190,7 +275,6 @@ ENTRYPOINT ["docker-entrypoint"]

USER root


#########
# Nginx #
#########
Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
46 changes: 43 additions & 3 deletions compose.override.yml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -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:
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
27 changes: 27 additions & 0 deletions docker/frankenphp/Caddyfile
Original file line number Diff line number Diff line change
@@ -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
}
34 changes: 34 additions & 0 deletions docker/frankenphp/conf.d/app.dev.ini
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions docker/frankenphp/conf.d/app.ini
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions docker/frankenphp/docker-entrypoint.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
set -e

exec docker-php-entrypoint "$@"
4 changes: 4 additions & 0 deletions docker/frankenphp/worker.Caddyfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
worker {
file ./public/index.php
env APP_RUNTIME Runtime\FrankenPhpSymfony\Runtime
}

0 comments on commit 31cc3a1

Please sign in to comment.