Files
openwaf/scripts/aot-link-report.sh
T
Pavlo Ratushnyi cbafca491b
ci / lint the workflow and the shell (push) Successful in 10s
ci / the operator page in a real browser (push) Successful in 2m36s
ci / the same smoke on an image with no base (push) Successful in 4m4s
ci / build the image and smoke it (push) Successful in 4m4s
ci / build, test, smoke (push) Successful in 2m19s
the static-link gate asks the binary, not the build log, because a cache prints nothing
Run 2503 turned a good artifact red: the publish layer was cached, the report
layer was cached with it, the build log carried no report lines, and the gate
that greps that log found nothing to match. The report is now a script
(scripts/aot-link-report.sh) that the build stage copies in and runs, and that CI
runs again with `docker run --entrypoint sh … /report.sh` — a container start is
never cached, so the gate asks the binary. It exits non-zero when the link names
an interpreter or needs a shared object, which is the one claim a scratch layer
depends on.

Verified here: the script prints `binary bytes: 56820992`, `static-pie linked`,
`program headers naming an interpreter: 0`, `NEEDED shared objects: 0`,
`static: no interpreter, no NEEDED shared object`, exit 0 — both as a build step
and as a `docker run`. .dockerignore keeps `scripts/` out of the context and now
makes one named exception for it.
2026-10-06 09:35:16 +02:00

54 lines
2.0 KiB
Bash
Executable File

#!/bin/sh
# The static-link report for the NativeAOT probe image, run INSIDE the build
# stage against the binary it just produced.
#
# Why a script and not a RUN line in the Dockerfile: a cached layer prints
# nothing. Measured on Gitea Actions run 2503 — the publish layer was cached, the
# report layer was cached with it, the build log carried no report lines, and the
# CI gate that greps the log failed on a perfectly good artifact. A `docker run`
# of this script always executes, so the gate asks the binary rather than asking
# the cache.
#
# Exits non-zero when the link is NOT fully static, because that is the one claim
# Dockerfile.aot-probe makes and the claim a scratch layer depends on: an
# interpreter or a NEEDED shared object means the image would be silently
# depending on a libc it does not contain.
set -eu
BIN=${1:-/publish/api/OpenWaf.Edge}
if [ ! -f "$BIN" ]; then
printf 'no binary at %s: cannot report\n' "$BIN" >&2
exit 2
fi
# file(1) and readelf(1) are not in the SDK image; the AOT toolchain stage has
# binutils already, but this runs in any stage that holds the binary.
if ! command -v readelf >/dev/null 2>&1; then
apk add --no-cache binutils file >/dev/null 2>&1 || {
printf 'neither readelf nor a way to install it: cannot report (exit 2), not a pass\n' >&2
exit 2
}
fi
printf 'binary: %s\n' "$BIN"
printf 'binary bytes: %s\n' "$(wc -c < "$BIN" | tr -d ' ')"
if command -v file >/dev/null 2>&1; then
printf 'file says: %s\n' "$(file -b "$BIN")"
fi
interpreters=$(readelf -l "$BIN" 2>/dev/null | grep -c 'program interpreter' || true)
needed=$(readelf -d "$BIN" 2>/dev/null | grep -c '(NEEDED)' || true)
printf 'program headers naming an interpreter: %s\n' "$interpreters"
printf 'NEEDED shared objects: %s\n' "$needed"
if [ "$interpreters" != "0" ]; then
printf 'NOT static: the binary names a dynamic loader\n' >&2
exit 1
fi
if [ "$needed" != "0" ]; then
printf 'NOT static: the binary needs a shared object at run time\n' >&2
exit 1
fi
printf 'static: no interpreter, no NEEDED shared object\n'