diff --git a/.github/scripts/check-php-image.sh b/.github/scripts/check-php-image.sh new file mode 100755 index 0000000..3cf3529 --- /dev/null +++ b/.github/scripts/check-php-image.sh @@ -0,0 +1,75 @@ +#!/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=() + +# 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). +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 <<<"$wanted" +[ ${#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\");" 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" | + 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