|
| 1 | +#syntax=docker/dockerfile:1 |
| 2 | + |
| 3 | +# Versions |
| 4 | +FROM dunglas/frankenphp:1-php8.4 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 | + |
| 37 | +RUN set -eux; \ |
| 38 | + install-php-extensions \ |
| 39 | + @composer \ |
| 40 | + pdo_pgsql \ |
| 41 | + gmp \ |
| 42 | + gd \ |
| 43 | + imagick \ |
| 44 | + amqp \ |
| 45 | + fileinfo \ |
| 46 | + iconv \ |
| 47 | + exif \ |
| 48 | + gettext \ |
| 49 | + uuid \ |
| 50 | + xsl \ |
| 51 | + xml \ |
| 52 | + zip \ |
| 53 | + brotli \ |
| 54 | + zstd \ |
| 55 | + ; |
| 56 | + |
| 57 | +# https://getcomposer.org/doc/03-cli.md#composer-allow-superuser |
| 58 | +ENV COMPOSER_ALLOW_SUPERUSER=1 |
| 59 | + |
| 60 | +# Transport to use by Mercure (default to Bolt) |
| 61 | +ENV MERCURE_TRANSPORT_URL=bolt:///data/mercure.db |
| 62 | + |
| 63 | +ENV PHP_INI_SCAN_DIR=":$PHP_INI_DIR/app.conf.d" |
| 64 | + |
| 65 | +###> recipes ### |
| 66 | +###< recipes ### |
| 67 | + |
| 68 | +COPY --link frankenphp/conf.d/10-app.ini $PHP_INI_DIR/app.conf.d/ |
| 69 | +COPY --link --chmod=755 frankenphp/docker-entrypoint.sh /usr/local/bin/docker-entrypoint |
| 70 | +COPY --link frankenphp/Caddyfile /etc/frankenphp/Caddyfile |
| 71 | + |
| 72 | +ENTRYPOINT ["docker-entrypoint"] |
| 73 | + |
| 74 | +HEALTHCHECK --start-period=60s CMD curl -f http://localhost:2019/metrics || exit 1 |
| 75 | +CMD [ "frankenphp", "run", "--config", "/etc/frankenphp/Caddyfile" ] |
| 76 | + |
| 77 | +# Dev FrankenPHP image |
| 78 | +FROM frankenphp_base AS frankenphp_dev |
| 79 | + |
| 80 | +ENV APP_ENV=dev |
| 81 | +ENV XDEBUG_MODE=off |
| 82 | +ENV FRANKENPHP_WORKER_CONFIG=watch |
| 83 | + |
| 84 | +RUN mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini" |
| 85 | + |
| 86 | +RUN set -eux; \ |
| 87 | + install-php-extensions \ |
| 88 | + xdebug \ |
| 89 | + ; |
| 90 | + |
| 91 | +COPY --link frankenphp/conf.d/20-app.dev.ini $PHP_INI_DIR/app.conf.d/ |
| 92 | + |
| 93 | +CMD [ "frankenphp", "run", "--config", "/etc/frankenphp/Caddyfile", "--watch" ] |
| 94 | + |
| 95 | +# Prod FrankenPHP image |
| 96 | +FROM frankenphp_base AS frankenphp_prod |
| 97 | + |
| 98 | +ENV APP_ENV=prod |
| 99 | + |
| 100 | +RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini" |
| 101 | + |
| 102 | +COPY --link frankenphp/conf.d/20-app.prod.ini $PHP_INI_DIR/app.conf.d/ |
| 103 | + |
| 104 | +# prevent the reinstallation of vendors at every changes in the source code |
| 105 | +COPY --link composer.* symfony.* ./ |
| 106 | +RUN set -eux; \ |
| 107 | + composer install --no-cache --prefer-dist --no-dev --no-autoloader --no-scripts --no-progress |
| 108 | + |
| 109 | +# copy sources |
| 110 | +COPY --link . ./ |
| 111 | +RUN rm -Rf frankenphp/ |
| 112 | + |
| 113 | +RUN set -eux; \ |
| 114 | + mkdir -p var/cache var/log; \ |
| 115 | + composer dump-autoload --classmap-authoritative --no-dev; \ |
| 116 | + composer dump-env prod; \ |
| 117 | + composer run-script --no-dev post-install-cmd; \ |
| 118 | + chmod +x bin/console; sync; |
0 commit comments