Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 66 additions & 13 deletions .github/scripts/smoke-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,38 @@
# image never gets a floating tag. Run by build-and-push.yml between pushing an
# image by digest and tagging it; also runnable by hand:
#
# .github/scripts/smoke-test.sh <variant> <image> <php-version>
# .github/scripts/smoke-test.sh <variant> <image> <php-version> [<platform>]
# .github/scripts/smoke-test.sh wordpress ghcr.io/aliasproject/php:8.4-frankenphp-wordpress 8.4
# .github/scripts/smoke-test.sh cli ghcr.io/aliasproject/php:8.4-cli 8.4 linux/arm64
#
# variant: cli | base | dev | wordpress | wordpress-dev
# cli runs php; no server
# base, dev the frankenphp Tier 1 extensions
# wordpress, wordpress-dev Tier 1 plus the WordPress extension set
# The frankenphp variants are booted and served over HTTP, so the PHP that is
# checked is the one embedded in the server (not the separate `php` binary).
# platform (optional, linux/amd64 or linux/arm64) is passed to every docker run
# as --platform, and the container's architecture is checked against it. Without
# it, docker runs the image for the host's own architecture. A platform other
# than the host's needs QEMU (binfmt) set up on the host.
set -euo pipefail

if [ "$#" -ne 3 ]; then
echo "usage: $0 <cli|base|dev|wordpress|wordpress-dev> <image> <php-version>" >&2
if [ "$#" -lt 3 ] || [ "$#" -gt 4 ]; then
echo "usage: $0 <cli|base|dev|wordpress|wordpress-dev> <image> <php-version> [<platform>]" >&2
exit 2
fi
variant=$1
image=$2
php_version=$3
platform=${4:-}

expected_arch=
case "$platform" in
"") ;;
linux/amd64) expected_arch=x86_64 ;;
linux/arm64) expected_arch=aarch64 ;;
*) echo "unknown platform: $platform (expected linux/amd64 or linux/arm64)" >&2; exit 2 ;;
esac

tier1="pdo_mysql zip intl bcmath pcntl posix"
wordpress_ext="mysqli gd exif imagick redis igbinary soap"
Expand All @@ -31,7 +45,42 @@ case "$variant" in
*) echo "unknown variant: $variant" >&2; exit 2 ;;
esac

fail() { echo "SMOKE TEST FAILED ($variant, $image): $*" >&2; exit 1; }
fail() { echo "SMOKE TEST FAILED ($variant, $image${platform:+, $platform}): $*" >&2; exit 1; }

# docker run, with --platform when a platform was given. A function rather
# than an array of extra arguments: bash before 4.4 (macOS's /bin/bash) treats
# an empty array as unset under set -u.
drun() {
if [ -n "$platform" ]; then
docker run --platform "$platform" "$@"
else
docker run "$@"
fi
}

# With a platform, pull that platform's image first. Without this, a docker
# engine that keeps one image per name (the classic image store) can find the
# other architecture's image, pulled for an earlier run of this script, under
# the same name. The check_arch below would then fail. A failed pull is fatal
# unless the image is already present locally (a locally built image that was
# never pushed, say). A digest reference always comes from a registry, and the
# local copy may be the other architecture's, so its pull must succeed.
if [ -n "$platform" ]; then
if ! docker pull --quiet --platform "$platform" "$image" >/dev/null; then
case "$image" in
*@sha256:*) fail "could not pull the $platform image" ;;
esac
docker image inspect "$image" >/dev/null 2>&1 \
|| fail "could not pull the $platform image"
echo "pull failed; using the local image" >&2
fi
fi

# uname -m inside the container ($1) against the requested platform.
check_arch() {
[ -n "$expected_arch" ] || return 0
[ "$1" = "$expected_arch" ] || fail "architecture is '$1', expected $expected_arch for $platform"
}

# Shared checks on a PHP version string and a list of loaded extensions.
check_php() {
Expand All @@ -49,16 +98,18 @@ check_php() {
}

if [ "$variant" = cli ]; then
version=$(docker run --rm "$image" php -r 'echo PHP_VERSION;') || fail "php did not run"
loaded=$(docker run --rm "$image" php -m | tr '\n' ' ') || fail "php -m did not run"
version=$(drun --rm "$image" php -r 'echo PHP_VERSION;') || fail "php did not run"
loaded=$(drun --rm "$image" php -m | tr '\n' ' ') || fail "php -m did not run"
check_php "$version" "$loaded"
uid=$(docker run --rm "$image" id -u) || fail "id did not run"
uid=$(drun --rm "$image" id -u) || fail "id did not run"
[ "$uid" != 0 ] || fail "runs as root"
arch=$(drun --rm "$image" uname -m) || fail "uname did not run"
check_arch "$arch"
# Only cli/Dockerfile.wordpress carries the WORDPRESS_VCS_CHECKOUT prepend
# file (see the frankenphp checks below). CI doesn't build that image, so
# this runs only by hand. A docker run that fails fails the check, rather
# than reading as "no file".
has_vcs=$(docker run --rm "$image" sh -c \
has_vcs=$(drun --rm "$image" sh -c \
'if test -f /usr/local/share/php-prepend/wordpress-vcs-checkout.php; then echo yes; else echo no; fi') \
|| fail "the WORDPRESS_VCS_CHECKOUT file check did not run"
case "$has_vcs" in
Expand All @@ -68,12 +119,12 @@ if [ "$variant" = cli ]; then
if [ "$has_vcs" = yes ]; then
seeded='{"automatic_updates_is_vcs_checkout":{"10":[{"function":"__return_true","accepted_args":1}]}}'
check='echo "<?php echo isset(\$GLOBALS[\"wp_filter\"]) ? json_encode(\$GLOBALS[\"wp_filter\"]) : \"none\";" > /tmp/vcs.php && php /tmp/vcs.php'
out=$(docker run --rm "$image" sh -c "$check") || fail "vcs check did not run"
out=$(drun --rm "$image" sh -c "$check") || fail "vcs check did not run"
[ "$out" = none ] || fail "WORDPRESS_VCS_CHECKOUT unset, but the filter was seeded: $out"
out=$(docker run --rm -e WORDPRESS_VCS_CHECKOUT=1 "$image" sh -c "$check") || fail "vcs check did not run"
out=$(drun --rm -e WORDPRESS_VCS_CHECKOUT=1 "$image" sh -c "$check") || fail "vcs check did not run"
[ "$out" = "$seeded" ] || fail "WORDPRESS_VCS_CHECKOUT=1 did not seed the filter: $out"
fi
echo "ok: $image (PHP $version, uid $uid)"
echo "ok: $image (PHP $version, uid $uid, $arch)"
exit 0
fi

Expand Down Expand Up @@ -118,7 +169,7 @@ boot() {
containers+=("$cname")
# Short health interval: the image's own HEALTHCHECK (30s) would make the
# wait below much longer than it needs to be.
docker run -d --name "$cname" -p 127.0.0.1::80 -v "$fixture:/app:ro" \
drun -d --name "$cname" -p 127.0.0.1::80 -v "$fixture:/app:ro" \
--health-interval 2s --health-timeout 5s --health-retries 5 --health-start-period 30s \
"$@" "$image" >/dev/null

Expand Down Expand Up @@ -152,6 +203,8 @@ check_php "$version" "$loaded"

uid=$(docker exec "$name" id -u)
[ "$uid" != 0 ] || fail "runs as root"
arch=$(docker exec "$name" uname -m) || fail "uname did not run"
check_arch "$arch"

# PHP under /storage/ never executes, but ordinary files there are still served
# and other /storage/ URLs still reach the app (Laravel's local-disk serve route).
Expand Down Expand Up @@ -209,4 +262,4 @@ vcs_case "$seeded" -e WORDPRESS_VCS_CHECKOUT=1
vcs_case "$seeded" -e WORDPRESS_VCS_CHECKOUT=1 -e PHP_OPEN_BASEDIR=/app:/tmp
vcs_case none -e WORDPRESS_VCS_CHECKOUT=1 -e PHP_DISABLE_FUNCTIONS=getenv

echo "ok: $image (PHP $version, uid $uid, healthy, WORDPRESS_VCS_CHECKOUT)"
echo "ok: $image (PHP $version, uid $uid, $arch, healthy, WORDPRESS_VCS_CHECKOUT)"
73 changes: 61 additions & 12 deletions .github/workflows/build-and-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,28 @@ jobs:
cache-from: type=gha,scope=${{ matrix.name }}
cache-to: type=gha,mode=max,scope=${{ matrix.name }}

- name: Smoke test ${{ matrix.name }}
- name: Smoke test ${{ matrix.name }} (amd64)
if: ${{ steps.build.outcome == 'success' }}
run: |
tag="${{ matrix.tag }}"
.github/scripts/smoke-test.sh cli \
"${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@${{ steps.build.outputs.digest }}" \
"${tag%%-*}"
"${tag%%-*}" linux/amd64

# The arm64 image runs under the QEMU set up above for the build. The
# cli checks are a handful of short `docker run`s with no server or
# timeouts, far lighter than the emulated extension compile the build
# step has already survived.
# The timeout turns a hung emulated run into a failure in minutes
# rather than at the 6-hour job limit.
- name: Smoke test ${{ matrix.name }} (arm64, QEMU)
if: ${{ steps.build.outcome == 'success' && contains(matrix.platforms, 'arm64') }}
timeout-minutes: 10
run: |
tag="${{ matrix.tag }}"
.github/scripts/smoke-test.sh cli \
"${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@${{ steps.build.outputs.digest }}" \
"${tag%%-*}" linux/arm64

- name: Tag ${{ matrix.name }}
if: ${{ steps.build.outcome == 'success' }}
Expand Down Expand Up @@ -218,6 +233,17 @@ jobs:
cache-from: type=gha,scope=8.${{ matrix.version }}-frankenphp-${{ matrix.arch }}
cache-to: type=gha,mode=max,scope=8.${{ matrix.version }}-frankenphp-${{ matrix.arch }}

# Boot the arm64 image here, on the native arm64 runner that built it,
# before its digest is uploaded: the merge job runs on amd64 and boots
# only the amd64 image. A failure leaves no arm64 digest, so the merge
# job fails at its download and the floating tags stay where they were.
- name: Smoke test (arm64)
if: ${{ matrix.arch == 'arm64' && steps.build.outcome == 'success' }}
run: |
.github/scripts/smoke-test.sh base \
"${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@${{ steps.build.outputs.digest }}" \
"${{ matrix.version }}" linux/arm64

- name: Export digest
if: ${{ inputs.force_build_all || github.event_name == 'schedule' || inputs[matrix.force_input] || (contains(needs.detect-changes.outputs.changed_files, format('php/{0}/frankenphp/Dockerfile', matrix.version)) || contains(needs.detect-changes.outputs.changed_files, format('php/{0}/frankenphp/docker-configure', matrix.version))) }}
run: |
Expand Down Expand Up @@ -283,9 +309,9 @@ jobs:
password: ${{ secrets.GITHUB_TOKEN }}

# Boot the amd64 image (the runner's own architecture) before it gets
# any tag. A failure here leaves the existing floating tags untouched,
# and holds back the images built FROM this one (their jobs need this
# one to succeed).
# any tag; the arm64 image was booted in its build leg. A failure here
# leaves the existing floating tags untouched, and holds back the images
# built FROM this one (their jobs need this one to succeed).
- name: Checkout smoke test script
if: ${{ steps.digest_amd64.outcome == 'success' }}
uses: actions/checkout@v7
Expand All @@ -297,7 +323,7 @@ jobs:
run: |
.github/scripts/smoke-test.sh "base" \
"${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@sha256:$(find /tmp/digests/amd64 -type f -printf '%f')" \
"${{ matrix.version }}"
"${{ matrix.version }}" linux/amd64

- name: Create manifest list and push
if: ${{ inputs.force_build_all || github.event_name == 'schedule' || inputs[matrix.force_input] || (contains(needs.detect-changes.outputs.changed_files, format('php/{0}/frankenphp/Dockerfile', matrix.version)) || contains(needs.detect-changes.outputs.changed_files, format('php/{0}/frankenphp/docker-configure', matrix.version))) }}
Expand Down Expand Up @@ -396,6 +422,17 @@ jobs:
cache-from: type=gha,scope=${{ matrix.version }}-frankenphp-${{ matrix.variant }}-${{ matrix.arch }}
cache-to: type=gha,mode=max,scope=${{ matrix.version }}-frankenphp-${{ matrix.variant }}-${{ matrix.arch }}

# Boot the arm64 image here, on the native arm64 runner that built it,
# before its digest is uploaded: the merge job runs on amd64 and boots
# only the amd64 image. A failure leaves no arm64 digest, so the merge
# job fails at its download and the floating tags stay where they were.
- name: Smoke test (arm64)
if: ${{ matrix.arch == 'arm64' && steps.build.outcome == 'success' }}
run: |
.github/scripts/smoke-test.sh "${{ matrix.variant }}" \
"${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@${{ steps.build.outputs.digest }}" \
"${{ matrix.version }}" linux/arm64

- name: Export digest
if: ${{ inputs.force_build_all || github.event_name == 'schedule' || inputs[matrix.force_input] || contains(needs.detect-changes.outputs.changed_files, format('php/{0}/frankenphp/{1}', matrix.version, matrix.file)) || (contains(needs.detect-changes.outputs.changed_files, format('php/{0}/frankenphp/Dockerfile', matrix.version)) || contains(needs.detect-changes.outputs.changed_files, format('php/{0}/frankenphp/docker-configure', matrix.version))) }}
run: |
Expand Down Expand Up @@ -463,9 +500,9 @@ jobs:
password: ${{ secrets.GITHUB_TOKEN }}

# Boot the amd64 image (the runner's own architecture) before it gets
# any tag. A failure here leaves the existing floating tags untouched,
# and holds back the images built FROM this one (their jobs need this
# one to succeed).
# any tag; the arm64 image was booted in its build leg. A failure here
# leaves the existing floating tags untouched, and holds back the images
# built FROM this one (their jobs need this one to succeed).
- name: Checkout smoke test script
if: ${{ steps.digest_amd64.outcome == 'success' }}
uses: actions/checkout@v7
Expand All @@ -477,7 +514,7 @@ jobs:
run: |
.github/scripts/smoke-test.sh "${{ matrix.variant }}" \
"${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@sha256:$(find /tmp/digests/amd64 -type f -printf '%f')" \
"${{ matrix.version }}"
"${{ matrix.version }}" linux/amd64

- name: Create manifest list and push
if: ${{ inputs.force_build_all || github.event_name == 'schedule' || inputs[matrix.force_input] || contains(needs.detect-changes.outputs.changed_files, format('php/{0}/frankenphp/Dockerfile.{1}', matrix.version, matrix.variant)) || (contains(needs.detect-changes.outputs.changed_files, format('php/{0}/frankenphp/Dockerfile', matrix.version)) || contains(needs.detect-changes.outputs.changed_files, format('php/{0}/frankenphp/docker-configure', matrix.version))) }}
Expand Down Expand Up @@ -562,6 +599,17 @@ jobs:
cache-from: type=gha,scope=${{ matrix.version }}-frankenphp-${{ matrix.variant }}-${{ matrix.arch }}
cache-to: type=gha,mode=max,scope=${{ matrix.version }}-frankenphp-${{ matrix.variant }}-${{ matrix.arch }}

# Boot the arm64 image here, on the native arm64 runner that built it,
# before its digest is uploaded: the merge job runs on amd64 and boots
# only the amd64 image. A failure leaves no arm64 digest, so the merge
# job fails at its download and the floating tags stay where they were.
- name: Smoke test (arm64)
if: ${{ matrix.arch == 'arm64' && steps.build.outcome == 'success' }}
run: |
.github/scripts/smoke-test.sh "${{ matrix.variant }}" \
"${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@${{ steps.build.outputs.digest }}" \
"${{ matrix.version }}" linux/arm64

- name: Export digest
if: ${{ inputs.force_build_all || github.event_name == 'schedule' || inputs[matrix.force_input] || contains(needs.detect-changes.outputs.changed_files, format('php/{0}/frankenphp/{1}', matrix.version, matrix.file)) || (contains(needs.detect-changes.outputs.changed_files, format('php/{0}/frankenphp/Dockerfile', matrix.version)) || contains(needs.detect-changes.outputs.changed_files, format('php/{0}/frankenphp/docker-configure', matrix.version))) }}
run: |
Expand Down Expand Up @@ -624,7 +672,8 @@ jobs:
password: ${{ secrets.GITHUB_TOKEN }}

# Boot the amd64 image (the runner's own architecture) before it gets
# any tag. A failure here leaves the existing floating tags untouched.
# any tag; the arm64 image was booted in its build leg. A failure here
# leaves the existing floating tags untouched.
- name: Checkout smoke test script
if: ${{ steps.digest_amd64.outcome == 'success' }}
uses: actions/checkout@v7
Expand All @@ -636,7 +685,7 @@ jobs:
run: |
.github/scripts/smoke-test.sh "${{ matrix.variant }}" \
"${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@sha256:$(find /tmp/digests/amd64 -type f -printf '%f')" \
"${{ matrix.version }}"
"${{ matrix.version }}" linux/amd64

- name: Create manifest list and push
if: ${{ inputs.force_build_all || github.event_name == 'schedule' || inputs[matrix.force_input] || contains(needs.detect-changes.outputs.changed_files, format('php/{0}/frankenphp/Dockerfile.{1}', matrix.version, matrix.variant)) || (contains(needs.detect-changes.outputs.changed_files, format('php/{0}/frankenphp/Dockerfile', matrix.version)) || contains(needs.detect-changes.outputs.changed_files, format('php/{0}/frankenphp/docker-configure', matrix.version))) }}
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Docker images for PHP, published to `ghcr.io/aliasproject/php`. The primary offe
| 8.4 | ✅ | ✅ | ✅ | ✅ |
| 8.5 | ✅ | ✅ | ✅ | ✅ |

Tags follow `<version>-<variant>` (e.g. `8.4-frankenphp-wordpress`), each also published as `-latest` and as `-<sha>` for the commit it was built from. Every image is rebuilt weekly (Mondays 10:00 UTC) to pick up base-image and Alpine package updates, which also refreshes the `-<sha>` tag of the current commit; pin by digest (`@sha256:…`) for a byte-for-byte fixed image. The amd64 image of every variant is booted and checked (PHP version, extensions, non-root, healthy and serving PHP for the frankenphp images) before it gets any tag, so a build that doesn't start never replaces `-latest`; the check is `.github/scripts/smoke-test.sh`. The arm64 images are built and published but not booted. The frankenphp images stay on their pinned FrankenPHP version, so a new FrankenPHP release (and the PHP version it ships) still needs `FRANKENPHP_VERSION` bumped in their Dockerfiles.
Tags follow `<version>-<variant>` (e.g. `8.4-frankenphp-wordpress`), each also published as `-latest` and as `-<sha>` for the commit it was built from. Every image is rebuilt weekly (Mondays 10:00 UTC) to pick up base-image and Alpine package updates, which also refreshes the `-<sha>` tag of the current commit; pin by digest (`@sha256:…`) for a byte-for-byte fixed image. Both the amd64 and arm64 images of every variant are booted and checked (PHP version, extensions, architecture, non-root, healthy and serving PHP for the frankenphp images) before they get any tag, so a build that doesn't start on either architecture never replaces `-latest`; the check is `.github/scripts/smoke-test.sh`. The arm64 frankenphp images are checked on a native arm64 runner, the arm64 cli images under QEMU. The frankenphp images stay on their pinned FrankenPHP version, so a new FrankenPHP release (and the PHP version it ships) still needs `FRANKENPHP_VERSION` bumped in their Dockerfiles.

```sh
docker pull ghcr.io/aliasproject/php:8.4-frankenphp
Expand Down