From cbb9bc8eac8b9d9a4253d3dae0853c9c7684e9a2 Mon Sep 17 00:00:00 2001 From: Riddhesh Sanghvi Date: Thu, 19 Nov 2026 11:57:55 +0530 Subject: [PATCH 1/4] ci(php): fail the image build when an expected PHP module is missing The Dockerfiles chain `pecl install` calls with `;`, so a failed download (pecl.php.net HTTP 500 during the v4.14.2 tag build) left the build green and shipped images without apcu/imagick/mcrypt/redis/timezonedb or with a memcached.ini pointing at a missing memcached.so. The PHP job now builds and loads the image on PRs and tags, then runs .github/scripts/check-php-image.sh before the push step. It fails when a module from php//expected-modules.txt is missing from `php -m`, when PHP prints anything on startup, when `php-fpm -t` fails or warns, or when a conf.d ini loads a .so that doesn't exist. The lists come from the verified published images (php8.1:v4.14.0, php8.2-8.5:v4.14.2). --- .github/scripts/check-php-image.sh | 63 ++++++++++++++++++++++++++ .github/workflows/test_and_publish.yml | 6 ++- php/8.1/expected-modules.txt | 58 ++++++++++++++++++++++++ php/8.2/expected-modules.txt | 58 ++++++++++++++++++++++++ php/8.3/expected-modules.txt | 58 ++++++++++++++++++++++++ php/8.4/expected-modules.txt | 58 ++++++++++++++++++++++++ php/8.5/expected-modules.txt | 58 ++++++++++++++++++++++++ 7 files changed, 358 insertions(+), 1 deletion(-) create mode 100755 .github/scripts/check-php-image.sh create mode 100644 php/8.1/expected-modules.txt create mode 100644 php/8.2/expected-modules.txt create mode 100644 php/8.3/expected-modules.txt create mode 100644 php/8.4/expected-modules.txt create mode 100644 php/8.5/expected-modules.txt diff --git a/.github/scripts/check-php-image.sh b/.github/scripts/check-php-image.sh new file mode 100755 index 0000000..de70a0d --- /dev/null +++ b/.github/scripts/check-php-image.sh @@ -0,0 +1,63 @@ +#!/usr/bin/env bash +# Fail when a built PHP image lacks an expected module, warns on startup, +# or has a conf.d ini that loads a missing .so (a failed `pecl install` is +# otherwise swallowed by the Dockerfile's `;`-chained RUN). +# Usage: check-php-image.sh +set -uo pipefail + +image=${1:?image} +expected=${2:?expected modules file} +errors=() + +run() { docker run --rm --pull=never --entrypoint sh "$image" -c "$1" 2>&1; } + +# 1. Expected modules (extra modules are fine). +if ! modules=$(docker run --rm --pull=never --entrypoint php "$image" -m 2>&1); then + errors+=("php -m failed: $modules") +fi +missing=() +while IFS= read -r m; do + [ -z "$m" ] && continue + grep -Fxq -- "$m" <<<"$modules" || missing+=("$m") +done < <(sed -e 's/[[:space:]]*$//' -e '/^#/d' "$expected") +[ ${#missing[@]} -gt 0 ] && errors+=("missing modules: ${missing[*]}") + +# 2. Startup must be silent, and the FPM config must load cleanly. +startup=$(run 'php -r "exit(0);"') || errors+=("php exited non-zero on startup") +[ -n "$startup" ] && errors+=("php startup output (warnings): $startup") + +if ! fpm=$(run 'php-fpm -t'); then + errors+=("php-fpm -t failed: $fpm") +elif grep -Eiq 'warning|unable to load' <<<"$fpm"; then + errors+=("php-fpm -t warnings: $fpm") +fi + +# 3. Every extension= / zend_extension= line in the scanned ini dir must resolve to a file. +dangling=$(run ' + ext_dir=$(php -r "echo ini_get(\"extension_dir\");") + ini_dir=$(php -r "echo PHP_CONFIG_FILE_SCAN_DIR;") + for f in "$ini_dir"/*.ini; do + [ -f "$f" ] || continue + sed -n "s/^[[:space:]]*\(zend_\)\{0,1\}extension[[:space:]]*=[[:space:]]*\"\{0,1\}\([^\";[:space:]]*\).*/\2/p" "$f" | + while IFS= read -r so; do + [ -z "$so" ] && continue + case "$so" in + /*) path=$so ;; + *.so) path=$ext_dir/$so ;; + *) path=$ext_dir/$so.so ;; + esac + [ -f "$path" ] || echo "$(basename "$f") -> $path" + done + done +') +[ -n "$dangling" ] && errors+=("ini files load a missing .so: $dangling") + +if [ ${#errors[@]} -gt 0 ]; then + for e in "${errors[@]}"; do + # Keep multi-line details inside one annotation. + e=${e//'%'/'%25'}; e=${e//$'\n'/'%0A'} + echo "::error title=PHP image check failed ($image)::$e" + done + exit 1 +fi +echo "$image: all $(grep -cv -e '^#' -e '^[[:space:]]*$' "$expected") expected modules present, clean startup, no dangling extension ini." diff --git a/.github/workflows/test_and_publish.yml b/.github/workflows/test_and_publish.yml index a802918..eecbb19 100644 --- a/.github/workflows/test_and_publish.yml +++ b/.github/workflows/test_and_publish.yml @@ -48,13 +48,17 @@ jobs: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} + # Built on PRs and tags alike, so a broken image is caught before the push step. - name: Build PHP - ${{ matrix.php }} image uses: docker/build-push-action@v7 - if: github.event_name == 'pull_request' with: context: php/${{ matrix.php }} + load: true tags: easyengine/php${{ steps.img-tag.outputs.tag }}:test + - name: Check PHP - ${{ matrix.php }} modules and startup + run: .github/scripts/check-php-image.sh easyengine/php${{ steps.img-tag.outputs.tag }}:test php/${{ matrix.php }}/expected-modules.txt + - name: Build and push PHP - ${{ matrix.php }} image uses: docker/build-push-action@v7 if: github.event_name != 'pull_request' diff --git a/php/8.1/expected-modules.txt b/php/8.1/expected-modules.txt new file mode 100644 index 0000000..ba31449 --- /dev/null +++ b/php/8.1/expected-modules.txt @@ -0,0 +1,58 @@ +apcu +bcmath +calendar +Core +ctype +curl +date +dom +exif +fileinfo +filter +ftp +gd +gmagick +gmp +hash +iconv +imagick +imap +intl +json +libxml +mbstring +mcrypt +memcached +mysqli +mysqlnd +newrelic +openssl +pcntl +pcre +PDO +pdo_mysql +pdo_sqlite +Phar +posix +readline +redis +Reflection +session +shmop +SimpleXML +soap +sockets +sodium +SPL +sqlite3 +standard +sysvsem +sysvshm +timezonedb +tokenizer +xml +xmlreader +xmlwriter +Zend OPcache +zip +zlib diff --git a/php/8.2/expected-modules.txt b/php/8.2/expected-modules.txt new file mode 100644 index 0000000..3121f27 --- /dev/null +++ b/php/8.2/expected-modules.txt @@ -0,0 +1,58 @@ +apcu +bcmath +calendar +Core +ctype +curl +date +dom +exif +fileinfo +filter +gd +gmagick +gmp +hash +iconv +imagick +imap +intl +json +libxml +mbstring +mcrypt +memcached +mysqli +mysqlnd +newrelic +openssl +pcntl +pcre +PDO +pdo_mysql +pdo_sqlite +Phar +posix +random +readline +redis +Reflection +session +shmop +SimpleXML +soap +sockets +sodium +SPL +sqlite3 +standard +sysvsem +sysvshm +timezonedb +tokenizer +xml +xmlreader +xmlwriter +Zend OPcache +zip +zlib diff --git a/php/8.3/expected-modules.txt b/php/8.3/expected-modules.txt new file mode 100644 index 0000000..3121f27 --- /dev/null +++ b/php/8.3/expected-modules.txt @@ -0,0 +1,58 @@ +apcu +bcmath +calendar +Core +ctype +curl +date +dom +exif +fileinfo +filter +gd +gmagick +gmp +hash +iconv +imagick +imap +intl +json +libxml +mbstring +mcrypt +memcached +mysqli +mysqlnd +newrelic +openssl +pcntl +pcre +PDO +pdo_mysql +pdo_sqlite +Phar +posix +random +readline +redis +Reflection +session +shmop +SimpleXML +soap +sockets +sodium +SPL +sqlite3 +standard +sysvsem +sysvshm +timezonedb +tokenizer +xml +xmlreader +xmlwriter +Zend OPcache +zip +zlib diff --git a/php/8.4/expected-modules.txt b/php/8.4/expected-modules.txt new file mode 100644 index 0000000..3121f27 --- /dev/null +++ b/php/8.4/expected-modules.txt @@ -0,0 +1,58 @@ +apcu +bcmath +calendar +Core +ctype +curl +date +dom +exif +fileinfo +filter +gd +gmagick +gmp +hash +iconv +imagick +imap +intl +json +libxml +mbstring +mcrypt +memcached +mysqli +mysqlnd +newrelic +openssl +pcntl +pcre +PDO +pdo_mysql +pdo_sqlite +Phar +posix +random +readline +redis +Reflection +session +shmop +SimpleXML +soap +sockets +sodium +SPL +sqlite3 +standard +sysvsem +sysvshm +timezonedb +tokenizer +xml +xmlreader +xmlwriter +Zend OPcache +zip +zlib diff --git a/php/8.5/expected-modules.txt b/php/8.5/expected-modules.txt new file mode 100644 index 0000000..c3a3421 --- /dev/null +++ b/php/8.5/expected-modules.txt @@ -0,0 +1,58 @@ +apcu +bcmath +calendar +Core +ctype +curl +date +dom +exif +fileinfo +filter +gd +gmp +hash +iconv +imagick +imap +intl +json +lexbor +libxml +mbstring +mcrypt +memcached +mysqli +mysqlnd +openssl +pcntl +pcre +PDO +pdo_mysql +pdo_sqlite +Phar +posix +random +readline +redis +Reflection +session +shmop +SimpleXML +soap +sockets +sodium +SPL +sqlite3 +standard +sysvsem +sysvshm +timezonedb +tokenizer +uri +xml +xmlreader +xmlwriter +Zend OPcache +zip +zlib From 9762d8c4fee3362878180ccba27b06a158ba93f5 Mon Sep 17 00:00:00 2001 From: Riddhesh Sanghvi Date: Thu, 19 Nov 2026 11:59:58 +0530 Subject: [PATCH 2/4] ci(php): keep startup warnings out of the dangling-ini report The startup check already reports them; the ini check should only list the ini files and the missing .so paths. --- .github/scripts/check-php-image.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/scripts/check-php-image.sh b/.github/scripts/check-php-image.sh index de70a0d..ba2cda4 100755 --- a/.github/scripts/check-php-image.sh +++ b/.github/scripts/check-php-image.sh @@ -34,8 +34,8 @@ fi # 3. Every extension= / zend_extension= line in the scanned ini dir must resolve to a file. dangling=$(run ' - ext_dir=$(php -r "echo ini_get(\"extension_dir\");") - ini_dir=$(php -r "echo PHP_CONFIG_FILE_SCAN_DIR;") + ext_dir=$(php -r "echo ini_get(\"extension_dir\");" 2>/dev/null) + ini_dir=$(php -r "echo PHP_CONFIG_FILE_SCAN_DIR;" 2>/dev/null) for f in "$ini_dir"/*.ini; do [ -f "$f" ] || continue sed -n "s/^[[:space:]]*\(zend_\)\{0,1\}extension[[:space:]]*=[[:space:]]*\"\{0,1\}\([^\";[:space:]]*\).*/\2/p" "$f" | From ded9e189030e922bcc9bb7315149d1fc09782434 Mon Sep 17 00:00:00 2001 From: Riddhesh Sanghvi Date: Thu, 19 Nov 2026 12:02:58 +0530 Subject: [PATCH 3/4] ci(php): fail the module check when the expected list is missing or empty Without it a PHP version with no list (e.g. a new one) would pass the check silently. --- .github/scripts/check-php-image.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/scripts/check-php-image.sh b/.github/scripts/check-php-image.sh index ba2cda4..70ba374 100755 --- a/.github/scripts/check-php-image.sh +++ b/.github/scripts/check-php-image.sh @@ -9,6 +9,12 @@ image=${1:?image} expected=${2:?expected modules file} errors=() +# A missing list would otherwise check nothing and pass (e.g. a new PHP version). +if ! grep -qv -e '^#' -e '^[[:space:]]*$' "$expected" 2>/dev/null; then + echo "::error title=PHP image check failed ($image)::expected modules file $expected is missing or empty" + exit 1 +fi + run() { docker run --rm --pull=never --entrypoint sh "$image" -c "$1" 2>&1; } # 1. Expected modules (extra modules are fine). From b7be16da95741b8694bc1f246d1f61c99f2ddb77 Mon Sep 17 00:00:00 2001 From: Riddhesh Sanghvi Date: Thu, 19 Nov 2026 12:05:17 +0530 Subject: [PATCH 4/4] ci(php): read the expected list without losing errors or an unterminated last line --- .github/scripts/check-php-image.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/scripts/check-php-image.sh b/.github/scripts/check-php-image.sh index 70ba374..3cf3529 100755 --- a/.github/scripts/check-php-image.sh +++ b/.github/scripts/check-php-image.sh @@ -21,11 +21,17 @@ run() { docker run --rm --pull=never --entrypoint sh "$image" -c "$1" 2>&1; } if ! modules=$(docker run --rm --pull=never --entrypoint php "$image" -m 2>&1); then errors+=("php -m failed: $modules") fi +# Command substitution (not process substitution) so a read failure stops the +# check, and the here-string also covers a last line without a newline. +if ! wanted=$(sed -e 's/[[:space:]]*$//' -e '/^#/d' "$expected"); then + echo "::error title=PHP image check failed ($image)::cannot read $expected" + exit 1 +fi missing=() while IFS= read -r m; do [ -z "$m" ] && continue grep -Fxq -- "$m" <<<"$modules" || missing+=("$m") -done < <(sed -e 's/[[:space:]]*$//' -e '/^#/d' "$expected") +done <<<"$wanted" [ ${#missing[@]} -gt 0 ] && errors+=("missing modules: ${missing[*]}") # 2. Startup must be silent, and the FPM config must load cleanly.