Skip to content

Commit 8641760

Browse files
authored
fix: backport changes from Symfony Docker (api-platform#2889)
1 parent 24aafbd commit 8641760

10 files changed

Lines changed: 70 additions & 33 deletions

File tree

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ jobs:
5050
-
5151
name: Check PWA reachability
5252
run: "curl -vk --fail-with-body -H 'Accept: text/html' https://localhost"
53+
-
54+
name: Check Mercure reachability
55+
run: curl -vkI --fail-with-body https://localhost/.well-known/mercure?topic=test
5356
-
5457
name: Create test database
5558
run: docker compose exec -T php bin/console -e test doctrine:database:create

api/Dockerfile

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ RUN apt-get update && apt-get install --no-install-recommends -y \
2929
# https://getcomposer.org/doc/03-cli.md#composer-allow-superuser
3030
ENV COMPOSER_ALLOW_SUPERUSER=1
3131

32+
ENV PHP_INI_SCAN_DIR=":$PHP_INI_DIR/app.conf.d"
33+
3234
RUN set -eux; \
3335
install-php-extensions \
3436
@composer \
@@ -45,19 +47,21 @@ RUN set -eux; \
4547
###< doctrine/doctrine-bundle ###
4648
###< recipes ###
4749

48-
COPY --link frankenphp/conf.d/app.ini $PHP_INI_DIR/conf.d/
50+
COPY --link frankenphp/conf.d/10-app.ini $PHP_INI_DIR/app.conf.d/
4951
COPY --link --chmod=755 frankenphp/docker-entrypoint.sh /usr/local/bin/docker-entrypoint
50-
COPY --link frankenphp/Caddyfile /etc/caddy/Caddyfile
52+
COPY --link frankenphp/Caddyfile /etc/frankenphp/Caddyfile
5153

5254
ENTRYPOINT ["docker-entrypoint"]
5355

5456
HEALTHCHECK --start-period=60s CMD curl -f http://localhost:2019/metrics || exit 1
55-
CMD [ "frankenphp", "run", "--config", "/etc/caddy/Caddyfile" ]
57+
CMD [ "frankenphp", "run", "--config", "/etc/frankenphp/Caddyfile" ]
5658

5759
# Dev FrankenPHP image
5860
FROM frankenphp_base AS frankenphp_dev
5961

60-
ENV APP_ENV=dev XDEBUG_MODE=off
62+
ENV APP_ENV=dev
63+
ENV XDEBUG_MODE=off
64+
ENV FRANKENPHP_WORKER_CONFIG=watch
6165
VOLUME /app/var/
6266

6367
RUN mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini"
@@ -67,20 +71,18 @@ RUN set -eux; \
6771
xdebug \
6872
;
6973

70-
COPY --link frankenphp/conf.d/app.dev.ini $PHP_INI_DIR/conf.d/
74+
COPY --link frankenphp/conf.d/20-app.dev.ini $PHP_INI_DIR/app.conf.d/
7175

72-
CMD [ "frankenphp", "run", "--config", "/etc/caddy/Caddyfile", "--watch" ]
76+
CMD [ "frankenphp", "run", "--config", "/etc/frankenphp/Caddyfile", "--watch" ]
7377

7478
# Prod FrankenPHP image
7579
FROM frankenphp_base AS frankenphp_prod
7680

7781
ENV APP_ENV=prod
78-
ENV FRANKENPHP_CONFIG="import worker.Caddyfile"
7982

8083
RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"
8184

82-
COPY --link frankenphp/conf.d/app.prod.ini $PHP_INI_DIR/conf.d/
83-
COPY --link frankenphp/worker.Caddyfile /etc/caddy/worker.Caddyfile
85+
COPY --link frankenphp/conf.d/20-app.prod.ini $PHP_INI_DIR/app.conf.d/
8486

8587
# prevent the reinstallation of vendors at every changes in the source code
8688
COPY --link composer.* symfony.* ./

api/frankenphp/Caddyfile

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
11
{
2+
skip_install_trust
3+
24
{$CADDY_GLOBAL_OPTIONS}
35

46
frankenphp {
57
{$FRANKENPHP_CONFIG}
8+
9+
worker {
10+
env APP_RUNTIME Runtime\FrankenPhpSymfony\Runtime
11+
file ./public/index.php
12+
13+
{$FRANKENPHP_WORKER_CONFIG}
14+
}
615
}
716
}
817

@@ -18,7 +27,7 @@
1827
}
1928
}
2029

21-
root * /app/public
30+
root /app/public
2231
encode zstd br gzip
2332

2433
mercure {
@@ -43,21 +52,34 @@
4352
# Disable Topics tracking if not enabled explicitly: https://github.com/jkarlin/topics
4453
header ?Permissions-Policy "browsing-topics=()"
4554

46-
# Matches requests for HTML documents, for static files and for Next.js files,
47-
# except for known API paths and paths with extensions handled by API Platform
48-
@pwa expression `(
49-
header({'Accept': '*text/html*'})
50-
&& !path(
51-
'/docs*', '/graphql*', '/bundles*', '/contexts*', '/_profiler*', '/_wdt*',
52-
'*.json*', '*.html', '*.csv', '*.yml', '*.yaml', '*.xml'
55+
route {
56+
# Matches requests for HTML documents, for static files and for Next.js files,
57+
# except for known API paths and paths with extensions handled by API Platform
58+
@pwa expression `(
59+
header({'Accept': '*text/html*'})
60+
&& !path(
61+
'/docs*', '/graphql*', '/bundles*', '/contexts*', '/_profiler*', '/_wdt*',
62+
'*.json*', '*.html', '*.csv', '*.yml', '*.yaml', '*.xml'
63+
)
5364
)
54-
)
55-
|| path('/favicon.ico', '/manifest.json', '/robots.txt', '/sitemap*', '/_next*', '/__next*')
56-
|| query({'_rsc': '*'})`
65+
|| path('/favicon.ico', '/manifest.json', '/robots.txt', '/sitemap*', '/_next*', '/__next*')
66+
|| query({'_rsc': '*'})`
5767

58-
# Comment the following line if you don't want Next.js to catch requests for HTML documents.
59-
# In this case, they will be handled by the PHP app.
60-
reverse_proxy @pwa http://{$PWA_UPSTREAM}
68+
# Comment the following line if you don't want Next.js to catch requests for HTML documents.
69+
# In this case, they will be handled by the PHP app.
70+
reverse_proxy @pwa http://{$PWA_UPSTREAM}
6171

62-
php_server
72+
@phpRoute {
73+
not path /.well-known/mercure*
74+
not file {path}
75+
}
76+
rewrite @phpRoute index.php
77+
78+
@frontController path index.php
79+
php @frontController
80+
81+
file_server {
82+
hide *.php
83+
}
84+
}
6385
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
; https://symfony.com/doc/current/performance.html#use-the-opcache-class-preloading
2+
opcache.preload_user = root
3+
opcache.preload = /app/config/preload.php
4+
; https://symfony.com/doc/current/performance.html#don-t-check-php-files-timestamps
5+
opcache.validate_timestamps = 0

api/frankenphp/conf.d/app.prod.ini

Lines changed: 0 additions & 2 deletions
This file was deleted.

api/frankenphp/docker-entrypoint.sh

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,14 @@ if [ "$1" = 'frankenphp' ] || [ "$1" = 'php' ] || [ "$1" = 'bin/console' ]; then
66
composer install --prefer-dist --no-progress --no-interaction
77
fi
88

9+
# Display information about the current project
10+
# Or about an error in project initialization
11+
php bin/console -V
12+
913
if grep -q ^DATABASE_URL= .env; then
10-
echo "Waiting for database to be ready..."
14+
echo 'Waiting for database to be ready...'
1115
ATTEMPTS_LEFT_TO_REACH_DATABASE=60
12-
until [ $ATTEMPTS_LEFT_TO_REACH_DATABASE -eq 0 ] || DATABASE_ERROR=$(php bin/console dbal:run-sql -q "SELECT 1" 2>&1); do
16+
until [ $ATTEMPTS_LEFT_TO_REACH_DATABASE -eq 0 ] || DATABASE_ERROR=$(php bin/console dbal:run-sql -q 'SELECT 1' 2>&1); do
1317
if [ $? -eq 255 ]; then
1418
# If the Doctrine command exits with 255, an unrecoverable error occurred
1519
ATTEMPTS_LEFT_TO_REACH_DATABASE=0
@@ -21,11 +25,11 @@ if [ "$1" = 'frankenphp' ] || [ "$1" = 'php' ] || [ "$1" = 'bin/console' ]; then
2125
done
2226

2327
if [ $ATTEMPTS_LEFT_TO_REACH_DATABASE -eq 0 ]; then
24-
echo "The database is not up or not reachable:"
28+
echo 'The database is not up or not reachable:'
2529
echo "$DATABASE_ERROR"
2630
exit 1
2731
else
28-
echo "The database is now ready and reachable"
32+
echo 'The database is now ready and reachable'
2933
fi
3034

3135
if [ "$( find ./migrations -iname '*.php' -print -quit )" ]; then
@@ -35,6 +39,8 @@ if [ "$1" = 'frankenphp' ] || [ "$1" = 'php' ] || [ "$1" = 'bin/console' ]; then
3539

3640
setfacl -R -m u:www-data:rwX -m u:"$(whoami)":rwX var
3741
setfacl -dR -m u:www-data:rwX -m u:"$(whoami)":rwX var
42+
43+
echo 'PHP app ready!'
3844
fi
3945

4046
exec docker-php-entrypoint "$@"

compose.override.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@ services:
77
volumes:
88
- ./api:/app
99
- /app/var
10-
- ./api/frankenphp/Caddyfile:/etc/caddy/Caddyfile:ro
11-
- ./api/frankenphp/conf.d/app.dev.ini:/usr/local/etc/php/conf.d/app.dev.ini:ro
10+
- ./api/frankenphp/Caddyfile:/etc/frankenphp/Caddyfile:ro
11+
- ./api/frankenphp/conf.d/20-app.dev.ini:/usr/local/etc/php/app.conf.d/20-app.dev.ini:ro
1212
# If you develop on Mac or Windows you can remove the vendor/ directory
1313
# from the bind-mount for better performance by enabling the next line:
1414
#- /app/vendor
1515
environment:
16+
FRANKENPHP_WORKER_CONFIG: watch
1617
MERCURE_EXTRA_DIRECTIVES: demo
1718
# See https://xdebug.org/docs/all_settings#mode
1819
XDEBUG_MODE: "${XDEBUG_MODE:-off}"

compose.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ services:
1313
TRUSTED_HOSTS: ${TRUSTED_HOSTS:-^${SERVER_NAME:-example\.com|localhost}|php$$}
1414
DATABASE_URL: postgresql://${POSTGRES_USER:-app}:${POSTGRES_PASSWORD:-!ChangeMe!}@database:5432/${POSTGRES_DB:-app}?serverVersion=${POSTGRES_VERSION:-16}&charset=${POSTGRES_CHARSET:-utf8}
1515
MERCURE_URL: ${CADDY_MERCURE_URL:-http://php/.well-known/mercure}
16-
MERCURE_PUBLIC_URL: ${CADDY_MERCURE_PUBLIC_URL:-https://${SERVER_NAME:-localhost}/.well-known/mercure}
16+
MERCURE_PUBLIC_URL: ${CADDY_MERCURE_PUBLIC_URL:-https://${SERVER_NAME:-localhost}:${HTTPS_PORT:-443}/.well-known/mercure}
1717
MERCURE_JWT_SECRET: ${CADDY_MERCURE_JWT_SECRET:-!ChangeThisMercureHubJWTSecretKey!}
1818
volumes:
1919
- caddy_data:/data

0 commit comments

Comments
 (0)