diff --git a/.github/workflows/build-and-push.yml b/.github/workflows/build-and-push.yml index f4e5c8d..48c0d74 100644 --- a/.github/workflows/build-and-push.yml +++ b/.github/workflows/build-and-push.yml @@ -101,10 +101,11 @@ jobs: php/8.5/frankenphp/docker-configure # Images with no in-repo FROM dependency - safe to build fully in parallel. - # The frankenphp images live in their own build-frankenphp-base job below: - # every one of these still finishes in well under a minute (confirmed from - # actual run logs), so there's nothing to gain from the digest-split/native - # -arm64 treatment frankenphp needs - it would only add job overhead here. + # The frankenphp images live in their own build-frankenphp-base job below. + # The 8.3-8.5 cli images compile their extensions (install-php-extensions on + # the official php images), which is slower under QEMU for arm64; if these + # legs become the bottleneck, give them the digest-split/native-arm64 + # treatment frankenphp has. build-base: needs: detect-changes runs-on: ubuntu-latest diff --git a/README.md b/README.md index 6098288..188eba4 100644 --- a/README.md +++ b/README.md @@ -22,12 +22,12 @@ docker pull ghcr.io/aliasproject/php:8.4-frankenphp ## Variants -- **cli** — Alpine + the PHP CLI SAPI and a minimal extension set (`pdo_mysql`, `bcmath`, `pcntl`, `posix`, etc.), unlimited execution time, runs as an unprivileged `appuser` in group `0`. +- **cli** — the PHP CLI with unlimited execution time. 8.3–8.5 are built on the official `php:-cli-alpine` images, so a rebuild picks up the latest php.net patch release (7.4–8.1 still use Alpine's EOL packages). Images are only rebuilt when their Dockerfile changes or the workflow is run by hand. PHP's ini files are in `/usr/local/etc/php` (`conf.d/` for overrides). 8.3–8.5 are identical apart from the PHP version: a minimal extension set (`pdo_mysql`, `bcmath`, `intl`, `pcntl`, `zip`, etc.), a 512M memory limit, and an unprivileged `appuser` in group `0`. Backend and library extensions (`mysqli`, `gd`, `imagick`, `redis`, `igbinary`, …) belong in a derived image such as `php/8.4/cli/Dockerfile.wordpress`. - **frankenphp** — FrankenPHP serves PHP directly through Caddy; no separate web server. Minimal extension set, non-root by default, mail sent through `msmtp`, Composer baked in, `HEALTHCHECK` against Caddy's admin API. - **frankenphp (dev)** — the FrankenPHP base with extra extensions (`mysqli`, `gd`, `exif`, `imagick`, `redis`, `igbinary`, `soap`) for local development. - **frankenphp (wordpress)** — the FrankenPHP base with the same extensions as `dev`, plus a hardening policy suited to running WordPress (see below). -Every image is configurable via environment variables — `PHP_MEMORY_LIMIT`, `PHP_OPCACHE_*`, `PHP_UPLOAD_MAX_FILESIZE`, etc. — see each Dockerfile's `ENV` block for the defaults. +Every frankenphp image is configurable via environment variables — `PHP_MEMORY_LIMIT`, `PHP_OPCACHE_*`, `PHP_UPLOAD_MAX_FILESIZE`, etc. — see each Dockerfile's `ENV` block for the defaults. The cli images have no such variables; override PHP settings with an ini file in `/usr/local/etc/php/conf.d/` or `php -d`. ## Static asset caching diff --git a/php/8.3/cli/Dockerfile b/php/8.3/cli/Dockerfile index 48b07c3..3f34827 100644 --- a/php/8.3/cli/Dockerfile +++ b/php/8.3/cli/Dockerfile @@ -1,38 +1,53 @@ -FROM alpine:3.21 +# Official image: it tracks php.net patch releases, where Alpine's stable +# branches can sit on one PHP patch release for months. The frankenphp images +# are built on the same images (the ZTS variant, php:*-zts-alpine), so CLI and +# web containers get PHP from the same source and build recipe. +FROM php:8.3-cli-alpine LABEL maintainer="Michael Aguiar " -RUN apk add --no-cache \ - curl \ - php83 \ - php83-bcmath \ - php83-common \ - php83-ctype \ - php83-curl \ - php83-dom \ - php83-exif \ - php83-fileinfo \ - php83-gd \ - php83-iconv \ - php83-mbstring \ - php83-mysqli \ - php83-opcache \ - php83-openssl \ - php83-pcntl \ - php83-pdo_mysql \ - php83-pecl-imagick \ - php83-pecl-redis \ - php83-phar \ - php83-posix \ - php83-session \ - php83-simplexml \ - php83-sodium \ - php83-tokenizer \ - php83-xml \ - php83-xmlreader \ - php83-xmlwriter \ - php83-zip +ARG APP_UID=1000 + +# Same installer the frankenphp images ship, so derived images +# (Dockerfile.wordpress) install extensions with the same names and builds. +COPY --from=mlocati/php-extension-installer:2 /usr/bin/install-php-extensions /usr/local/bin/ + +# Tier 1 only: the PHP runtime itself, plus pdo_mysql as the generic modern +# driver (mysqlnd is compiled in, so the shim is effectively free). +# +# Deliberately NOT here -- each picks a backend or wraps an external library, +# and belongs in a derived image: mysqli, redis, igbinary, gd, exif, imagick, +# soap, pgsql. +RUN apk add --no-cache tzdata && \ + install-php-extensions \ + bcmath \ + intl \ + pcntl \ + pdo_mysql \ + zip && \ + \ + cp "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini" && \ + # CLI tasks (search-replace, imports, exports) blow past the 128M default. + # max_execution_time 0 = unlimited, which is the CLI SAPI norm. + # The socket paths are the ones the Alpine-package image this replaced + # used; without them mysqlnd falls back to /tmp/mysql.sock. + printf 'memory_limit = 512M\nmax_execution_time = 0\ndate.timezone = UTC\nmysqli.default_socket = /run/mysqld/mysqld.sock\npdo_mysql.default_socket = /run/mysqld/mysqld.sock\n' \ + > "$PHP_INI_DIR/conf.d/99-cli.ini" && \ + \ + # The Alpine-package images this replaced had PHP at /usr/bin/php and + # /usr/bin/php83; keep both working for scripts that call them. + ln -s /usr/local/bin/php /usr/bin/php && \ + ln -s /usr/local/bin/php /usr/bin/php83 && \ + \ + # Match the frankenphp images: unprivileged UID in group 0 + adduser -u ${APP_UID} -G root -s /sbin/nologin -D appuser && \ + mkdir -p /app && \ + chgrp -R 0 /app && \ + chmod -R g=u /app WORKDIR /app +# Running unprivileged keeps file ownership consistent with the web containers. +USER ${APP_UID}:0 + CMD ["php", "-a"] diff --git a/php/8.4/cli/Dockerfile b/php/8.4/cli/Dockerfile index c14d76b..1dc145c 100644 --- a/php/8.4/cli/Dockerfile +++ b/php/8.4/cli/Dockerfile @@ -1,51 +1,43 @@ -# Alpine 3.22 matches the OS of the frankenphp base image (3.22.2), keeping the -# CLI and web PHP builds on the same release line. -FROM alpine:3.22 +# Official image: it tracks php.net patch releases, where Alpine's stable +# branches can sit on one PHP patch release for months. The frankenphp images +# are built on the same images (the ZTS variant, php:*-zts-alpine), so CLI and +# web containers get PHP from the same source and build recipe. +FROM php:8.4-cli-alpine LABEL maintainer="Michael Aguiar " ARG APP_UID=1000 +# Same installer the frankenphp images ship, so derived images +# (Dockerfile.wordpress) install extensions with the same names and builds. +COPY --from=mlocati/php-extension-installer:2 /usr/bin/install-php-extensions /usr/local/bin/ + # Tier 1 only: the PHP runtime itself, plus pdo_mysql as the generic modern # driver (mysqlnd is compiled in, so the shim is effectively free). # # Deliberately NOT here -- each picks a backend or wraps an external library, # and belongs in a derived image: mysqli, redis, igbinary, gd, exif, imagick, # soap, pgsql. -RUN apk add --no-cache \ - ca-certificates \ - curl \ - tzdata \ - php84 \ - php84-bcmath \ - php84-common \ - php84-ctype \ - php84-curl \ - php84-dom \ - php84-fileinfo \ - php84-iconv \ - php84-intl \ - php84-mbstring \ - php84-opcache \ - php84-openssl \ - php84-pcntl \ - php84-pdo_mysql \ - php84-phar \ - php84-posix \ - php84-session \ - php84-simplexml \ - php84-sodium \ - php84-tokenizer \ - php84-xml \ - php84-xmlreader \ - php84-xmlwriter \ - php84-zip && \ - ln -s /usr/bin/php84 /usr/bin/php && \ +RUN apk add --no-cache tzdata && \ + install-php-extensions \ + bcmath \ + intl \ + pcntl \ + pdo_mysql \ + zip && \ \ + cp "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini" && \ # CLI tasks (search-replace, imports, exports) blow past the 128M default. # max_execution_time 0 = unlimited, which is the CLI SAPI norm. - printf 'memory_limit = 512M\nmax_execution_time = 0\n' \ - > /etc/php84/conf.d/99-cli.ini && \ + # The socket paths are the ones the Alpine-package image this replaced + # used; without them mysqlnd falls back to /tmp/mysql.sock. + printf 'memory_limit = 512M\nmax_execution_time = 0\ndate.timezone = UTC\nmysqli.default_socket = /run/mysqld/mysqld.sock\npdo_mysql.default_socket = /run/mysqld/mysqld.sock\n' \ + > "$PHP_INI_DIR/conf.d/99-cli.ini" && \ + \ + # The Alpine-package images this replaced had PHP at /usr/bin/php and + # /usr/bin/php84; keep both working for scripts that call them. + ln -s /usr/local/bin/php /usr/bin/php && \ + ln -s /usr/local/bin/php /usr/bin/php84 && \ \ # Match the frankenphp images: unprivileged UID in group 0 adduser -u ${APP_UID} -G root -s /sbin/nologin -D appuser && \ diff --git a/php/8.4/cli/Dockerfile.wordpress b/php/8.4/cli/Dockerfile.wordpress index a3efc0a..2287bf7 100644 --- a/php/8.4/cli/Dockerfile.wordpress +++ b/php/8.4/cli/Dockerfile.wordpress @@ -25,13 +25,13 @@ RUN if [ "${APP_UID}" != "$(id -u appuser)" ]; then \ # igbinary in particular is a correctness requirement, not parity for its own # sake -- the redis-cache plugin can serialize with it, and a CLI without # igbinary silently fails to deserialize the object cache. -RUN apk add --no-cache \ - php84-exif \ - php84-gd \ - php84-mysqli \ - php84-pecl-igbinary \ - php84-pecl-imagick \ - php84-pecl-redis \ - php84-soap +RUN install-php-extensions \ + mysqli \ + gd \ + exif \ + redis \ + igbinary \ + imagick \ + soap USER appuser diff --git a/php/8.5/cli/Dockerfile b/php/8.5/cli/Dockerfile index 74ee39c..0105167 100644 --- a/php/8.5/cli/Dockerfile +++ b/php/8.5/cli/Dockerfile @@ -1,37 +1,53 @@ -FROM alpine:edge +# Official image: it tracks php.net patch releases, where Alpine's stable +# branches can sit on one PHP patch release for months. The frankenphp images +# are built on the same images (the ZTS variant, php:*-zts-alpine), so CLI and +# web containers get PHP from the same source and build recipe. +FROM php:8.5-cli-alpine LABEL maintainer="Michael Aguiar " -RUN apk add --no-cache \ - curl \ - php85 \ - php85-bcmath \ - php85-common \ - php85-ctype \ - php85-curl \ - php85-dom \ - php85-exif \ - php85-fileinfo \ - php85-gd \ - php85-iconv \ - php85-mbstring \ - php85-mysqli \ - php85-openssl \ - php85-pcntl \ - php85-pdo_mysql \ - php85-pecl-imagick \ - php85-pecl-redis \ - php85-phar \ - php85-posix \ - php85-session \ - php85-simplexml \ - php85-sodium \ - php85-tokenizer \ - php85-xml \ - php85-xmlreader \ - php85-xmlwriter \ - php85-zip +ARG APP_UID=1000 + +# Same installer the frankenphp images ship, so derived images +# (Dockerfile.wordpress) install extensions with the same names and builds. +COPY --from=mlocati/php-extension-installer:2 /usr/bin/install-php-extensions /usr/local/bin/ + +# Tier 1 only: the PHP runtime itself, plus pdo_mysql as the generic modern +# driver (mysqlnd is compiled in, so the shim is effectively free). +# +# Deliberately NOT here -- each picks a backend or wraps an external library, +# and belongs in a derived image: mysqli, redis, igbinary, gd, exif, imagick, +# soap, pgsql. +RUN apk add --no-cache tzdata && \ + install-php-extensions \ + bcmath \ + intl \ + pcntl \ + pdo_mysql \ + zip && \ + \ + cp "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini" && \ + # CLI tasks (search-replace, imports, exports) blow past the 128M default. + # max_execution_time 0 = unlimited, which is the CLI SAPI norm. + # The socket paths are the ones the Alpine-package image this replaced + # used; without them mysqlnd falls back to /tmp/mysql.sock. + printf 'memory_limit = 512M\nmax_execution_time = 0\ndate.timezone = UTC\nmysqli.default_socket = /run/mysqld/mysqld.sock\npdo_mysql.default_socket = /run/mysqld/mysqld.sock\n' \ + > "$PHP_INI_DIR/conf.d/99-cli.ini" && \ + \ + # The Alpine-package images this replaced had PHP at /usr/bin/php and + # /usr/bin/php85; keep both working for scripts that call them. + ln -s /usr/local/bin/php /usr/bin/php && \ + ln -s /usr/local/bin/php /usr/bin/php85 && \ + \ + # Match the frankenphp images: unprivileged UID in group 0 + adduser -u ${APP_UID} -G root -s /sbin/nologin -D appuser && \ + mkdir -p /app && \ + chgrp -R 0 /app && \ + chmod -R g=u /app WORKDIR /app +# Running unprivileged keeps file ownership consistent with the web containers. +USER ${APP_UID}:0 + CMD ["php", "-a"]