Skip to content

Commit 72391b2

Browse files
chore: update from api-platform/api-platform (#588)
1 parent 43892aa commit 72391b2

28 files changed

+219
-151
lines changed

.github/workflows/ci.yml

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ jobs:
7979
-
8080
name: Check PWA reachability
8181
run: "curl -vk --fail-with-body -H 'Accept: text/html' https://localhost"
82+
-
83+
name: Check Mercure reachability
84+
run: curl -vkI --fail-with-body https://localhost/.well-known/mercure?topic=test
8285
-
8386
name: Create test database
8487
run: docker compose exec -T php bin/console -e test doctrine:database:create
@@ -180,7 +183,7 @@ jobs:
180183
run: docker compose run --rm php bin/console doctrine:fixtures:load --no-interaction
181184
-
182185
name: Run Playwright
183-
run: docker run --network host -w /app -v ./e2e:/app --rm --ipc=host mcr.microsoft.com/playwright:v1.56.1-noble /bin/sh -c 'npm i; npx playwright test --grep ${{ matrix.annotation }};'
186+
run: docker run --network host -w /app -v ./e2e:/app --rm --ipc=host mcr.microsoft.com/playwright:v1.58.0-noble /bin/sh -c 'npm i; npx playwright test --grep ${{ matrix.annotation }};'
184187
-
185188
name: Debug Services
186189
if: failure()
@@ -210,35 +213,34 @@ jobs:
210213
recursive: true
211214

212215
# Lint API
213-
# todo Waiting for PHP CS Fixer to support PHP 8.4
214-
# -
215-
# name: PHP CS Fixer Cache
216-
# uses: actions/cache@v5
217-
# with:
218-
# path: api/.php-cs-fixer.cache
219-
# key: ${{ runner.OS }}-phpcsfixer-${{ github.sha }}
220-
# restore-keys: |
221-
# ${{ runner.OS }}-phpcsfixer-
222-
# -
223-
# name: Get API changed files
224-
# id: api-changed-files
225-
# uses: tj-actions/changed-files@v46
226-
# with:
227-
# files: api/**/*.php
228-
# -
229-
# name: Get Extra Arguments for PHP-CS-Fixer
230-
# id: phpcs-intersection
231-
# run: |
232-
# CHANGED_FILES=$(echo "${{ steps.api-changed-files.outputs.all_changed_and_modified_files }}" | tr ' ' '\n')
233-
# if ! echo "${CHANGED_FILES}" | grep -qE "^api\/(\\.php-cs-fixer(\\.dist)?\\.php|composer\\.lock)$"; then EXTRA_ARGS=$(printf -- '--path-mode=intersection\n--\n%s' "${CHANGED_FILES}"); else EXTRA_ARGS=''; fi
234-
# echo "PHPCS_EXTRA_ARGS<<EOF" >> $GITHUB_ENV
235-
# echo "$EXTRA_ARGS" >> $GITHUB_ENV
236-
# echo "EOF" >> $GITHUB_ENV
237-
# -
238-
# name: Lint API
239-
# uses: docker://oskarstark/php-cs-fixer-ga
240-
# with:
241-
# args: --config=api/.php-cs-fixer.dist.php -v --dry-run --stop-on-violation --using-cache=no ${{ env.PHPCS_EXTRA_ARGS }}"
216+
-
217+
name: PHP CS Fixer Cache
218+
uses: actions/cache@v5
219+
with:
220+
path: api/.php-cs-fixer.cache
221+
key: ${{ runner.OS }}-phpcsfixer-${{ github.sha }}
222+
restore-keys: |
223+
${{ runner.OS }}-phpcsfixer-
224+
-
225+
name: Get API changed files
226+
id: api-changed-files
227+
uses: tj-actions/changed-files@v46
228+
with:
229+
files: api/**/*.php
230+
-
231+
name: Get Extra Arguments for PHP-CS-Fixer
232+
id: phpcs-intersection
233+
run: |
234+
CHANGED_FILES=$(echo "${{ steps.api-changed-files.outputs.all_changed_and_modified_files }}" | tr ' ' '\n')
235+
if ! echo "${CHANGED_FILES}" | grep -qE "^api\/(\\.php-cs-fixer(\\.dist)?\\.php|composer\\.lock)$"; then EXTRA_ARGS=$(printf -- '--path-mode=intersection\n--\n%s' "${CHANGED_FILES}"); else EXTRA_ARGS=''; fi
236+
echo "PHPCS_EXTRA_ARGS<<EOF" >> $GITHUB_ENV
237+
echo "$EXTRA_ARGS" >> $GITHUB_ENV
238+
echo "EOF" >> $GITHUB_ENV
239+
-
240+
name: Lint API
241+
uses: docker://oskarstark/php-cs-fixer-ga
242+
with:
243+
args: --config=api/.php-cs-fixer.dist.php -v --dry-run --stop-on-violation --using-cache=no ${{ env.PHPCS_EXTRA_ARGS }}"
242244

243245
# Lint PWA
244246
-

api/Dockerfile

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

33+
ENV PHP_INI_SCAN_DIR=":$PHP_INI_DIR/app.conf.d"
34+
3335
RUN set -eux; \
3436
install-php-extensions \
3537
@composer \
@@ -47,19 +49,21 @@ RUN set -eux; \
4749
###< doctrine/doctrine-bundle ###
4850
###< recipes ###
4951

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

5456
ENTRYPOINT ["docker-entrypoint"]
5557

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

5961
# Dev FrankenPHP image
6062
FROM frankenphp_base AS frankenphp_dev
6163

62-
ENV APP_ENV=dev XDEBUG_MODE=off
64+
ENV APP_ENV=dev
65+
ENV XDEBUG_MODE=off
66+
ENV FRANKENPHP_WORKER_CONFIG=watch
6367
VOLUME /app/var/
6468

6569
RUN mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini"
@@ -69,20 +73,18 @@ RUN set -eux; \
6973
xdebug \
7074
;
7175

72-
COPY --link frankenphp/conf.d/app.dev.ini $PHP_INI_DIR/conf.d/
76+
COPY --link frankenphp/conf.d/20-app.dev.ini $PHP_INI_DIR/app.conf.d/
7377

74-
CMD [ "frankenphp", "run", "--config", "/etc/caddy/Caddyfile", "--watch" ]
78+
CMD [ "frankenphp", "run", "--config", "/etc/frankenphp/Caddyfile", "--watch" ]
7579

7680
# Prod FrankenPHP image
7781
FROM frankenphp_base AS frankenphp_prod
7882

7983
ENV APP_ENV=prod
80-
ENV FRANKENPHP_CONFIG="import worker.Caddyfile"
8184

8285
RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"
8386

84-
COPY --link frankenphp/conf.d/app.prod.ini $PHP_INI_DIR/conf.d/
85-
COPY --link frankenphp/worker.Caddyfile /etc/caddy/worker.Caddyfile
87+
COPY --link frankenphp/conf.d/20-app.prod.ini $PHP_INI_DIR/app.conf.d/
8688

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

api/frankenphp/Caddyfile

Lines changed: 40 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33

44
frankenphp {
55
{$FRANKENPHP_CONFIG}
6-
}
76

8-
# https://caddyserver.com/docs/caddyfile/directives#sorting-algorithm
9-
order mercure after encode
10-
order vulcain after reverse_proxy
11-
order php_server before file_server
7+
worker {
8+
env APP_RUNTIME Runtime\FrankenPhpSymfony\Runtime
9+
file ./public/index.php
10+
11+
{$FRANKENPHP_WORKER_CONFIG}
12+
}
13+
}
1214
}
1315

1416
{$CADDY_EXTRA_CONFIG}
@@ -23,7 +25,7 @@
2325
}
2426
}
2527

26-
root * /app/public
28+
root /app/public
2729
encode zstd br gzip
2830

2931
mercure {
@@ -48,28 +50,41 @@
4850
# Disable Topics tracking if not enabled explicitly: https://github.com/jkarlin/topics
4951
header ?Permissions-Policy "browsing-topics=()"
5052

51-
# Matches requests for OIDC routes
52-
@oidc expression path('/oidc/*')
53+
route {
54+
# Matches requests for OIDC routes
55+
@oidc expression path('/oidc/*')
5356

54-
# Comment the following line if you don't want to manage Keycloak locally
55-
# In this case, you'll need an external OIDC server
56-
reverse_proxy @oidc http://{$OIDC_UPSTREAM}
57+
# Comment the following line if you don't want to manage Keycloak locally
58+
# In this case, you'll need an external OIDC server
59+
reverse_proxy @oidc http://{$OIDC_UPSTREAM}
5760

58-
# Matches requests for HTML documents, for static files and for Next.js files,
59-
# except for known API paths and paths with extensions handled by API Platform
60-
@pwa expression `(
61-
header({'Accept': '*text/html*'})
62-
&& !path(
63-
'/docs*', '/graphql*', '/bundles*', '/contexts*', '/_profiler*', '/_wdt*',
64-
'*.json*', '*.html', '*.csv', '*.yml', '*.yaml', '*.xml'
61+
# Matches requests for HTML documents, for static files and for Next.js files,
62+
# except for known API paths and paths with extensions handled by API Platform
63+
@pwa expression `(
64+
header({'Accept': '*text/html*'})
65+
&& !path(
66+
'/docs*', '/graphql*', '/bundles*', '/contexts*', '/_profiler*', '/_wdt*',
67+
'*.json*', '*.html', '*.csv', '*.yml', '*.yaml', '*.xml'
68+
)
6569
)
66-
)
67-
|| path('/favicon.ico', '/manifest.json', '/robots.txt', '/sitemap*', '/_next*', '/__next*', '/api/auth/*')
68-
|| query({'_rsc': '*'})`
70+
|| path('/favicon.ico', '/manifest.json', '/robots.txt', '/sitemap*', '/_next*', '/__next*', '/api/auth/*')
71+
|| query({'_rsc': '*'})`
6972

70-
# Comment the following line if you don't want Next.js to catch requests for HTML documents.
71-
# In this case, they will be handled by the PHP app.
72-
reverse_proxy @pwa http://{$PWA_UPSTREAM}
73+
# Comment the following line if you don't want Next.js to catch requests for HTML documents.
74+
# In this case, they will be handled by the PHP app.
75+
reverse_proxy @pwa http://{$PWA_UPSTREAM}
7376

74-
php_server
77+
@phpRoute {
78+
not path /.well-known/mercure*
79+
not file {path}
80+
}
81+
rewrite @phpRoute index.php
82+
83+
@frontController path index.php
84+
php @frontController
85+
86+
file_server {
87+
hide *.php
88+
}
89+
}
7590
}
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 "$@"

api/phpunit.xml.dist

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,14 @@
1111
failOnRisky="true"
1212
failOnDeprecation="true"
1313
failOnNotice="true"
14+
failOnPhpunitDeprecation="true"
15+
failOnPhpunitNotice="true"
1416
displayDetailsOnTestsThatTriggerDeprecations="true"
1517
displayDetailsOnTestsThatTriggerErrors="true"
1618
displayDetailsOnTestsThatTriggerNotices="true"
1719
displayDetailsOnTestsThatTriggerWarnings="true"
20+
displayDetailsOnPhpunitDeprecations="true"
21+
displayDetailsOnPhpunitNotices="true"
1822
>
1923
<php>
2024
<ini name="display_errors" value="1" />

api/tests/Api/Admin/BookTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function asAdminUserICanGetACollectionOfBooks(FactoryCollection $factory,
7575

7676
self::assertResponseIsSuccessful();
7777
self::assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8');
78-
self::assertEquals('<https://localhost/.well-known/mercure>; rel="mercure"', $response->getHeaders()['link'][1]);
78+
self::assertEquals('<https://localhost:443/.well-known/mercure>; rel="mercure"', $response->getHeaders()['link'][1]);
7979
self::assertJsonContains([
8080
'hydra:totalItems' => $hydraTotalItems,
8181
]);
@@ -143,7 +143,7 @@ public function asAdminUserICanGetACollectionOfBooksOrderedByTitle(): void
143143

144144
self::assertResponseIsSuccessful();
145145
self::assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8');
146-
self::assertEquals('<https://localhost/.well-known/mercure>; rel="mercure"', $response->getHeaders()['link'][1]);
146+
self::assertEquals('<https://localhost:443/.well-known/mercure>; rel="mercure"', $response->getHeaders()['link'][1]);
147147
self::assertEquals('Ball Lightning', $response->toArray()['hydra:member'][0]['title']);
148148
self::assertEquals('Hyperion', $response->toArray()['hydra:member'][1]['title']);
149149
self::assertEquals('The Wandering Earth', $response->toArray()['hydra:member'][2]['title']);
@@ -215,7 +215,7 @@ public function asAdminUserICanGetABook(): void
215215

216216
self::assertResponseIsSuccessful();
217217
self::assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8');
218-
self::assertEquals('<https://localhost/.well-known/mercure>; rel="mercure"', $response->getHeaders(false)['link'][1]);
218+
self::assertEquals('<https://localhost:443/.well-known/mercure>; rel="mercure"', $response->getHeaders(false)['link'][1]);
219219
self::assertJsonContains([
220220
'@id' => '/admin/books/' . $book->getId(),
221221
'book' => $book->book,
@@ -385,7 +385,7 @@ public function asAdminUserICanCreateABook(): void
385385

386386
self::assertResponseStatusCodeSame(Response::HTTP_CREATED);
387387
self::assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8');
388-
self::assertEquals('<https://localhost/.well-known/mercure>; rel="mercure"', $response->getHeaders(false)['link'][1]);
388+
self::assertEquals('<https://localhost:443/.well-known/mercure>; rel="mercure"', $response->getHeaders(false)['link'][1]);
389389
self::assertJsonContains([
390390
'book' => 'https://gutendex.com/books/31547.json',
391391
'condition' => BookCondition::NewCondition->value,
@@ -523,7 +523,7 @@ public function asAdminUserICanUpdateABook(): void
523523

524524
self::assertResponseStatusCodeSame(Response::HTTP_OK);
525525
self::assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8');
526-
self::assertEquals('<https://localhost/.well-known/mercure>; rel="mercure"', $response->getHeaders(false)['link'][1]);
526+
self::assertEquals('<https://localhost:443/.well-known/mercure>; rel="mercure"', $response->getHeaders(false)['link'][1]);
527527
self::assertJsonContains([
528528
'book' => 'https://gutendex.com/books/31547.json',
529529
'condition' => BookCondition::DamagedCondition->value,

0 commit comments

Comments
 (0)