|
| 1 | +#syntax=docker/dockerfile:1.4 |
| 2 | + |
| 3 | +# Versions |
| 4 | +FROM dunglas/frankenphp:1-php8.3 AS frankenphp_upstream |
| 5 | + |
| 6 | +# The different stages of this Dockerfile are meant to be built into separate images |
| 7 | +# https://docs.docker.com/develop/develop-images/multistage-build/#stop-at-a-specific-build-stage |
| 8 | +# https://docs.docker.com/compose/compose-file/#target |
| 9 | + |
| 10 | + |
| 11 | +# Base FrankenPHP image |
| 12 | +FROM frankenphp_upstream AS frankenphp_base |
| 13 | + |
| 14 | +WORKDIR /app |
| 15 | + |
| 16 | +VOLUME /app/var/ |
| 17 | + |
| 18 | +# persistent / runtime deps |
| 19 | +# hadolint ignore=DL3008 |
| 20 | +RUN apt-get update && apt-get install -y --no-install-recommends \ |
| 21 | + acl \ |
| 22 | + file \ |
| 23 | + gettext \ |
| 24 | + git \ |
| 25 | + && rm -rf /var/lib/apt/lists/* |
| 26 | + |
| 27 | +RUN set -eux; \ |
| 28 | + install-php-extensions \ |
| 29 | + @composer \ |
| 30 | + apcu \ |
| 31 | + intl \ |
| 32 | + opcache \ |
| 33 | + zip \ |
| 34 | + ; |
| 35 | + |
| 36 | +# https://getcomposer.org/doc/03-cli.md#composer-allow-superuser |
| 37 | +ENV COMPOSER_ALLOW_SUPERUSER=1 |
| 38 | + |
| 39 | +###> recipes ### |
| 40 | +###> doctrine/doctrine-bundle ### |
| 41 | +RUN install-php-extensions pdo_pgsql |
| 42 | +###< doctrine/doctrine-bundle ### |
| 43 | +###< recipes ### |
| 44 | + |
| 45 | +COPY --link frankenphp/conf.d/app.ini $PHP_INI_DIR/conf.d/ |
| 46 | +COPY --link --chmod=755 frankenphp/docker-entrypoint.sh /usr/local/bin/docker-entrypoint |
| 47 | +COPY --link frankenphp/Caddyfile /etc/caddy/Caddyfile |
| 48 | + |
| 49 | +ENTRYPOINT ["docker-entrypoint"] |
| 50 | + |
| 51 | +HEALTHCHECK --start-period=60s CMD curl -f http://localhost:2019/metrics || exit 1 |
| 52 | +CMD [ "frankenphp", "run", "--config", "/etc/caddy/Caddyfile" ] |
| 53 | + |
| 54 | +# Dev FrankenPHP image |
| 55 | +FROM frankenphp_base AS frankenphp_dev |
| 56 | + |
| 57 | +ENV APP_ENV=dev XDEBUG_MODE=off |
| 58 | + |
| 59 | +RUN mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini" |
| 60 | + |
| 61 | +RUN set -eux; \ |
| 62 | + install-php-extensions \ |
| 63 | + xdebug \ |
| 64 | + ; |
| 65 | + |
| 66 | +COPY --link frankenphp/conf.d/app.dev.ini $PHP_INI_DIR/conf.d/ |
| 67 | + |
| 68 | +CMD [ "frankenphp", "run", "--config", "/etc/caddy/Caddyfile", "--watch" ] |
| 69 | + |
| 70 | +# Prod FrankenPHP image |
| 71 | +FROM frankenphp_base AS frankenphp_prod |
| 72 | + |
| 73 | +ENV APP_ENV=prod |
| 74 | +ENV FRANKENPHP_CONFIG="import worker.Caddyfile" |
| 75 | + |
| 76 | +RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini" |
| 77 | + |
| 78 | +COPY --link frankenphp/conf.d/app.prod.ini $PHP_INI_DIR/conf.d/ |
| 79 | +COPY --link frankenphp/worker.Caddyfile /etc/caddy/worker.Caddyfile |
| 80 | + |
| 81 | +# prevent the reinstallation of vendors at every changes in the source code |
| 82 | +COPY --link composer.* symfony.* ./ |
| 83 | +RUN set -eux; \ |
| 84 | + composer install --no-cache --prefer-dist --no-dev --no-autoloader --no-scripts --no-progress |
| 85 | + |
| 86 | +# copy sources |
| 87 | +COPY --link . ./ |
| 88 | +RUN rm -Rf frankenphp/ |
| 89 | + |
| 90 | +RUN set -eux; \ |
| 91 | + mkdir -p var/cache var/log; \ |
| 92 | + composer dump-autoload --classmap-authoritative --no-dev; \ |
| 93 | + composer dump-env prod; \ |
| 94 | + composer run-script --no-dev post-install-cmd; \ |
| 95 | + chmod +x bin/console; sync; |
0 commit comments