Skip to content

Commit

Permalink
chore: update api from distro
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentchalamon committed Oct 26, 2023
1 parent 988144e commit a65b36b
Show file tree
Hide file tree
Showing 21 changed files with 1,392 additions and 552 deletions.
4 changes: 4 additions & 0 deletions api/.dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
**/.gitattributes
**/.gitignore
**/.gitmodules
**/compose.*.yaml
**/compose.*.yml
**/compose.yaml
**/compose.yml
**/docker-compose.*.yaml
**/docker-compose.*.yml
**/docker-compose.yaml
Expand Down
11 changes: 6 additions & 5 deletions api/.env
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

# API Platform distribution
TRUSTED_PROXIES=127.0.0.0/8,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16
TRUSTED_HOSTS=^(localhost|caddy)$
TRUSTED_HOSTS=^(localhost|php)$
OIDC_SERVER_URL=https://localhost/oidc/realms/demo
OIDC_SERVER_URL_INTERNAL=https://caddy/oidc/realms/demo
OIDC_SERVER_URL_INTERNAL=http://php/oidc/realms/demo
OIDC_SWAGGER_CLIENT_ID=api-platform-swagger

###> symfony/framework-bundle ###
Expand All @@ -31,8 +31,9 @@ APP_SECRET=!ChangeMe!
# IMPORTANT: You MUST configure your server version, either here or in config/packages/doctrine.yaml
#
# DATABASE_URL="sqlite:///%kernel.project_dir%/var/data.db"
# DATABASE_URL="mysql://app:!ChangeMe!@127.0.0.1:3306/app?serverVersion=8&charset=utf8mb4"
DATABASE_URL="postgresql://app:!ChangeMe!@127.0.0.1:5432/app?serverVersion=15&charset=utf8"
# DATABASE_URL="mysql://app:!ChangeMe!@127.0.0.1:3306/app?serverVersion=8.0.32&charset=utf8mb4"
# DATABASE_URL="mysql://app:!ChangeMe!@127.0.0.1:3306/app?serverVersion=10.11.2-MariaDB&charset=utf8mb4"
DATABASE_URL="postgresql://app:!ChangeMe!@database:5432/app?serverVersion=15&charset=utf8"
###< doctrine/doctrine-bundle ###

###> nelmio/cors-bundle ###
Expand All @@ -42,7 +43,7 @@ CORS_ALLOW_ORIGIN='^https?://(localhost|127\.0\.0\.1)(:[0-9]+)?$'
###> symfony/mercure-bundle ###
# See https://symfony.com/doc/current/mercure.html#configuration
# The URL of the Mercure hub, used by the app to publish updates (can be a local URL)
MERCURE_URL=http://caddy/.well-known/mercure
MERCURE_URL=http://php/.well-known/mercure
# The public URL of the Mercure hub, used by the browser to connect
MERCURE_PUBLIC_URL=https://localhost/.well-known/mercure
# The secret used to sign the JWTs
Expand Down
1 change: 1 addition & 0 deletions api/.env.test
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# define your env variables for the test env here
KERNEL_CLASS='App\Kernel'
APP_SECRET='$ecretf0rt3st'
SYMFONY_DEPRECATIONS_HELPER=999999
PANTHER_APP_ENV=panther
PANTHER_ERROR_SCREENSHOT_DIR=./var/error-screenshots

Expand Down
81 changes: 27 additions & 54 deletions api/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,95 +4,86 @@


# Versions
FROM php:8.2-fpm-alpine AS php_upstream
FROM mlocati/php-extension-installer:2 AS php_extension_installer_upstream
# hadolint ignore=DL3007
FROM dunglas/frankenphp:latest-alpine AS frankenphp_upstream
FROM composer/composer:2-bin AS composer_upstream
FROM caddy:2-alpine AS caddy_upstream


# The different stages of this Dockerfile are meant to be built into separate images
# https://docs.docker.com/develop/develop-images/multistage-build/#stop-at-a-specific-build-stage
# https://docs.docker.com/compose/compose-file/#target


# Base PHP image
FROM php_upstream AS php_base
# Base FrankenPHP image
FROM frankenphp_upstream AS frankenphp_base

WORKDIR /srv/app
WORKDIR /app

# persistent / runtime deps
# hadolint ignore=DL3018
RUN apk add --no-cache \
acl \
fcgi \
file \
gettext \
git \
;

# php extensions installer: https://github.com/mlocati/docker-php-extension-installer
COPY --from=php_extension_installer_upstream --link /usr/bin/install-php-extensions /usr/local/bin/

RUN set -eux; \
install-php-extensions \
install-php-extensions \
apcu \
intl \
opcache \
zip \
;
;

###> recipes ###
###> doctrine/doctrine-bundle ###
RUN set -eux; \
install-php-extensions pdo_pgsql
install-php-extensions pdo_pgsql
###< doctrine/doctrine-bundle ###
###< recipes ###

COPY --link docker/php/conf.d/app.ini $PHP_INI_DIR/conf.d/

COPY --link docker/php/php-fpm.d/zz-docker.conf /usr/local/etc/php-fpm.d/zz-docker.conf
RUN mkdir -p /var/run/php

COPY --link docker/php/docker-healthcheck.sh /usr/local/bin/docker-healthcheck
RUN chmod +x /usr/local/bin/docker-healthcheck

HEALTHCHECK --interval=10s --timeout=3s --retries=3 CMD ["docker-healthcheck"]

COPY --link docker/php/docker-entrypoint.sh /usr/local/bin/docker-entrypoint
RUN chmod +x /usr/local/bin/docker-entrypoint
COPY --link frankenphp/conf.d/app.ini $PHP_INI_DIR/conf.d/
COPY --link --chmod=755 frankenphp/docker-entrypoint.sh /usr/local/bin/docker-entrypoint
COPY --link frankenphp/Caddyfile /etc/caddy/Caddyfile

ENTRYPOINT ["docker-entrypoint"]
CMD ["php-fpm"]

# https://getcomposer.org/doc/03-cli.md#composer-allow-superuser
ENV COMPOSER_ALLOW_SUPERUSER=1
ENV PATH="${PATH}:/root/.composer/vendor/bin"

COPY --from=composer_upstream --link /composer /usr/bin/composer

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

# Dev PHP image
FROM php_base AS php_dev
# Dev FrankenPHP image
FROM frankenphp_base AS frankenphp_dev

ENV APP_ENV=dev XDEBUG_MODE=off
VOLUME /srv/app/var/

RUN mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini"

RUN set -eux; \
install-php-extensions \
xdebug \
;
xdebug \
;

COPY --link frankenphp/conf.d/app.dev.ini $PHP_INI_DIR/conf.d/

COPY --link docker/php/conf.d/app.dev.ini $PHP_INI_DIR/conf.d/
CMD [ "frankenphp", "run", "--config", "/etc/caddy/Caddyfile", "--watch" ]

# Prod PHP image
FROM php_base AS php_prod
# Prod FrankenPHP image
FROM frankenphp_base AS frankenphp_prod

ENV APP_ENV=prod
ENV FRANKENPHP_CONFIG="import worker.Caddyfile"

RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"
COPY --link docker/php/conf.d/app.prod.ini $PHP_INI_DIR/conf.d/

COPY --link frankenphp/conf.d/app.prod.ini $PHP_INI_DIR/conf.d/
COPY --link frankenphp/worker.Caddyfile /etc/caddy/worker.Caddyfile

# prevent the reinstallation of vendors at every changes in the source code
COPY --link composer.* symfony.* ./
Expand All @@ -101,29 +92,11 @@ RUN set -eux; \

# copy sources
COPY --link . ./
RUN rm -Rf docker/
RUN rm -Rf frankenphp/

RUN set -eux; \
mkdir -p var/cache var/log; \
composer dump-autoload --classmap-authoritative --no-dev; \
composer dump-env prod; \
composer run-script --no-dev post-install-cmd; \
chmod +x bin/console; sync;


# Base Caddy image
FROM caddy_upstream AS caddy_base

ARG TARGETARCH

WORKDIR /srv/app

# Download Caddy compiled with the Mercure and Vulcain
ADD --chmod=500 https://caddyserver.com/api/download?os=linux&arch=$TARGETARCH&p=github.com/dunglas/mercure/caddy&p=github.com/dunglas/vulcain/caddy /usr/bin/caddy

COPY --link docker/caddy/Caddyfile /etc/caddy/Caddyfile

# Prod Caddy image
FROM caddy_base AS caddy_prod

COPY --from=php_prod --link /srv/app/public public/
7 changes: 3 additions & 4 deletions api/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
"php": ">=8.2",
"ext-ctype": "*",
"ext-iconv": "*",
"ext-xml": "*",
"api-platform/core": "^3.2@beta",
"api-platform/core": "^3.2",
"doctrine/doctrine-bundle": "^2.7",
"doctrine/doctrine-migrations-bundle": "^3.2",
"doctrine/orm": "^2.12",
"myclabs/php-enum": "^1.8",
"nelmio/cors-bundle": "^2.2",
"phpstan/phpdoc-parser": "^1.16",
"runtime/frankenphp-symfony": "^0.1.1",
"symfony/asset": "6.3.*",
"symfony/clock": "6.3.*",
"symfony/console": "6.3.*",
Expand All @@ -37,6 +37,7 @@
"webonyx/graphql-php": "^15.5"
},
"require-dev": {
"api-platform/schema-generator": "^5.0",
"dama/doctrine-test-bundle": "^7.2",
"doctrine/doctrine-fixtures-bundle": "^3.4",
"justinrainbow/json-schema": "^5.2",
Expand All @@ -51,15 +52,13 @@
"vimeo/psalm": "^4.7",
"zenstruck/foundry": "^1.32"
},
"prefer-stable": true,
"config": {
"optimize-autoloader": true,
"preferred-install": {
"*": "dist"
},
"sort-packages": true,
"allow-plugins": {
"composer/package-versions-deprecated": true,
"symfony/flex": true,
"symfony/runtime": true
}
Expand Down
Loading

0 comments on commit a65b36b

Please sign in to comment.