Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Added frankenphp #25

Merged
merged 11 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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]"
eliot488995568 marked this conversation as resolved.
Show resolved Hide resolved

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
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,13 @@ 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 for use it you need to override services `app`, `nginx` and `varnish` in `compose.override.yml`

You need to use the target `php-dev-franken` present in the `Dockerfile`.
We use `dunglas/frankenphp` image with the tag of your version of php and the tag bookworm

If you use frankenphp you can remove `docker/varnish` and `docker/nginx` folders
eliot488995568 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
vars {
baseUrl: https://localhost:4431
}
vars:secret [
access_token,
username,
password
]
49 changes: 46 additions & 3 deletions compose.override.yml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,53 @@ 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
# # HTTPS
# - target: 443
# published: ${PUBLIC_APP_HTTPS_PORT:-443}
# protocol: tcp
# tty: true
# volumes:
# - ./:/app:cached
eliot488995568 marked this conversation as resolved.
Show resolved Hide resolved
# - ./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}

# 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 @@ -148,6 +148,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/css-selector": "6.4.*",
"symfony/debug-bundle": "6.4.*",
Expand Down
23 changes: 23 additions & 0 deletions docker/frankenphp/Caddyfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
{$CADDY_GLOBAL_OPTIONS}

frankenphp {
{$FRANKENPHP_CONFIG}
}
}

{$SERVER_NAME:localhost} {
eliot488995568 marked this conversation as resolved.
Show resolved Hide resolved
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
}
5 changes: 5 additions & 0 deletions docker/frankenphp/conf.d/app.dev.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
; 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
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 = UTC
eliot488995568 marked this conversation as resolved.
Show resolved Hide resolved
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
}
Loading