1
0
mirror of https://github.com/php/pie.git synced 2026-03-23 23:12:17 +01:00

434: added a set of Dockerfile-based end-to-end tests to check build tools get installed

This commit is contained in:
James Titcumb
2025-12-10 18:03:36 +00:00
parent 81d8f982f0
commit 69b5290f4b
2 changed files with 104 additions and 0 deletions

View File

@@ -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

View File

@@ -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."