Something went wrong. Try again.
Something went wrong. Try again.
5.7 kB · 166 lines
Dockerfile
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167#syntax=docker/dockerfile:1
# VersionsFROM dunglas/frankenphp:1-php8.5 AS frankenphp_upstream
# The different stages of this Dockerfile are meant to be built into separate images# https://docs.docker.com/build/building/multi-stage/#stop-at-a-specific-build-stage# https://docs.docker.com/reference/compose-file/build/#target
# Base FrankenPHP imageFROM frankenphp_upstream AS frankenphp_base
SHELL ["/bin/bash", "-euxo", "pipefail", "-c"]
WORKDIR /app
# persistent deps# hadolint ignore=DL3008RUN <<-EOF apt-get update apt-get install -y --no-install-recommends \ file \ git install-php-extensions \ @composer \ apcu \ intl \ opcache \ zip rm -rf /var/lib/apt/lists/*EOF
# https://getcomposer.org/doc/03-cli.md#composer-allow-superuserENV COMPOSER_ALLOW_SUPERUSER=1
ENV PHP_INI_SCAN_DIR=":$PHP_INI_DIR/app.conf.d"
###> recipes ######< recipes ###
COPY --link frankenphp/conf.d/10-app.ini $PHP_INI_DIR/app.conf.d/COPY --link --chmod=755 frankenphp/docker-entrypoint.sh /usr/local/bin/docker-entrypointCOPY --link frankenphp/Caddyfile /etc/frankenphp/Caddyfile
ENTRYPOINT ["docker-entrypoint"]
HEALTHCHECK --start-period=60s CMD php -r 'exit(false === @file_get_contents("http://localhost:2019/metrics", context: stream_context_create(["http" => ["timeout" => 5]])) ? 1 : 0);'CMD [ "frankenphp", "run", "--config", "/etc/frankenphp/Caddyfile" ]
# Dev FrankenPHP imageFROM frankenphp_base AS frankenphp_dev
ENV APP_ENV=devENV XDEBUG_MODE=offENV FRANKENPHP_WORKER_CONFIG=watch
# dev dependenciesRUN <<-EOF mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini" install-php-extensions xdebug useradd -m -s /bin/bash nonroot git config --system --add safe.directory /appEOF
COPY --link frankenphp/conf.d/20-app.dev.ini $PHP_INI_DIR/app.conf.d/
CMD [ "frankenphp", "run", "--config", "/etc/frankenphp/Caddyfile", "--watch" ]
# Builder for the prod FrankenPHP imageFROM frankenphp_base AS frankenphp_prod_builder
ENV APP_ENV=prod
RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"
COPY --link frankenphp/conf.d/20-app.prod.ini $PHP_INI_DIR/app.conf.d/
# prevent the reinstallation of vendors at every changes in the source codeCOPY --link composer.* symfony.* ./ENV COMPOSER_CACHE_DIR=/tmp/composer-cacheRUN --mount=type=cache,target=/tmp/composer-cache,sharing=locked \ composer install --prefer-dist --no-dev --no-autoloader --no-scripts --no-progress
# copy sourcesCOPY --link --exclude=frankenphp/ . ./
RUN <<-EOF mkdir -p var/cache var/log var/share composer dump-autoload --classmap-authoritative --no-dev composer dump-env prod composer run-script --no-dev post-install-cmd if [ -f importmap.php ]; then php bin/console asset-map:compile fi chmod +x bin/console chmod -R g=u var syncEOF
# Collect shared libraries needed by FrankenPHP and PHP extensions# hadolint ignore=DL3008,SC3054,DL4006RUN <<-'EOF' apt-get update apt-get install -y --no-install-recommends libtree mkdir -p /tmp/libs BINARIES=(frankenphp php file) for target in $(printf '%s\n' "${BINARIES[@]}" | xargs -I{} which {}) \ $(find "$(php -r 'echo ini_get("extension_dir");')" -maxdepth 2 -name "*.so"); do libtree -pv "$target" 2>/dev/null | grep -oP '(?:── )\K/\S+(?= \[)' | while IFS= read -r lib; do [ -f "$lib" ] && cp -n "$lib" /tmp/libs/ done done rm -rf /var/lib/apt/lists/*EOF
# Prod FrankenPHP imageFROM debian:13-slim AS frankenphp_prod
SHELL ["/bin/bash", "-euxo", "pipefail", "-c"]
ENV APP_ENV=prodENV PHP_INI_SCAN_DIR=":/usr/local/etc/php/app.conf.d"
COPY --from=frankenphp_prod_builder /usr/local/bin/frankenphp /usr/local/bin/frankenphpCOPY --from=frankenphp_prod_builder /usr/local/bin/php /usr/local/bin/phpCOPY --from=frankenphp_prod_builder /usr/local/bin/docker-php-entrypoint /usr/local/bin/docker-php-entrypointCOPY --from=frankenphp_prod_builder /usr/local/lib/php/extensions /usr/local/lib/php/extensionsCOPY --from=frankenphp_prod_builder /tmp/libs /usr/lib
COPY --from=frankenphp_prod_builder /usr/local/etc/php/conf.d /usr/local/etc/php/conf.dCOPY --from=frankenphp_prod_builder /usr/local/etc/php/php.ini /usr/local/etc/php/php.iniCOPY --from=frankenphp_prod_builder /usr/local/etc/php/app.conf.d /usr/local/etc/php/app.conf.d
COPY --from=frankenphp_prod_builder /etc/frankenphp/Caddyfile /etc/frankenphp/Caddyfile
# CA certificates for TLS, file/libmagic for Symfony MIME type detectionCOPY --from=frankenphp_prod_builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crtCOPY --from=frankenphp_prod_builder /etc/ssl/openssl.cnf /etc/ssl/openssl.cnfCOPY --from=frankenphp_prod_builder /usr/bin/file /usr/bin/fileCOPY --from=frankenphp_prod_builder /usr/lib/file/magic.mgc /usr/lib/file/magic.mgc
ENV OPENSSL_CONF=/etc/ssl/openssl.cnf XDG_CONFIG_HOME=/config XDG_DATA_HOME=/data SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt
RUN <<-EOF mkdir -p /data/caddy /config/caddy chown -R www-data:www-data /data /config # Remove setuid/setgid bits find / -perm /6000 -type f -exec chmod a-s {} + 2>/dev/null || trueEOF
COPY --link --exclude=var --from=frankenphp_prod_builder /app /app# Group 0 + g=u for arbitrary-UID runtimes (e.g. OpenShift).COPY --chown=www-data:0 --from=frankenphp_prod_builder /app/var /app/varRUN chmod g=u /app/var
COPY --link --chmod=755 frankenphp/docker-entrypoint.sh /usr/local/bin/docker-entrypoint
USER www-data
WORKDIR /app
ENTRYPOINT ["docker-entrypoint"]
HEALTHCHECK --start-period=60s CMD php -r 'exit(false === @file_get_contents("http://localhost:2019/metrics", context: stream_context_create(["http" => ["timeout" => 5]])) ? 1 : 0);'CMD [ "frankenphp", "run", "--config", "/etc/frankenphp/Caddyfile" ]