Skip to content

Commit 9ac8776

Browse files
committed
Switch to FrankenPHP
1 parent 7d34d6c commit 9ac8776

File tree

15 files changed

+69
-190
lines changed

15 files changed

+69
-190
lines changed

.env

+1
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@
1717
###> symfony/framework-bundle ###
1818
APP_ENV=dev
1919
APP_SECRET=
20+
TRUSTED_PROXIES=127.0.0.1,172.17.0.0/16,172.18.0.0/15,172.20.0.0/14,172.24.0.0/13,192.168.0.0/16,10.0.0.0/8
2021
###< symfony/framework-bundle ###

config/packages/framework.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ framework:
88
#esi: true
99
#fragments: true
1010

11+
trusted_proxies: '%env(TRUSTED_PROXIES)%'
1112
when@test:
1213
framework:
1314
test: true

infrastructure/docker/docker-compose.yml

+6-5
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ services:
2323
build:
2424
context: services/php
2525
target: frontend
26+
environment:
27+
- SERVER_NAME=${PROJECT_ROOT_DOMAIN}
28+
- UID=${USER_ID}
2629
depends_on:
2730
postgres:
2831
condition: service_healthy
@@ -31,13 +34,11 @@ services:
3134
profiles:
3235
- default
3336
labels:
34-
- "traefik.enable=true"
3537
- "project-name=${PROJECT_NAME}"
36-
- "traefik.http.routers.${PROJECT_NAME}-frontend.rule=Host(${PROJECT_DOMAINS})"
38+
- "traefik.enable=true"
39+
- "traefik.http.routers.${PROJECT_NAME}-frontend.rule=Host(`${PROJECT_ROOT_DOMAIN}`)"
3740
- "traefik.http.routers.${PROJECT_NAME}-frontend.tls=true"
38-
- "traefik.http.routers.${PROJECT_NAME}-frontend-unsecure.rule=Host(${PROJECT_DOMAINS})"
39-
# Comment the next line to be able to access frontend via HTTP instead of HTTPS
40-
- "traefik.http.routers.${PROJECT_NAME}-frontend-unsecure.middlewares=redirect-to-https@file"
41+
- "traefik.http.services.${PROJECT_NAME}-frontend.loadbalancer.server.port=80"
4142

4243
postgres:
4344
image: postgres:16

infrastructure/docker/services/php/Dockerfile

+36-75
Original file line numberDiff line numberDiff line change
@@ -1,123 +1,77 @@
11
# hadolint global ignore=DL3008
22

3-
FROM debian:12.8-slim AS php-base
3+
FROM dunglas/frankenphp:1.4.4-php8.4-bookworm as php-base
44

5-
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
5+
RUN install-php-extensions \
6+
intl \
7+
opcache \
8+
pdo_pgsql \
9+
uuid
610

7-
RUN apt-get update \
8-
&& apt-get install -y --no-install-recommends \
9-
curl \
10-
ca-certificates \
11-
gnupg \
12-
&& curl -sSLo /tmp/debsuryorg-archive-keyring.deb https://packages.sury.org/debsuryorg-archive-keyring.deb \
13-
&& dpkg -i /tmp/debsuryorg-archive-keyring.deb \
14-
&& echo "deb [signed-by=/usr/share/keyrings/deb.sury.org-php.gpg] https://packages.sury.org/php bookworm main" > /etc/apt/sources.list.d/sury.list \
15-
&& apt-get clean \
16-
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/*
17-
18-
RUN apt-get update \
19-
&& apt-get install -y --no-install-recommends \
20-
bash-completion \
21-
procps \
22-
&& apt-get clean \
23-
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/*
24-
25-
ARG PHP_VERSION
26-
27-
RUN apt-get update \
28-
&& apt-get install -y --no-install-recommends \
29-
"php${PHP_VERSION}-apcu" \
30-
"php${PHP_VERSION}-bcmath" \
31-
"php${PHP_VERSION}-cli" \
32-
"php${PHP_VERSION}-common" \
33-
"php${PHP_VERSION}-curl" \
34-
"php${PHP_VERSION}-iconv" \
35-
"php${PHP_VERSION}-intl" \
36-
"php${PHP_VERSION}-mbstring" \
37-
"php${PHP_VERSION}-pgsql" \
38-
"php${PHP_VERSION}-uuid" \
39-
"php${PHP_VERSION}-xml" \
40-
"php${PHP_VERSION}-zip" \
41-
&& apt-get clean \
42-
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/*
11+
COPY ./base/php.ini $PHP_INI_DIR/conf.d/app-base.ini
4312

4413
# Fake user to maps with the one on the host
4514
ARG USER_ID
46-
COPY entrypoint /
4715
RUN addgroup --gid $USER_ID app && \
4816
adduser --system --uid $USER_ID --home /home/app --shell /bin/bash app && \
4917
curl -Ls https://github.com/tianon/gosu/releases/download/1.17/gosu-amd64 | \
50-
install /dev/stdin /usr/local/bin/gosu && \
51-
sed "s/{{ application_user }}/app/g" -i /entrypoint
52-
53-
# Configuration
54-
COPY base/php-configuration /etc/php/${PHP_VERSION}
55-
56-
ENV PHP_VERSION=${PHP_VERSION}
18+
install /dev/stdin /usr/local/bin/gosu
5719

58-
WORKDIR /var/www
20+
COPY entrypoint /
5921

60-
ENTRYPOINT [ "/entrypoint" ]
22+
ENTRYPOINT ["/entrypoint"]
6123

6224
FROM php-base AS frontend
6325

64-
RUN apt-get update \
65-
&& apt-get install -y --no-install-recommends \
66-
nginx \
67-
"php${PHP_VERSION}-fpm" \
68-
runit \
69-
&& apt-get clean \
70-
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/* \
71-
&& rm -r "/etc/php/${PHP_VERSION}/fpm/pool.d/"
26+
RUN setcap CAP_NET_BIND_SERVICE=+eip /usr/local/bin/frankenphp && \
27+
chown -R ${USER_ID}:${USER_ID} /data/caddy && \
28+
chown -R ${USER_ID}:${USER_ID} /config/caddy
7229

73-
RUN useradd -s /bin/false nginx
30+
COPY ./frontend/etc/. /etc/
31+
COPY ./frontend/php.ini $PHP_INI_DIR/conf.d/app-frontend.ini
7432

75-
COPY frontend/php-configuration /etc/php/${PHP_VERSION}
76-
COPY frontend/etc/nginx/. /etc/nginx/
77-
COPY frontend/etc/service/. /etc/service/
33+
WORKDIR /var/www
7834

79-
RUN phpenmod app-default \
80-
&& phpenmod app-fpm
35+
CMD [ "frankenphp", "run", "--config", "/etc/caddy/Caddyfile", "--adapter", "caddyfile"]
8136

8237
EXPOSE 80
8338

84-
CMD ["runsvdir", "-P", "/etc/service"]
85-
8639
FROM php-base AS worker
8740

8841
FROM php-base AS builder
8942

9043
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
9144

45+
# Default toys
46+
RUN apt-get update \
47+
&& apt-get install -y --no-install-recommends \
48+
ca-certificates \
49+
gnupg \
50+
&& apt-get clean \
51+
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/*
52+
9253
ARG NODEJS_VERSION=20.x
9354
RUN curl -s https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /usr/share/keyrings/nodesource.gpg \
9455
&& echo "deb [signed-by=/usr/share/keyrings/nodesource.gpg] https://deb.nodesource.com/node_${NODEJS_VERSION} nodistro main" > /etc/apt/sources.list.d/nodesource.list
9556

9657
# Default toys
9758
RUN apt-get update \
9859
&& apt-get install -y --no-install-recommends \
60+
bash-completion \
61+
ca-certificates \
62+
curl \
9963
git \
10064
make \
10165
nodejs \
66+
procps \
10267
sudo \
10368
unzip \
10469
&& apt-get clean \
10570
&& npm install -g [email protected] \
10671
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/*
10772

108-
# Config
109-
COPY builder/etc/. /etc/
110-
COPY builder/php-configuration /etc/php/${PHP_VERSION}
111-
RUN adduser app sudo \
112-
&& mkdir /var/log/php \
113-
&& chmod 777 /var/log/php \
114-
&& phpenmod app-default \
115-
&& phpenmod app-builder
116-
11773
# Composer
11874
COPY --from=composer/composer:2.8.4 /usr/bin/composer /usr/bin/composer
119-
RUN mkdir -p "/home/app/.composer/cache" \
120-
&& chown app: /home/app/.composer -R
12175

12276
ADD https://raw.githubusercontent.com/symfony/symfony/refs/heads/7.2/src/Symfony/Component/Console/Resources/completion.bash /tmp/completion.bash
12377

@@ -133,6 +87,13 @@ RUN sed /tmp/completion.bash \
13387
-e "s/{{ VERSION }}/1/g" \
13488
> /etc/bash_completion.d/console
13589

90+
# Config
91+
COPY ./builder/php.ini $PHP_INI_DIR/conf.d/app-builder.ini
92+
COPY builder/etc/. /etc/
93+
RUN adduser app sudo \
94+
&& mkdir /var/log/php \
95+
&& chmod 777 /var/log/php
96+
13697
# Third party tools
13798
ENV PATH="$PATH:/var/www/tools/bin"
13899

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
; priority=30
21
[PHP]
32
short_open_tag = Off
4-
memory_limit = 512M
3+
memory_limit = 128M
54
error_reporting = E_ALL
65
display_errors = On
76
display_startup_errors = On
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
; priority=40
21
[PHP]
32
error_log = /var/log/php/error.log
3+
memory_limit = 2G
44
[opcache]
55
opcache.error_log = /var/log/php/opcache.log

infrastructure/docker/services/php/entrypoint

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ if [ "$#" = 0 ]; then
1616
fi
1717

1818
if [ "$UID" != 0 ]; then
19-
usermod -u "$UID" "{{ application_user }}" >/dev/null 2>/dev/null && {
20-
groupmod -g "$GID" "{{ application_user }}" >/dev/null 2>/dev/null ||
21-
usermod -a -G "$GID" "{{ application_user }}" >/dev/null 2>/dev/null
19+
usermod -u "$UID" "app" >/dev/null 2>/dev/null && {
20+
groupmod -g "$GID" "app" >/dev/null 2>/dev/null ||
21+
usermod -a -G "$GID" "app" >/dev/null 2>/dev/null
2222
}
2323
set -- gosu "${UID}:${GID}" "${@}"
2424
fi
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
frankenphp
3+
auto_https off
4+
debug
5+
}
6+
7+
http://{$SERVER_NAME}:80 {
8+
encode zstd gzip
9+
10+
root /var/www/public
11+
php_server
12+
13+
log {
14+
output stdout
15+
format json
16+
}
17+
}

infrastructure/docker/services/php/frontend/etc/nginx/environments

Whitespace-only changes.

infrastructure/docker/services/php/frontend/etc/nginx/nginx.conf

-74
This file was deleted.

infrastructure/docker/services/php/frontend/etc/service/nginx/run

-3
This file was deleted.

infrastructure/docker/services/php/frontend/etc/service/php-fpm/run

-3
This file was deleted.

infrastructure/docker/services/php/frontend/php-configuration/fpm/php-fpm.conf

-19
This file was deleted.

infrastructure/docker/services/php/frontend/php-configuration/mods-available/app-fpm.ini

-5
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[PHP]
2+
; We should not put a value like this, but this is for the sake of the demo
3+
memory_limit = 2G

0 commit comments

Comments
 (0)