From e72252f27427285834722387c786f7aa12d6eceb Mon Sep 17 00:00:00 2001 From: IanM Date: Sat, 31 Oct 2026 10:07:58 +0000 Subject: [PATCH 1/7] perf: de-bloat FPM images by dropping build-only packages Build the PHP extensions in a single layer that installs the -dev packages, compiles, and purges them again, keeping only the runtime libraries the extensions link against (the official php image's apt-mark/ldd technique). Previously headers, static libraries and the extracted PHP source (~145 MB, left behind by a separate gd configure layer) shipped in every image. Install runtime packages with --no-install-recommends, naming the recommends that do real work (openssh-client and less for git, ImageMagick's extra coders and HEIC/AVIF encoders, Ghostscript's CJK fallback font, the perl modules mariadb-client's tools need). This drops exim4, dbus, systemd extras, netpbm and docs. Drop `docker-php-ext-install xml`: xml is compiled into the official image, so it only produced an xml.so that was never loaded. The build now fails if PHP prints a startup warning or an expected extension does not load. --- fpm/8.3/Dockerfile.apache | 158 +++++++++++++++++++++++------------ fpm/8.3/Dockerfile.cli | 158 +++++++++++++++++++++++------------ fpm/8.3/README.md | 22 +++++ fpm/8.5/Dockerfile.apache | 168 +++++++++++++++++++++++++------------- fpm/8.5/Dockerfile.cli | 166 ++++++++++++++++++++++++------------- fpm/8.5/README.md | 22 +++++ 6 files changed, 469 insertions(+), 225 deletions(-) diff --git a/fpm/8.3/Dockerfile.apache b/fpm/8.3/Dockerfile.apache index 49a92bc..cca581f 100644 --- a/fpm/8.3/Dockerfile.apache +++ b/fpm/8.3/Dockerfile.apache @@ -2,88 +2,138 @@ FROM php:8.3-fpm ENV DEBIAN_FRONTEND=noninteractive -# Setup Debian packages -RUN apt-get -y update && apt-get -y upgrade && ACCEPT_EULA=Y && apt-get install -y \ +# Runtime packages. --no-install-recommends keeps Debian from pulling in an +# MTA (exim4), dbus, systemd extras and docs; recommends that do real work are +# named explicitly instead: +# less, openssh-client git's pager, and git/composer over SSH +# psmisc, xxd killall/fuser/pstree, hex dumps +# fonts-droid-fallback Ghostscript's CJK fallback font +# libmagickcore-*-extra ImageMagick SVG, DjVu, OpenEXR and WMF coders +# libjxr-tools ImageMagick's JPEG XR delegate +# libheif-plugin-*enc HEIC and AVIF encoding through ImageMagick +# libdbd-mariadb-perl, the perl tools in mariadb-client (mytop, +# libterm-readkey-perl innotop, mariadb-hotcopy, ...) +# +# Headers, static libraries and other -dev packages are not installed here: +# they only exist inside the extension build layer below. +RUN apt-get -y update && apt-get -y upgrade && apt-get install -y --no-install-recommends \ apache2 \ procps \ cron \ unzip \ - libfreetype6-dev \ - libjpeg62-turbo-dev \ - libzip-dev \ - libxml2-dev \ - libxslt-dev \ - libssl-dev \ - zlib1g-dev \ - libpng-dev \ - libwebp-dev \ - libjpeg-dev \ - libonig-dev \ - libicu-dev \ + zip \ apt-file \ wget \ gnupg \ gnupg2 \ - zip \ git \ + less \ + openssh-client \ curl \ - gcc \ - g++ \ - autoconf \ - libc-dev \ - pkg-config \ iputils-ping \ netcat-openbsd \ default-mysql-client \ + libdbd-mariadb-perl \ + libterm-readkey-perl \ util-linux \ + psmisc \ gosu \ jq \ redis-tools \ vim \ + xxd \ python3 \ - liblz4-dev \ - libzstd-dev \ - libpq-dev \ - libmagickwand-dev \ imagemagick \ + libmagickcore-7.q16-10-extra \ + libjxr-tools \ + libheif-plugin-aomenc \ + libheif-plugin-x265 \ ghostscript \ - libavif-dev \ - libmaxminddb0 \ - libmaxminddb-dev && \ - apt-get clean && \ + fonts-droid-fallback \ + libmaxminddb0 && \ rm -rf /var/lib/apt/lists/* -# PHP extensions, separated for QEMU build purposes -RUN docker-php-ext-configure gd --with-freetype --with-webp --with-jpeg --with-avif -RUN docker-php-ext-install gd -RUN docker-php-ext-install calendar -RUN docker-php-ext-install intl -RUN docker-php-ext-install pdo_mysql -RUN docker-php-ext-install pdo_pgsql -RUN docker-php-ext-install xml -RUN docker-php-ext-install zip -RUN docker-php-ext-install exif -RUN docker-php-ext-install pcntl -RUN docker-php-ext-install sockets -RUN printf "log_errors = On \nerror_log = /dev/stderr\n" > /usr/local/etc/php/conf.d/php-logs.ini - # pecl.php.net fails under load; pecl-install retries with backoff. COPY bin/pecl-install /usr/local/bin/pecl-install RUN chmod +x /usr/local/bin/pecl-install -# Install redis extension with LZ4 and Zstd compression support -RUN pecl-install --configureoptions 'enable-redis-lz4="yes" with-liblz4="yes" enable-redis-zstd="yes"' redis \ - && docker-php-ext-enable redis - -# Install imagick extension -RUN pecl-install imagick && docker-php-ext-enable imagick - -# Install maxminddb extension for offline IP -> country lookups. +# PHP extensions, built in one layer so the build leaves nothing behind. +# +# The -dev packages, the extracted PHP source and pear's download cache are all +# installed, used and removed inside this RUN. Removing them in a later layer +# would not shrink the image: the files would still ship in the earlier layer. +# +# After the build, every package is marked auto except those that were already +# manual (the runtime packages above and the base image's) and those providing +# a shared library something under /usr/local links against, so the purge keeps +# exactly the runtime libraries the extensions need (libzip, libicu, libpq, +# libavif, libMagickWand, liblz4, libzstd, libmaxminddb, ...). This is the same +# technique the official php images use for their own build dependencies. # -# The C decoder is roughly 100x faster than maxmind-db/reader's pure-PHP -# fallback (~1.7us vs ~160us per lookup), which matters when a lookup happens -# on every request. Requires libmaxminddb0 at runtime -- do not purge it. -RUN pecl-install maxminddb && docker-php-ext-enable maxminddb +# xml is not built: it is compiled into the official php image already. +RUN set -eux; \ + savedAptMark="$(apt-mark showmanual)"; \ + apt-get update; \ + apt-get install -y --no-install-recommends \ + libavif-dev \ + libfreetype-dev \ + libicu-dev \ + libjpeg62-turbo-dev \ + liblz4-dev \ + libmagickwand-dev \ + libmaxminddb-dev \ + libpng-dev \ + libpq-dev \ + libwebp-dev \ + libzip-dev \ + libzstd-dev; \ + \ + docker-php-ext-configure gd --with-freetype --with-webp --with-jpeg --with-avif; \ + docker-php-ext-install -j"$(nproc)" \ + gd \ + calendar \ + intl \ + pdo_mysql \ + pdo_pgsql \ + zip \ + exif \ + pcntl \ + sockets; \ + \ + # redis with LZ4 and Zstd compression support + pecl-install --configureoptions 'enable-redis-lz4="yes" with-liblz4="yes" enable-redis-zstd="yes"' redis; \ + pecl-install imagick; \ + # maxminddb: offline IP -> country lookups. The C decoder is roughly 100x + # faster than maxmind-db/reader's pure-PHP fallback (~1.7us vs ~160us per + # lookup), which matters when a lookup happens on every request. + pecl-install maxminddb; \ + docker-php-ext-enable redis imagick maxminddb; \ + \ + docker-php-source delete; \ + rm -rf /tmp/pear ~/.pearrc; \ + \ + apt-mark auto '.*' > /dev/null; \ + [ -z "$savedAptMark" ] || apt-mark manual $savedAptMark > /dev/null; \ + find /usr/local -type f -executable -exec ldd '{}' ';' \ + | awk '/=>/ { so = $(NF-1); if (index(so, "/usr/local/") == 1) { next }; gsub("^/(usr/)?", "", so); printf "*%s\n", so }' \ + | sort -u \ + | xargs -r dpkg-query --search \ + | cut -d: -f1 \ + | sort -u \ + | xargs -r apt-mark manual; \ + apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \ + rm -rf /var/lib/apt/lists/*; \ + \ + # Fail the build here, not at runtime, if the purge took a library an + # extension needs: a missing .so makes PHP warn on startup. + out="$(php -v 2>&1)"; \ + echo "$out"; \ + case "$out" in *Warning*|*"nable to load"*) exit 1 ;; esac; \ + for ext in gd calendar intl pdo_mysql pdo_pgsql zip exif pcntl sockets redis imagick maxminddb; do \ + php -r "exit(extension_loaded('$ext') ? 0 : 1);" || { echo "extension $ext failed to load" >&2; exit 1; }; \ + done + +RUN printf "log_errors = On \nerror_log = /dev/stderr\n" > /usr/local/etc/php/conf.d/php-logs.ini # GeoIP databases (DB-IP Country, City and ASN Lite, CC BY 4.0). # diff --git a/fpm/8.3/Dockerfile.cli b/fpm/8.3/Dockerfile.cli index 70a596d..8801d17 100644 --- a/fpm/8.3/Dockerfile.cli +++ b/fpm/8.3/Dockerfile.cli @@ -2,87 +2,137 @@ FROM php:8.3-cli ENV DEBIAN_FRONTEND=noninteractive -# Setup Debian packages -RUN apt-get -y update && apt-get -y upgrade && ACCEPT_EULA=Y && apt-get install -y \ +# Runtime packages. --no-install-recommends keeps Debian from pulling in an +# MTA (exim4), dbus, systemd extras and docs; recommends that do real work are +# named explicitly instead: +# less, openssh-client git's pager, and git/composer over SSH +# psmisc, xxd killall/fuser/pstree, hex dumps +# fonts-droid-fallback Ghostscript's CJK fallback font +# libmagickcore-*-extra ImageMagick SVG, DjVu, OpenEXR and WMF coders +# libjxr-tools ImageMagick's JPEG XR delegate +# libheif-plugin-*enc HEIC and AVIF encoding through ImageMagick +# libdbd-mariadb-perl, the perl tools in mariadb-client (mytop, +# libterm-readkey-perl innotop, mariadb-hotcopy, ...) +# +# Headers, static libraries and other -dev packages are not installed here: +# they only exist inside the extension build layer below. +RUN apt-get -y update && apt-get -y upgrade && apt-get install -y --no-install-recommends \ procps \ cron \ unzip \ - libfreetype6-dev \ - libjpeg62-turbo-dev \ - libzip-dev \ - libxml2-dev \ - libxslt-dev \ - libssl-dev \ - zlib1g-dev \ - libpng-dev \ - libwebp-dev \ - libjpeg-dev \ - libonig-dev \ - libicu-dev \ + zip \ apt-file \ wget \ gnupg \ gnupg2 \ - zip \ git \ + less \ + openssh-client \ curl \ - gcc \ - g++ \ - autoconf \ - libc-dev \ - pkg-config \ iputils-ping \ netcat-openbsd \ default-mysql-client \ + libdbd-mariadb-perl \ + libterm-readkey-perl \ util-linux \ + psmisc \ gosu \ jq \ redis-tools \ vim \ + xxd \ python3 \ - liblz4-dev \ - libzstd-dev \ - libpq-dev \ - libmagickwand-dev \ imagemagick \ + libmagickcore-7.q16-10-extra \ + libjxr-tools \ + libheif-plugin-aomenc \ + libheif-plugin-x265 \ ghostscript \ - libavif-dev \ - libmaxminddb0 \ - libmaxminddb-dev && \ - apt-get clean && \ + fonts-droid-fallback \ + libmaxminddb0 && \ rm -rf /var/lib/apt/lists/* -# PHP extensions, separated for QEMU build purposes -RUN docker-php-ext-configure gd --with-freetype --with-webp --with-jpeg --with-avif -RUN docker-php-ext-install gd -RUN docker-php-ext-install calendar -RUN docker-php-ext-install intl -RUN docker-php-ext-install pdo_mysql -RUN docker-php-ext-install pdo_pgsql -RUN docker-php-ext-install xml -RUN docker-php-ext-install zip -RUN docker-php-ext-install exif -RUN docker-php-ext-install pcntl -RUN docker-php-ext-install sockets -RUN printf "log_errors = On \nerror_log = /dev/stderr\n" > /usr/local/etc/php/conf.d/php-logs.ini - # pecl.php.net fails under load; pecl-install retries with backoff. COPY bin/pecl-install /usr/local/bin/pecl-install RUN chmod +x /usr/local/bin/pecl-install -# Install redis extension with LZ4 and Zstd compression support -RUN pecl-install --configureoptions 'enable-redis-lz4="yes" with-liblz4="yes" enable-redis-zstd="yes"' redis \ - && docker-php-ext-enable redis - -# Install imagick extension -RUN pecl-install imagick && docker-php-ext-enable imagick - -# Install maxminddb extension for offline IP -> country lookups. +# PHP extensions, built in one layer so the build leaves nothing behind. +# +# The -dev packages, the extracted PHP source and pear's download cache are all +# installed, used and removed inside this RUN. Removing them in a later layer +# would not shrink the image: the files would still ship in the earlier layer. +# +# After the build, every package is marked auto except those that were already +# manual (the runtime packages above and the base image's) and those providing +# a shared library something under /usr/local links against, so the purge keeps +# exactly the runtime libraries the extensions need (libzip, libicu, libpq, +# libavif, libMagickWand, liblz4, libzstd, libmaxminddb, ...). This is the same +# technique the official php images use for their own build dependencies. # -# The C decoder is roughly 100x faster than maxmind-db/reader's pure-PHP -# fallback (~1.7us vs ~160us per lookup), which matters when a lookup happens -# on every request. Requires libmaxminddb0 at runtime -- do not purge it. -RUN pecl-install maxminddb && docker-php-ext-enable maxminddb +# xml is not built: it is compiled into the official php image already. +RUN set -eux; \ + savedAptMark="$(apt-mark showmanual)"; \ + apt-get update; \ + apt-get install -y --no-install-recommends \ + libavif-dev \ + libfreetype-dev \ + libicu-dev \ + libjpeg62-turbo-dev \ + liblz4-dev \ + libmagickwand-dev \ + libmaxminddb-dev \ + libpng-dev \ + libpq-dev \ + libwebp-dev \ + libzip-dev \ + libzstd-dev; \ + \ + docker-php-ext-configure gd --with-freetype --with-webp --with-jpeg --with-avif; \ + docker-php-ext-install -j"$(nproc)" \ + gd \ + calendar \ + intl \ + pdo_mysql \ + pdo_pgsql \ + zip \ + exif \ + pcntl \ + sockets; \ + \ + # redis with LZ4 and Zstd compression support + pecl-install --configureoptions 'enable-redis-lz4="yes" with-liblz4="yes" enable-redis-zstd="yes"' redis; \ + pecl-install imagick; \ + # maxminddb: offline IP -> country lookups. The C decoder is roughly 100x + # faster than maxmind-db/reader's pure-PHP fallback (~1.7us vs ~160us per + # lookup), which matters when a lookup happens on every request. + pecl-install maxminddb; \ + docker-php-ext-enable redis imagick maxminddb; \ + \ + docker-php-source delete; \ + rm -rf /tmp/pear ~/.pearrc; \ + \ + apt-mark auto '.*' > /dev/null; \ + [ -z "$savedAptMark" ] || apt-mark manual $savedAptMark > /dev/null; \ + find /usr/local -type f -executable -exec ldd '{}' ';' \ + | awk '/=>/ { so = $(NF-1); if (index(so, "/usr/local/") == 1) { next }; gsub("^/(usr/)?", "", so); printf "*%s\n", so }' \ + | sort -u \ + | xargs -r dpkg-query --search \ + | cut -d: -f1 \ + | sort -u \ + | xargs -r apt-mark manual; \ + apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \ + rm -rf /var/lib/apt/lists/*; \ + \ + # Fail the build here, not at runtime, if the purge took a library an + # extension needs: a missing .so makes PHP warn on startup. + out="$(php -v 2>&1)"; \ + echo "$out"; \ + case "$out" in *Warning*|*"nable to load"*) exit 1 ;; esac; \ + for ext in gd calendar intl pdo_mysql pdo_pgsql zip exif pcntl sockets redis imagick maxminddb; do \ + php -r "exit(extension_loaded('$ext') ? 0 : 1);" || { echo "extension $ext failed to load" >&2; exit 1; }; \ + done + +RUN printf "log_errors = On \nerror_log = /dev/stderr\n" > /usr/local/etc/php/conf.d/php-logs.ini # GeoIP databases (DB-IP Country, City and ASN Lite, CC BY 4.0). # diff --git a/fpm/8.3/README.md b/fpm/8.3/README.md index dd13e1a..78b62e7 100644 --- a/fpm/8.3/README.md +++ b/fpm/8.3/README.md @@ -20,6 +20,28 @@ The measurements and reasoning behind the OPcache, JIT, pool and `mpm_event` val --- +### Extending these images + +The images ship runtime libraries only. The `-dev` packages (headers and static +libraries) used to compile the bundled extensions are installed and purged in +the same build step, so they never reach the image. The compiler toolchain +from the official `php:8.3-fpm` base (`gcc`, `make`, `autoconf`, ...) is still +present, so `pecl install` works for extensions with no library dependencies +(the `dev` tags build Xdebug this way). + +An image built on top that compiles an extension against a system library must +install that library's `-dev` package itself, for example: + +```dockerfile +FROM ianmgg/php83fpm:latest +RUN apt-get update \ + && apt-get install -y --no-install-recommends libxslt1-dev \ + && docker-php-ext-install xsl \ + && rm -rf /var/lib/apt/lists/* +``` + +--- + ### Building locally All commands are run from the **repository root** (the build context must be the repo root so `COPY fpm/8.3/...` paths resolve correctly). diff --git a/fpm/8.5/Dockerfile.apache b/fpm/8.5/Dockerfile.apache index 7d4a391..54ae540 100644 --- a/fpm/8.5/Dockerfile.apache +++ b/fpm/8.5/Dockerfile.apache @@ -2,93 +2,143 @@ FROM php:8.5-fpm ENV DEBIAN_FRONTEND=noninteractive -# Setup Debian packages -RUN apt-get -y update && apt-get -y upgrade && ACCEPT_EULA=Y && apt-get install -y \ +# Runtime packages. --no-install-recommends keeps Debian from pulling in an +# MTA (exim4), dbus, systemd extras and docs; recommends that do real work are +# named explicitly instead: +# less, openssh-client git's pager, and git/composer over SSH +# psmisc, xxd killall/fuser/pstree, hex dumps +# fonts-droid-fallback Ghostscript's CJK fallback font +# libmagickcore-*-extra ImageMagick SVG, DjVu, OpenEXR and WMF coders +# libjxr-tools ImageMagick's JPEG XR delegate +# libheif-plugin-*enc HEIC and AVIF encoding through ImageMagick +# libdbd-mariadb-perl, the perl tools in mariadb-client (mytop, +# libterm-readkey-perl innotop, mariadb-hotcopy, ...) +# +# Headers, static libraries and other -dev packages are not installed here: +# they only exist inside the extension build layer below. +RUN apt-get -y update && apt-get -y upgrade && apt-get install -y --no-install-recommends \ apache2 \ procps \ cron \ unzip \ - libfreetype6-dev \ - libjpeg62-turbo-dev \ - libzip-dev \ - libxml2-dev \ - libxslt-dev \ - libssl-dev \ - zlib1g-dev \ - libpng-dev \ - libwebp-dev \ - libjpeg-dev \ - libonig-dev \ - libicu-dev \ + zip \ apt-file \ wget \ gnupg \ gnupg2 \ - zip \ git \ + less \ + openssh-client \ curl \ - gcc \ - g++ \ - autoconf \ - libc-dev \ - pkg-config \ iputils-ping \ netcat-openbsd \ default-mysql-client \ + libdbd-mariadb-perl \ + libterm-readkey-perl \ util-linux \ + psmisc \ gosu \ jq \ redis-tools \ vim \ + xxd \ python3 \ - liblz4-dev \ - libzstd-dev \ - libpq-dev \ - libmagickwand-dev \ imagemagick \ + libmagickcore-7.q16-10-extra \ + libjxr-tools \ + libheif-plugin-aomenc \ + libheif-plugin-x265 \ ghostscript \ - libavif-dev \ - libmaxminddb0 \ - libmaxminddb-dev && \ - apt-get clean && \ + fonts-droid-fallback \ + libmaxminddb0 && \ rm -rf /var/lib/apt/lists/* -# PHP extensions, separated for QEMU build purposes -RUN docker-php-ext-configure gd --with-freetype --with-webp --with-jpeg --with-avif -RUN docker-php-ext-install gd -RUN docker-php-ext-install calendar -RUN docker-php-ext-install intl -RUN docker-php-ext-install pdo_mysql -RUN docker-php-ext-install pdo_pgsql -RUN docker-php-ext-install xml -RUN docker-php-ext-install zip -RUN docker-php-ext-install exif -RUN docker-php-ext-install pcntl -RUN docker-php-ext-install sockets -RUN printf "log_errors = On \nerror_log = /dev/stderr\n" > /usr/local/etc/php/conf.d/php-logs.ini - # pecl.php.net fails under load; pecl-install retries with backoff. COPY bin/pecl-install /usr/local/bin/pecl-install RUN chmod +x /usr/local/bin/pecl-install -# Install redis extension with LZ4 and Zstd compression support -RUN pecl-install --configureoptions 'enable-redis-lz4="yes" with-liblz4="yes" enable-redis-zstd="yes"' redis \ - && docker-php-ext-enable redis - -# Install imagick extension -RUN pecl-install imagick && docker-php-ext-enable imagick - -# Install maxminddb extension for offline IP -> country lookups. +# PHP extensions, built in one layer so the build leaves nothing behind. +# +# The -dev packages, the extracted PHP source and pear's download cache are all +# installed, used and removed inside this RUN. Removing them in a later layer +# would not shrink the image: the files would still ship in the earlier layer. +# +# After the build, every package is marked auto except those that were already +# manual (the runtime packages above and the base image's) and those providing +# a shared library something under /usr/local links against, so the purge keeps +# exactly the runtime libraries the extensions need (libzip, libicu, libpq, +# libavif, libMagickWand, liblz4, libzstd, libmaxminddb, ...). This is the same +# technique the official php images use for their own build dependencies. # -# The C decoder is roughly 100x faster than maxmind-db/reader's pure-PHP -# fallback (~1.7us vs ~160us per lookup), which matters when a lookup happens -# on every request. Requires libmaxminddb0 at runtime -- do not purge it. -RUN pecl-install maxminddb && docker-php-ext-enable maxminddb - -# Install excimer, Wikimedia's low-overhead sampling profiler. Sentry's PHP SDK -# uses it for profiling (fof/sentry's profiling sample rate). It costs nothing -# until a profiler is started, so loading it on every request is harmless. -RUN pecl-install excimer && docker-php-ext-enable excimer +# xml is not built: it is compiled into the official php image already. +RUN set -eux; \ + savedAptMark="$(apt-mark showmanual)"; \ + apt-get update; \ + apt-get install -y --no-install-recommends \ + libavif-dev \ + libfreetype-dev \ + libicu-dev \ + libjpeg62-turbo-dev \ + liblz4-dev \ + libmagickwand-dev \ + libmaxminddb-dev \ + libpng-dev \ + libpq-dev \ + libwebp-dev \ + libzip-dev \ + libzstd-dev; \ + \ + docker-php-ext-configure gd --with-freetype --with-webp --with-jpeg --with-avif; \ + docker-php-ext-install -j"$(nproc)" \ + gd \ + calendar \ + intl \ + pdo_mysql \ + pdo_pgsql \ + zip \ + exif \ + pcntl \ + sockets; \ + \ + # redis with LZ4 and Zstd compression support + pecl-install --configureoptions 'enable-redis-lz4="yes" with-liblz4="yes" enable-redis-zstd="yes"' redis; \ + pecl-install imagick; \ + # maxminddb: offline IP -> country lookups. The C decoder is roughly 100x + # faster than maxmind-db/reader's pure-PHP fallback (~1.7us vs ~160us per + # lookup), which matters when a lookup happens on every request. + pecl-install maxminddb; \ + \ + # excimer: Wikimedia's low-overhead sampling profiler. Sentry's PHP SDK + # uses it for profiling (fof/sentry's profiling sample rate). It costs + # nothing until a profiler is started. + pecl-install excimer; \ + docker-php-ext-enable redis imagick maxminddb excimer; \ + \ + docker-php-source delete; \ + rm -rf /tmp/pear ~/.pearrc; \ + \ + apt-mark auto '.*' > /dev/null; \ + [ -z "$savedAptMark" ] || apt-mark manual $savedAptMark > /dev/null; \ + find /usr/local -type f -executable -exec ldd '{}' ';' \ + | awk '/=>/ { so = $(NF-1); if (index(so, "/usr/local/") == 1) { next }; gsub("^/(usr/)?", "", so); printf "*%s\n", so }' \ + | sort -u \ + | xargs -r dpkg-query --search \ + | cut -d: -f1 \ + | sort -u \ + | xargs -r apt-mark manual; \ + apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \ + rm -rf /var/lib/apt/lists/*; \ + \ + # Fail the build here, not at runtime, if the purge took a library an + # extension needs: a missing .so makes PHP warn on startup. + out="$(php -v 2>&1)"; \ + echo "$out"; \ + case "$out" in *Warning*|*"nable to load"*) exit 1 ;; esac; \ + for ext in gd calendar intl pdo_mysql pdo_pgsql zip exif pcntl sockets redis imagick maxminddb excimer; do \ + php -r "exit(extension_loaded('$ext') ? 0 : 1);" || { echo "extension $ext failed to load" >&2; exit 1; }; \ + done + +RUN printf "log_errors = On \nerror_log = /dev/stderr\n" > /usr/local/etc/php/conf.d/php-logs.ini # GeoIP databases (DB-IP Country, City and ASN Lite, CC BY 4.0). # diff --git a/fpm/8.5/Dockerfile.cli b/fpm/8.5/Dockerfile.cli index 0741538..578f295 100644 --- a/fpm/8.5/Dockerfile.cli +++ b/fpm/8.5/Dockerfile.cli @@ -2,92 +2,142 @@ FROM php:8.5-cli ENV DEBIAN_FRONTEND=noninteractive -# Setup Debian packages -RUN apt-get -y update && apt-get -y upgrade && ACCEPT_EULA=Y && apt-get install -y \ +# Runtime packages. --no-install-recommends keeps Debian from pulling in an +# MTA (exim4), dbus, systemd extras and docs; recommends that do real work are +# named explicitly instead: +# less, openssh-client git's pager, and git/composer over SSH +# psmisc, xxd killall/fuser/pstree, hex dumps +# fonts-droid-fallback Ghostscript's CJK fallback font +# libmagickcore-*-extra ImageMagick SVG, DjVu, OpenEXR and WMF coders +# libjxr-tools ImageMagick's JPEG XR delegate +# libheif-plugin-*enc HEIC and AVIF encoding through ImageMagick +# libdbd-mariadb-perl, the perl tools in mariadb-client (mytop, +# libterm-readkey-perl innotop, mariadb-hotcopy, ...) +# +# Headers, static libraries and other -dev packages are not installed here: +# they only exist inside the extension build layer below. +RUN apt-get -y update && apt-get -y upgrade && apt-get install -y --no-install-recommends \ procps \ cron \ unzip \ - libfreetype6-dev \ - libjpeg62-turbo-dev \ - libzip-dev \ - libxml2-dev \ - libxslt-dev \ - libssl-dev \ - zlib1g-dev \ - libpng-dev \ - libwebp-dev \ - libjpeg-dev \ - libonig-dev \ - libicu-dev \ + zip \ apt-file \ wget \ gnupg \ gnupg2 \ - zip \ git \ + less \ + openssh-client \ curl \ - gcc \ - g++ \ - autoconf \ - libc-dev \ - pkg-config \ iputils-ping \ netcat-openbsd \ default-mysql-client \ + libdbd-mariadb-perl \ + libterm-readkey-perl \ util-linux \ + psmisc \ gosu \ jq \ redis-tools \ vim \ + xxd \ python3 \ - liblz4-dev \ - libzstd-dev \ - libpq-dev \ - libmagickwand-dev \ imagemagick \ + libmagickcore-7.q16-10-extra \ + libjxr-tools \ + libheif-plugin-aomenc \ + libheif-plugin-x265 \ ghostscript \ - libavif-dev \ - libmaxminddb0 \ - libmaxminddb-dev && \ - apt-get clean && \ + fonts-droid-fallback \ + libmaxminddb0 && \ rm -rf /var/lib/apt/lists/* -# PHP extensions, separated for QEMU build purposes -RUN docker-php-ext-configure gd --with-freetype --with-webp --with-jpeg --with-avif -RUN docker-php-ext-install gd -RUN docker-php-ext-install calendar -RUN docker-php-ext-install intl -RUN docker-php-ext-install pdo_mysql -RUN docker-php-ext-install pdo_pgsql -RUN docker-php-ext-install xml -RUN docker-php-ext-install zip -RUN docker-php-ext-install exif -RUN docker-php-ext-install pcntl -RUN docker-php-ext-install sockets -RUN printf "log_errors = On \nerror_log = /dev/stderr\n" > /usr/local/etc/php/conf.d/php-logs.ini - # pecl.php.net fails under load; pecl-install retries with backoff. COPY bin/pecl-install /usr/local/bin/pecl-install RUN chmod +x /usr/local/bin/pecl-install -# Install redis extension with LZ4 and Zstd compression support -RUN pecl-install --configureoptions 'enable-redis-lz4="yes" with-liblz4="yes" enable-redis-zstd="yes"' redis \ - && docker-php-ext-enable redis - -# Install imagick extension -RUN pecl-install imagick && docker-php-ext-enable imagick - -# Install maxminddb extension for offline IP -> country lookups. +# PHP extensions, built in one layer so the build leaves nothing behind. +# +# The -dev packages, the extracted PHP source and pear's download cache are all +# installed, used and removed inside this RUN. Removing them in a later layer +# would not shrink the image: the files would still ship in the earlier layer. # -# The C decoder is roughly 100x faster than maxmind-db/reader's pure-PHP -# fallback (~1.7us vs ~160us per lookup), which matters when a lookup happens -# on every request. Requires libmaxminddb0 at runtime -- do not purge it. -RUN pecl-install maxminddb && docker-php-ext-enable maxminddb +# After the build, every package is marked auto except those that were already +# manual (the runtime packages above and the base image's) and those providing +# a shared library something under /usr/local links against, so the purge keeps +# exactly the runtime libraries the extensions need (libzip, libicu, libpq, +# libavif, libMagickWand, liblz4, libzstd, libmaxminddb, ...). This is the same +# technique the official php images use for their own build dependencies. +# +# xml is not built: it is compiled into the official php image already. +RUN set -eux; \ + savedAptMark="$(apt-mark showmanual)"; \ + apt-get update; \ + apt-get install -y --no-install-recommends \ + libavif-dev \ + libfreetype-dev \ + libicu-dev \ + libjpeg62-turbo-dev \ + liblz4-dev \ + libmagickwand-dev \ + libmaxminddb-dev \ + libpng-dev \ + libpq-dev \ + libwebp-dev \ + libzip-dev \ + libzstd-dev; \ + \ + docker-php-ext-configure gd --with-freetype --with-webp --with-jpeg --with-avif; \ + docker-php-ext-install -j"$(nproc)" \ + gd \ + calendar \ + intl \ + pdo_mysql \ + pdo_pgsql \ + zip \ + exif \ + pcntl \ + sockets; \ + \ + # redis with LZ4 and Zstd compression support + pecl-install --configureoptions 'enable-redis-lz4="yes" with-liblz4="yes" enable-redis-zstd="yes"' redis; \ + pecl-install imagick; \ + # maxminddb: offline IP -> country lookups. The C decoder is roughly 100x + # faster than maxmind-db/reader's pure-PHP fallback (~1.7us vs ~160us per + # lookup), which matters when a lookup happens on every request. + pecl-install maxminddb; \ + \ + # excimer: Wikimedia's low-overhead sampling profiler. Sentry's PHP SDK + # uses it for profiling (fof/sentry's profiling sample rate). It costs + # nothing until a profiler is started. + pecl-install excimer; \ + docker-php-ext-enable redis imagick maxminddb excimer; \ + \ + docker-php-source delete; \ + rm -rf /tmp/pear ~/.pearrc; \ + \ + apt-mark auto '.*' > /dev/null; \ + [ -z "$savedAptMark" ] || apt-mark manual $savedAptMark > /dev/null; \ + find /usr/local -type f -executable -exec ldd '{}' ';' \ + | awk '/=>/ { so = $(NF-1); if (index(so, "/usr/local/") == 1) { next }; gsub("^/(usr/)?", "", so); printf "*%s\n", so }' \ + | sort -u \ + | xargs -r dpkg-query --search \ + | cut -d: -f1 \ + | sort -u \ + | xargs -r apt-mark manual; \ + apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \ + rm -rf /var/lib/apt/lists/*; \ + \ + # Fail the build here, not at runtime, if the purge took a library an + # extension needs: a missing .so makes PHP warn on startup. + out="$(php -v 2>&1)"; \ + echo "$out"; \ + case "$out" in *Warning*|*"nable to load"*) exit 1 ;; esac; \ + for ext in gd calendar intl pdo_mysql pdo_pgsql zip exif pcntl sockets redis imagick maxminddb excimer; do \ + php -r "exit(extension_loaded('$ext') ? 0 : 1);" || { echo "extension $ext failed to load" >&2; exit 1; }; \ + done -# Install excimer, Wikimedia's low-overhead sampling profiler. Sentry's PHP SDK -# uses it for profiling (fof/sentry's profiling sample rate). It costs nothing -# until a profiler is started, so loading it on every request is harmless. -RUN pecl-install excimer && docker-php-ext-enable excimer +RUN printf "log_errors = On \nerror_log = /dev/stderr\n" > /usr/local/etc/php/conf.d/php-logs.ini # GeoIP databases (DB-IP Country, City and ASN Lite, CC BY 4.0). # diff --git a/fpm/8.5/README.md b/fpm/8.5/README.md index c54547f..ade0aa1 100644 --- a/fpm/8.5/README.md +++ b/fpm/8.5/README.md @@ -20,6 +20,28 @@ The measurements and reasoning behind the OPcache, JIT, pool and `mpm_event` val --- +### Extending these images + +The images ship runtime libraries only. The `-dev` packages (headers and static +libraries) used to compile the bundled extensions are installed and purged in +the same build step, so they never reach the image. The compiler toolchain +from the official `php:8.5-fpm` base (`gcc`, `make`, `autoconf`, ...) is still +present, so `pecl install` works for extensions with no library dependencies +(the `dev` tags build Xdebug this way). + +An image built on top that compiles an extension against a system library must +install that library's `-dev` package itself, for example: + +```dockerfile +FROM ianmgg/php85fpm:latest +RUN apt-get update \ + && apt-get install -y --no-install-recommends libxslt1-dev \ + && docker-php-ext-install xsl \ + && rm -rf /var/lib/apt/lists/* +``` + +--- + ### Building locally All commands are run from the **repository root** (the build context must be the repo root so `COPY fpm/8.5/...` paths resolve correctly). From ec4cfa2ff1c610ca421ccba6b0796ec9c830a7af Mon Sep 17 00:00:00 2001 From: IanM Date: Sat, 31 Oct 2026 10:07:58 +0000 Subject: [PATCH 2/7] ci: build and smoke-test FPM images on pull requests The FPM workflow only builds on master and pushes straight to the published tags, so a broken Dockerfile was only found after merge. Add a pull-request workflow that builds all four FPM images per version and arch without pushing, checks extensions, tools and Apache -> FPM, and reports sizes against the published tags in the job summary. Also rebuild the FPM images when bin/ changes: pecl-install and fetch-geoip-db are copied into them. --- .github/workflows/docker-image-fpm-check.yml | 146 +++++++++++++++++++ .github/workflows/docker-image-fpm.yml | 2 + 2 files changed, 148 insertions(+) create mode 100644 .github/workflows/docker-image-fpm-check.yml diff --git a/.github/workflows/docker-image-fpm-check.yml b/.github/workflows/docker-image-fpm-check.yml new file mode 100644 index 0000000..a61a71a --- /dev/null +++ b/.github/workflows/docker-image-fpm-check.yml @@ -0,0 +1,146 @@ +name: Docker Image Check - FPM + +# Builds and smoke-tests the FPM images for a pull request, without pushing. +# +# docker-image-fpm.yml only builds on master and pushes straight to the +# published tags, so without this a Dockerfile that fails to build -- or builds +# but cannot load an extension -- is only found after merge, by which point +# the arch tags may already be overwritten. +on: + pull_request: + paths: + - 'fpm/**' + # pecl-install and fetch-geoip-db are copied into the FPM images + - 'bin/**' + - '.github/workflows/docker-image-fpm.yml' + - '.github/workflows/docker-image-fpm-check.yml' + workflow_dispatch: + +permissions: + contents: read + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + check: + runs-on: ${{ matrix.runner }} + strategy: + fail-fast: false + matrix: + version: ['8.3', '8.5'] + arch: [amd64, arm64] + include: + - arch: amd64 + runner: ubuntu-latest + - arch: arm64 + runner: ubuntu-24.04-arm + - version: '8.3' + image: php83fpm + - version: '8.5' + image: php85fpm + env: + IMAGE: ianmgg/${{ matrix.image }} + steps: + - uses: actions/checkout@v4 + + # The engine's own builder (no setup-buildx) keeps results in the local + # image store, so the dev Dockerfiles' `FROM ianmgg/:latest` and + # `:cli` resolve to the images just built here, not the published ones. + - name: Build apache + run: docker build --progress=plain -f fpm/${{ matrix.version }}/Dockerfile.apache -t "$IMAGE:latest" . + - name: Build cli + run: docker build --progress=plain -f fpm/${{ matrix.version }}/Dockerfile.cli -t "$IMAGE:cli" . + - name: Build dev + run: docker build --progress=plain -f fpm/${{ matrix.version }}/Dockerfile.apache.dev -t "$IMAGE:dev" . + - name: Build cli-dev + run: docker build --progress=plain -f fpm/${{ matrix.version }}/Dockerfile.cli.dev -t "$IMAGE:cli-dev" . + + - name: Extensions load cleanly + run: | + exts="gd calendar intl pdo_mysql pdo_pgsql pdo_sqlite zip exif pcntl sockets redis imagick maxminddb Zend_OPcache" + [ "${{ matrix.version }}" = "8.5" ] && exts="$exts excimer" + status=0 + for tag in latest cli dev cli-dev; do + want="$exts" + case "$tag" in *dev) want="$want xdebug" ;; esac + # A missing shared library makes PHP print a startup warning, which + # would otherwise only show up in a production log. + out="$(docker run --rm "$IMAGE:$tag" php -m 2>&1)" + if printf '%s\n' "$out" | grep -qiE 'warning|unable to load'; then + echo "FAIL $tag: PHP startup warning"; printf '%s\n' "$out"; status=1 + fi + for ext in $want; do + name="${ext/Zend_OPcache/Zend OPcache}" + if printf '%s\n' "$out" | grep -qxF "$name"; then + echo "PASS $tag: $name" + else + echo "FAIL $tag: $name not loaded"; status=1 + fi + done + done + exit $status + + - name: Tools are present + run: | + status=0 + tools="aws composer git ssh less mariadb mariadb-dump mytop convert magick gs jq vim xxd redis-cli python3 crontab gosu curl wget nc ping unzip zip killall" + for tag in latest cli; do + for t in $tools; do + if docker run --rm "$IMAGE:$tag" sh -c "command -v $t" >/dev/null; then + echo "PASS $tag: $t" + else + echo "FAIL $tag: $t missing"; status=1 + fi + done + done + # ImageMagick coders and delegates the images promise + for fmt in AVIF HEIC WEBP SVG PDF; do + if docker run --rm "$IMAGE:latest" sh -c "magick -list format | grep -qE '^ *$fmt\*? '"; then + echo "PASS ImageMagick format: $fmt" + else + echo "FAIL ImageMagick format: $fmt"; status=1 + fi + done + # mytop is a perl script; it needs DBI and the MariaDB driver + if docker run --rm "$IMAGE:latest" perl -MDBI -MDBD::MariaDB -e1; then + echo "PASS perl DBD::MariaDB" + else + echo "FAIL perl DBD::MariaDB"; status=1 + fi + exit $status + + - name: Apache serves PHP through FPM + run: | + docker run -d --name web -p 8080:8080 "$IMAGE:latest" + for i in $(seq 1 30); do + if curl -fsS http://127.0.0.1:8080/ -o page.html 2>/dev/null; then break; fi + sleep 1 + done + if grep -q "PHP Version" page.html 2>/dev/null; then + echo "PASS apache -> php-fpm" + else + echo "FAIL apache -> php-fpm"; docker logs web; exit 1 + fi + + - name: Size against published images + if: always() + run: | + { + echo "### ${IMAGE} (${{ matrix.arch }})" + echo + echo "| Tag | Published | This PR |" + echo "|-----|-----------|---------|" + } >> "$GITHUB_STEP_SUMMARY" + for tag in latest cli dev cli-dev; do + # Uncompressed size in the local image store, so both columns are + # measured the same way. + new="$(docker image inspect -f '{{.Size}}' "$IMAGE:$tag" 2>/dev/null || echo 0)" + old=0 + if docker pull -q --platform "linux/${{ matrix.arch }}" "$IMAGE:$tag-${{ matrix.arch }}" >/dev/null 2>&1; then + old="$(docker image inspect -f '{{.Size}}' "$IMAGE:$tag-${{ matrix.arch }}")" + docker rmi "$IMAGE:$tag-${{ matrix.arch }}" >/dev/null + fi + echo "| \`$tag\` | $((old / 1048576)) MB | $((new / 1048576)) MB |" >> "$GITHUB_STEP_SUMMARY" + done diff --git a/.github/workflows/docker-image-fpm.yml b/.github/workflows/docker-image-fpm.yml index 4c12a05..7b92f0c 100644 --- a/.github/workflows/docker-image-fpm.yml +++ b/.github/workflows/docker-image-fpm.yml @@ -7,6 +7,8 @@ on: branches: [master] paths: - 'fpm/**' + # pecl-install and fetch-geoip-db are copied into the FPM images + - 'bin/**' - '.github/workflows/docker-image-fpm.yml' schedule: # 02:00 UTC on the 1st and 15th of each month, to pull in upstream PHP From fad22fcfe8a01d132f6418d117a9619440532402 Mon Sep 17 00:00:00 2001 From: IanM Date: Sat, 31 Oct 2026 10:10:39 +0000 Subject: [PATCH 3/7] ci: serialise FPM publishes and scope the workflow token Overlapping runs (push during the scheduled rebuild, a dispatch) raced on the arch tags, and the merge jobs could build :latest from arch images of different runs. Queue runs in one concurrency group without cancelling, since a run cancelled mid-push leaves the arch tags out of step. The token is only used for checkout, so limit it to contents: read. --- .github/workflows/docker-image-fpm.yml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/.github/workflows/docker-image-fpm.yml b/.github/workflows/docker-image-fpm.yml index 7b92f0c..63e3f42 100644 --- a/.github/workflows/docker-image-fpm.yml +++ b/.github/workflows/docker-image-fpm.yml @@ -19,6 +19,19 @@ on: repository_dispatch: types: [build-docker-fpm] +# Checkout is all the token is used for; Docker Hub auth comes from secrets. +permissions: + contents: read + +# One publish at a time. Overlapping runs (a push landing during the scheduled +# rebuild, say) would race on the arch tags, and the merge jobs could stitch +# :latest together from images built by different runs. Queue rather than +# cancel: a run cancelled mid-push leaves arch tags out of step with :latest. +# GitHub keeps only the newest queued run, which builds the newest master. +concurrency: + group: ${{ github.workflow }} + cancel-in-progress: false + jobs: # Build apache and cli images on native runners for each arch build_apache: From c0e34f714123a1eec35081fbde27b03d799e6490 Mon Sep 17 00:00:00 2001 From: IanM Date: Sat, 31 Oct 2026 10:48:20 +0000 Subject: [PATCH 4/7] fix: parse dpkg-query --search output strictly when keeping runtime libs dpkg-query --search also prints "diversion by X from/to: " lines. They reached apt-mark as package names ("diversion", "by", ...), which failed the build with exit 123 on every arch and version. Drop them, and split "pkg-a:arch, pkg-b: " lines so every owning package is kept. --- fpm/8.3/Dockerfile.apache | 10 ++++++++-- fpm/8.3/Dockerfile.cli | 10 ++++++++-- fpm/8.5/Dockerfile.apache | 10 ++++++++-- fpm/8.5/Dockerfile.cli | 10 ++++++++-- 4 files changed, 32 insertions(+), 8 deletions(-) diff --git a/fpm/8.3/Dockerfile.apache b/fpm/8.3/Dockerfile.apache index cca581f..54540fd 100644 --- a/fpm/8.3/Dockerfile.apache +++ b/fpm/8.3/Dockerfile.apache @@ -68,7 +68,10 @@ RUN chmod +x /usr/local/bin/pecl-install # a shared library something under /usr/local links against, so the purge keeps # exactly the runtime libraries the extensions need (libzip, libicu, libpq, # libavif, libMagickWand, liblz4, libzstd, libmaxminddb, ...). This is the same -# technique the official php images use for their own build dependencies. +# technique the official php images use for their own build dependencies, except +# that the dpkg-query --search output is parsed strictly: "diversion by ..." +# lines are dropped (they are not package names, and apt-mark fails on them), +# and "pkg-a:arch, pkg-b: " lines yield every owning package. # # xml is not built: it is compiled into the official php image already. RUN set -eux; \ @@ -118,7 +121,10 @@ RUN set -eux; \ | awk '/=>/ { so = $(NF-1); if (index(so, "/usr/local/") == 1) { next }; gsub("^/(usr/)?", "", so); printf "*%s\n", so }' \ | sort -u \ | xargs -r dpkg-query --search \ - | cut -d: -f1 \ + | grep -v '^diversion by ' \ + | sed -E 's/: [^ ]+$//' \ + | tr ',' '\n' \ + | sed -E 's/^ +//; s/:.*$//' \ | sort -u \ | xargs -r apt-mark manual; \ apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \ diff --git a/fpm/8.3/Dockerfile.cli b/fpm/8.3/Dockerfile.cli index 8801d17..2aecd12 100644 --- a/fpm/8.3/Dockerfile.cli +++ b/fpm/8.3/Dockerfile.cli @@ -67,7 +67,10 @@ RUN chmod +x /usr/local/bin/pecl-install # a shared library something under /usr/local links against, so the purge keeps # exactly the runtime libraries the extensions need (libzip, libicu, libpq, # libavif, libMagickWand, liblz4, libzstd, libmaxminddb, ...). This is the same -# technique the official php images use for their own build dependencies. +# technique the official php images use for their own build dependencies, except +# that the dpkg-query --search output is parsed strictly: "diversion by ..." +# lines are dropped (they are not package names, and apt-mark fails on them), +# and "pkg-a:arch, pkg-b: " lines yield every owning package. # # xml is not built: it is compiled into the official php image already. RUN set -eux; \ @@ -117,7 +120,10 @@ RUN set -eux; \ | awk '/=>/ { so = $(NF-1); if (index(so, "/usr/local/") == 1) { next }; gsub("^/(usr/)?", "", so); printf "*%s\n", so }' \ | sort -u \ | xargs -r dpkg-query --search \ - | cut -d: -f1 \ + | grep -v '^diversion by ' \ + | sed -E 's/: [^ ]+$//' \ + | tr ',' '\n' \ + | sed -E 's/^ +//; s/:.*$//' \ | sort -u \ | xargs -r apt-mark manual; \ apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \ diff --git a/fpm/8.5/Dockerfile.apache b/fpm/8.5/Dockerfile.apache index 54ae540..8ec9b0b 100644 --- a/fpm/8.5/Dockerfile.apache +++ b/fpm/8.5/Dockerfile.apache @@ -68,7 +68,10 @@ RUN chmod +x /usr/local/bin/pecl-install # a shared library something under /usr/local links against, so the purge keeps # exactly the runtime libraries the extensions need (libzip, libicu, libpq, # libavif, libMagickWand, liblz4, libzstd, libmaxminddb, ...). This is the same -# technique the official php images use for their own build dependencies. +# technique the official php images use for their own build dependencies, except +# that the dpkg-query --search output is parsed strictly: "diversion by ..." +# lines are dropped (they are not package names, and apt-mark fails on them), +# and "pkg-a:arch, pkg-b: " lines yield every owning package. # # xml is not built: it is compiled into the official php image already. RUN set -eux; \ @@ -123,7 +126,10 @@ RUN set -eux; \ | awk '/=>/ { so = $(NF-1); if (index(so, "/usr/local/") == 1) { next }; gsub("^/(usr/)?", "", so); printf "*%s\n", so }' \ | sort -u \ | xargs -r dpkg-query --search \ - | cut -d: -f1 \ + | grep -v '^diversion by ' \ + | sed -E 's/: [^ ]+$//' \ + | tr ',' '\n' \ + | sed -E 's/^ +//; s/:.*$//' \ | sort -u \ | xargs -r apt-mark manual; \ apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \ diff --git a/fpm/8.5/Dockerfile.cli b/fpm/8.5/Dockerfile.cli index 578f295..f102f86 100644 --- a/fpm/8.5/Dockerfile.cli +++ b/fpm/8.5/Dockerfile.cli @@ -67,7 +67,10 @@ RUN chmod +x /usr/local/bin/pecl-install # a shared library something under /usr/local links against, so the purge keeps # exactly the runtime libraries the extensions need (libzip, libicu, libpq, # libavif, libMagickWand, liblz4, libzstd, libmaxminddb, ...). This is the same -# technique the official php images use for their own build dependencies. +# technique the official php images use for their own build dependencies, except +# that the dpkg-query --search output is parsed strictly: "diversion by ..." +# lines are dropped (they are not package names, and apt-mark fails on them), +# and "pkg-a:arch, pkg-b: " lines yield every owning package. # # xml is not built: it is compiled into the official php image already. RUN set -eux; \ @@ -122,7 +125,10 @@ RUN set -eux; \ | awk '/=>/ { so = $(NF-1); if (index(so, "/usr/local/") == 1) { next }; gsub("^/(usr/)?", "", so); printf "*%s\n", so }' \ | sort -u \ | xargs -r dpkg-query --search \ - | cut -d: -f1 \ + | grep -v '^diversion by ' \ + | sed -E 's/: [^ ]+$//' \ + | tr ',' '\n' \ + | sed -E 's/^ +//; s/:.*$//' \ | sort -u \ | xargs -r apt-mark manual; \ apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \ From 6c13c7729a875791cb52c0f262fc0b8b12915342 Mon Sep 17 00:00:00 2001 From: IanM Date: Sat, 31 Oct 2026 10:58:25 +0000 Subject: [PATCH 5/7] ci: request index.php explicitly in the Apache -> FPM smoke test Debian's apache2 package installs /var/www/html/index.html, which DirectoryIndex serves for /, so the check never reached PHP-FPM. --- .github/workflows/docker-image-fpm-check.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/docker-image-fpm-check.yml b/.github/workflows/docker-image-fpm-check.yml index a61a71a..a59adb3 100644 --- a/.github/workflows/docker-image-fpm-check.yml +++ b/.github/workflows/docker-image-fpm-check.yml @@ -114,8 +114,10 @@ jobs: - name: Apache serves PHP through FPM run: | docker run -d --name web -p 8080:8080 "$IMAGE:latest" + # Ask for index.php by name: Debian's apache2 package also installs + # /var/www/html/index.html, which DirectoryIndex serves for /. for i in $(seq 1 30); do - if curl -fsS http://127.0.0.1:8080/ -o page.html 2>/dev/null; then break; fi + if curl -fsS http://127.0.0.1:8080/index.php -o page.html 2>/dev/null; then break; fi sleep 1 done if grep -q "PHP Version" page.html 2>/dev/null; then From 28f29ffc538231d7079b747479fedea4620759fe Mon Sep 17 00:00:00 2001 From: IanM Date: Sat, 31 Oct 2026 11:10:20 +0000 Subject: [PATCH 6/7] ci: print the FPM size comparison to the job log as well as the summary Job summaries are only visible in the web UI, not through the API or gh run view --log. --- .github/workflows/docker-image-fpm-check.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/docker-image-fpm-check.yml b/.github/workflows/docker-image-fpm-check.yml index a59adb3..581479d 100644 --- a/.github/workflows/docker-image-fpm-check.yml +++ b/.github/workflows/docker-image-fpm-check.yml @@ -129,12 +129,14 @@ jobs: - name: Size against published images if: always() run: | + # Written to the log as well as the summary: summaries are only + # visible in the web UI, not through the API or gh run view --log. { echo "### ${IMAGE} (${{ matrix.arch }})" echo echo "| Tag | Published | This PR |" echo "|-----|-----------|---------|" - } >> "$GITHUB_STEP_SUMMARY" + } | tee -a "$GITHUB_STEP_SUMMARY" for tag in latest cli dev cli-dev; do # Uncompressed size in the local image store, so both columns are # measured the same way. @@ -144,5 +146,5 @@ jobs: old="$(docker image inspect -f '{{.Size}}' "$IMAGE:$tag-${{ matrix.arch }}")" docker rmi "$IMAGE:$tag-${{ matrix.arch }}" >/dev/null fi - echo "| \`$tag\` | $((old / 1048576)) MB | $((new / 1048576)) MB |" >> "$GITHUB_STEP_SUMMARY" + echo "| \`$tag\` | $((old / 1048576)) MB | $((new / 1048576)) MB |" | tee -a "$GITHUB_STEP_SUMMARY" done From 5d53748fbaae0945e7705d3a4fccf25822419ff8 Mon Sep 17 00:00:00 2001 From: IanM Date: Sat, 31 Oct 2026 22:53:22 +0000 Subject: [PATCH 7/7] feat: include Excimer in PHP 8.3 FPM images --- .github/workflows/docker-image-fpm-check.yml | 3 +-- fpm/8.3/Dockerfile.apache | 5 +++-- fpm/8.3/Dockerfile.cli | 5 +++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/.github/workflows/docker-image-fpm-check.yml b/.github/workflows/docker-image-fpm-check.yml index 581479d..efa2621 100644 --- a/.github/workflows/docker-image-fpm-check.yml +++ b/.github/workflows/docker-image-fpm-check.yml @@ -59,8 +59,7 @@ jobs: - name: Extensions load cleanly run: | - exts="gd calendar intl pdo_mysql pdo_pgsql pdo_sqlite zip exif pcntl sockets redis imagick maxminddb Zend_OPcache" - [ "${{ matrix.version }}" = "8.5" ] && exts="$exts excimer" + exts="gd calendar intl pdo_mysql pdo_pgsql pdo_sqlite zip exif pcntl sockets redis imagick maxminddb excimer Zend_OPcache" status=0 for tag in latest cli dev cli-dev; do want="$exts" diff --git a/fpm/8.3/Dockerfile.apache b/fpm/8.3/Dockerfile.apache index 54540fd..b930e9d 100644 --- a/fpm/8.3/Dockerfile.apache +++ b/fpm/8.3/Dockerfile.apache @@ -110,7 +110,8 @@ RUN set -eux; \ # faster than maxmind-db/reader's pure-PHP fallback (~1.7us vs ~160us per # lookup), which matters when a lookup happens on every request. pecl-install maxminddb; \ - docker-php-ext-enable redis imagick maxminddb; \ + pecl-install excimer; \ + docker-php-ext-enable redis imagick maxminddb excimer; \ \ docker-php-source delete; \ rm -rf /tmp/pear ~/.pearrc; \ @@ -135,7 +136,7 @@ RUN set -eux; \ out="$(php -v 2>&1)"; \ echo "$out"; \ case "$out" in *Warning*|*"nable to load"*) exit 1 ;; esac; \ - for ext in gd calendar intl pdo_mysql pdo_pgsql zip exif pcntl sockets redis imagick maxminddb; do \ + for ext in gd calendar intl pdo_mysql pdo_pgsql zip exif pcntl sockets redis imagick maxminddb excimer; do \ php -r "exit(extension_loaded('$ext') ? 0 : 1);" || { echo "extension $ext failed to load" >&2; exit 1; }; \ done diff --git a/fpm/8.3/Dockerfile.cli b/fpm/8.3/Dockerfile.cli index 2aecd12..f3207c1 100644 --- a/fpm/8.3/Dockerfile.cli +++ b/fpm/8.3/Dockerfile.cli @@ -109,7 +109,8 @@ RUN set -eux; \ # faster than maxmind-db/reader's pure-PHP fallback (~1.7us vs ~160us per # lookup), which matters when a lookup happens on every request. pecl-install maxminddb; \ - docker-php-ext-enable redis imagick maxminddb; \ + pecl-install excimer; \ + docker-php-ext-enable redis imagick maxminddb excimer; \ \ docker-php-source delete; \ rm -rf /tmp/pear ~/.pearrc; \ @@ -134,7 +135,7 @@ RUN set -eux; \ out="$(php -v 2>&1)"; \ echo "$out"; \ case "$out" in *Warning*|*"nable to load"*) exit 1 ;; esac; \ - for ext in gd calendar intl pdo_mysql pdo_pgsql zip exif pcntl sockets redis imagick maxminddb; do \ + for ext in gd calendar intl pdo_mysql pdo_pgsql zip exif pcntl sockets redis imagick maxminddb excimer; do \ php -r "exit(extension_loaded('$ext') ? 0 : 1);" || { echo "extension $ext failed to load" >&2; exit 1; }; \ done