From 69b5290f4be80be9ea5618612b101d9fd950448e Mon Sep 17 00:00:00 2001 From: James Titcumb Date: Wed, 10 Dec 2025 18:03:36 +0000 Subject: [PATCH] 434: added a set of Dockerfile-based end-to-end tests to check build tools get installed --- test/end-to-end/Dockerfile | 22 +++++++ test/end-to-end/dockerfile-e2e-test.sh | 82 ++++++++++++++++++++++++++ 2 files changed, 104 insertions(+) create mode 100644 test/end-to-end/Dockerfile create mode 100755 test/end-to-end/dockerfile-e2e-test.sh diff --git a/test/end-to-end/Dockerfile b/test/end-to-end/Dockerfile new file mode 100644 index 0000000..f75bcac --- /dev/null +++ b/test/end-to-end/Dockerfile @@ -0,0 +1,22 @@ +FROM boxproject/box:4.6.10 AS build_pie_phar +RUN apk add git +COPY . /app +RUN cd /app && touch creating_this_means_phar_will_never_be_verified && /box.phar compile + +FROM alpine AS test_pie_installs_build_tools_on_alpine +RUN apk add php php-phar php-mbstring php-iconv php-openssl bzip2-dev libbz2 +COPY --from=build_pie_phar /app/pie.phar /usr/local/bin/pie +RUN pie install --auto-install-build-tools -v php/bz2 +RUN pie show + +FROM fedora AS test_pie_installs_build_tools_on_fedora +RUN dnf install -y php php-pecl-zip unzip bzip2-devel +COPY --from=build_pie_phar /app/pie.phar /usr/local/bin/pie +RUN pie install --auto-install-build-tools -v php/bz2 +RUN pie show + +FROM ubuntu AS test_pie_installs_build_tools_on_ubuntu +COPY --from=build_pie_phar /app/pie.phar /usr/local/bin/pie +RUN apt-get update && apt-get install -y php unzip libbz2-dev +RUN pie install --auto-install-build-tools -v php/bz2 +RUN pie show diff --git a/test/end-to-end/dockerfile-e2e-test.sh b/test/end-to-end/dockerfile-e2e-test.sh new file mode 100755 index 0000000..415aef8 --- /dev/null +++ b/test/end-to-end/dockerfile-e2e-test.sh @@ -0,0 +1,82 @@ +#!/usr/bin/env bash + +set -euo pipefail + +cd "$(dirname "$0")/../../" + +E2E_PATH="$(dirname "$0")" +DOCKERFILE="$E2E_PATH/Dockerfile" + +if [[ ! -f "$DOCKERFILE" ]]; then + echo "Dockerfile not found: $DOCKERFILE" >&2 + exit 1 +fi + +# Make a list of the build targets starting with test_ +mapfile -t TARGETS < <(awk ' + tolower($1) == "from" { + for (i = 1; i <= NF; i++) { + if (tolower($i) == "as" && i < NF) { + t = $(i+1) + if (substr(t,1,5) == "test_") print t + } + } + } +' "$DOCKERFILE") + +if [[ ${#TARGETS[@]} -eq 0 ]]; then + echo "No test_ targets found in $DOCKERFILE" >&2 + exit 1 +fi + +# If a specific target is provided as an argument, run only that target +if [[ $# -gt 0 ]]; then + REQUESTED_TARGET="$1" + # Verify the requested target exists among discovered test_ targets + found=false + for t in "${TARGETS[@]}"; do + if [[ "$t" == "$REQUESTED_TARGET" ]]; then + found=true + break + fi + done + if [[ $found == false ]]; then + echo "Requested target '$REQUESTED_TARGET' not found in $DOCKERFILE" >&2 + echo "Available test_ targets:" >&2 + for t in "${TARGETS[@]}"; do + echo " - $t" >&2 + done + exit 1 + fi + TARGETS=("$REQUESTED_TARGET") +fi + +PASSED=() +FAILED=() + +for TARGET in "${TARGETS[@]}"; do + echo "๐Ÿงช Running $TARGET" + LOGFILE="$E2E_PATH/$TARGET.out" + # Stream to console and to the logfile + if docker buildx build --target="$TARGET" --file "$DOCKERFILE" . |& tee "$LOGFILE"; then + PASSED+=("$TARGET") + echo "โœ… Passed $TARGET" + rm "$LOGFILE" + else + FAILED+=("$TARGET") + echo "โŒ Failed $TARGET" >&2 + fi + echo +done + +echo "================ Summary ================" +echo "Total: ${#TARGETS[@]} | Passed: ${#PASSED[@]} | Failed: ${#FAILED[@]}" +if [[ ${#FAILED[@]} -gt 0 ]]; then + echo "Failed targets:" >&2 + for f in "${FAILED[@]}"; do + echo " - $f" >&2 + done + exit 1 +fi + +echo "All test targets passed."