From 11325f73963770819376b2473bfaae4be27d6c94 Mon Sep 17 00:00:00 2001 From: tchapi Date: Fri, 31 May 2024 22:20:56 +0200 Subject: [PATCH] Update to PHP8.3 for Docker, reorganize layers --- docker/Dockerfile | 33 +++++++++++++++++++++++---------- docker/Dockerfile-standalone | 28 +++++++++++++++++++++------- 2 files changed, 44 insertions(+), 17 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 0d26dd5..8775187 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,15 +1,9 @@ -FROM php:8.2-fpm-alpine - +# Initial PHP image is available here: # https://github.com/docker-library/php/blob/master/8.2/alpine3.18/fpm/Dockerfile#L33 ARG fpm_user=82:82 -ENV FPM_USER=${fpm_user} -ENV PHP_OPCACHE_MEMORY_CONSUMPTION="256" \ - PHP_OPCACHE_MAX_WASTED_PERCENTAGE="10" - -LABEL org.opencontainers.image.authors="tchap@tchap.me" -LABEL org.opencontainers.image.url="https://github.com/tchapi/davis/pkgs/container/davis" -LABEL org.opencontainers.image.description="A simple, fully translatable admin interface for sabre/dav based on Symfony 5 and Bootstrap 4" +# Base image, used to build extensions and the final image ——————————————————————— +FROM php:8.3-fpm-alpine as base-image # Run update, and gets basic packages and packages for runtime RUN apk --no-progress --update add --no-cache \ @@ -27,6 +21,9 @@ RUN apk --no-progress --update add --no-cache \ # This is for PostgreSQL libpq +# Build all extensions in a separate image ——————————————————————————————————————— +FROM base-image AS extension-builder + # Intl support RUN apk --update --virtual build-deps-intl add --no-cache icu-dev \ && docker-php-ext-install intl \ @@ -70,6 +67,22 @@ RUN apk --update --virtual build-deps-imap add --no-cache imap-dev openssl-dev k RUN docker-php-ext-install opcache COPY ./docker/configurations/opcache.ini /usr/local/etc/php/conf.d/opcache.ini +# Final image ———————————————————————————————————————————————————————————————————— +FROM base-image + +ENV FPM_USER=${fpm_user} + +ENV PHP_OPCACHE_MEMORY_CONSUMPTION="256" \ + PHP_OPCACHE_MAX_WASTED_PERCENTAGE="10" + +LABEL org.opencontainers.image.authors="tchap@tchap.me" +LABEL org.opencontainers.image.url="https://github.com/tchapi/davis/pkgs/container/davis" +LABEL org.opencontainers.image.description="A simple, fully translatable admin interface for sabre/dav based on Symfony 5 and Bootstrap 5" + +# Rapatriate built extensions +COPY --from=extension-builder /usr/local/etc/php/conf.d /usr/local/etc/php/conf.d/ +COPY --from=extension-builder /usr/local/lib/php/extensions /usr/local/lib/php/extensions/ + # PHP-FPM healthcheck RUN set -xe && echo "pm.status_path = /status" >> /usr/local/etc/php-fpm.d/zz-docker.conf RUN curl https://raw.githubusercontent.com/renatomefi/php-fpm-healthcheck/v0.5.0/php-fpm-healthcheck \ @@ -85,7 +98,7 @@ RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local RUN APP_ENV=prod COMPOSER_ALLOW_SUPERUSER=1 composer install --no-ansi --no-dev --no-interaction --no-progress --optimize-autoloader # Cleanup (only useful when using --squash) -RUN docker-php-source delete && rm -rf /var/www/davis/docker +RUN rm -rf /var/www/davis/docker USER $FPM_USER diff --git a/docker/Dockerfile-standalone b/docker/Dockerfile-standalone index 558d75c..769d1cf 100644 --- a/docker/Dockerfile-standalone +++ b/docker/Dockerfile-standalone @@ -1,11 +1,8 @@ -FROM php:8.2-fpm-alpine +# Initial PHP image is available here: +# https://github.com/docker-library/php/blob/master/8.2/alpine3.18/fpm/Dockerfile#L33 -ENV PHP_OPCACHE_MEMORY_CONSUMPTION="256" \ - PHP_OPCACHE_MAX_WASTED_PERCENTAGE="10" - -LABEL org.opencontainers.image.authors="tchap@tchap.me" -LABEL org.opencontainers.image.url="https://github.com/tchapi/davis/pkgs/container/davis-standalone" -LABEL org.opencontainers.image.description="A simple, fully translatable admin interface for sabre/dav based on Symfony 5 and Bootstrap 4 (Standalone version with reverse-proxy)" +# Base image, used to build extensions and the final image ——————————————————————— +FROM php:8.3-fpm-alpine as base-image # Run update, and gets basic packages and packages for runtime RUN apk --no-progress --update add --no-cache \ @@ -25,6 +22,9 @@ RUN apk --no-progress --update add --no-cache \ # For the webserver and process manager caddy supervisor +# Build all extensions in a separate image ——————————————————————————————————————— +FROM base-image AS extension-builder + # Intl support RUN apk --update --virtual build-deps-intl add --no-cache icu-dev \ && docker-php-ext-install intl \ @@ -68,6 +68,20 @@ RUN apk --update --virtual build-deps-imap add --no-cache imap-dev openssl-dev k RUN docker-php-ext-install opcache COPY ./docker/configurations/opcache.ini /usr/local/etc/php/conf.d/opcache.ini +# Final image ———————————————————————————————————————————————————————————————————— +FROM base-image + +ENV PHP_OPCACHE_MEMORY_CONSUMPTION="256" \ + PHP_OPCACHE_MAX_WASTED_PERCENTAGE="10" + +LABEL org.opencontainers.image.authors="tchap@tchap.me" +LABEL org.opencontainers.image.url="https://github.com/tchapi/davis/pkgs/container/davis-standalone" +LABEL org.opencontainers.image.description="A simple, fully translatable admin interface for sabre/dav based on Symfony 5 and Bootstrap 5 (Standalone version with reverse-proxy)" + +# Rapatriate built extensions +COPY --from=extension-builder /usr/local/etc/php/conf.d /usr/local/etc/php/conf.d/ +COPY --from=extension-builder /usr/local/lib/php/extensions /usr/local/lib/php/extensions/ + # Davis source # The app folder needs to be owned by www-data so PHP-fpm can execute files ADD --chown=www-data:www-data . /var/www/davis