Files
openwaf/Dockerfile.aot-probe
T
Pavlo Ratushnyi d08ec30e0a
ci / lint the workflow and the shell (push) Successful in 10s
ci / build, test, smoke (push) Failing after 2m11s
ci / the operator page in a real browser (push) Successful in 2m29s
ci / build the image and smoke it (push) Successful in 4m15s
ci / the same smoke on an image with no base (push) Successful in 4m15s
the AOT edge links fully static and dies on sqlite, which names the wall exactly
Dockerfile.aot-probe applies the packaging recipe a neighbouring .NET 10 service
already ships — musl RID, StaticExecutable, StaticOpenSslLinking, IlcSingleThreaded,
scratch plus a CA bundle — and the link claim is checked inside the build rather
than asserted in a comment. Measured here (arm64, native): `file` says
`static-pie linked`, `readelf -l` reports 0 program interpreters, `readelf -d`
reports 0 NEEDED shared objects, the binary is 56,820,992 bytes and the image is
94 MB — against 222 MB for the self-contained scratch image and 262 MB chiseled.

It does not serve, and the reason is one step earlier than the query wall:
`Microsoft.Data.Sqlite.SqliteConnection..cctor` throws `DllNotFoundException:
e_sqlite3` with `Dynamic loading not supported`, because SQLitePCLRaw resolves
sqlite by loading a shared library and a NativeAOT binary has no way to load one.
`scripts/compose-smoke.sh` against that image therefore never gets past
readiness: the container reports exited/unhealthy and every curl answers 000.
Behind that sits the EF precompiler wall measured at 7c5e1ef and today.

So the static scratch shape is reachable for this program and the data layer is
the thing in the way. The deployment that ships it has no EF Core and no SQLite:
Npgsql plus a Roslyn source generator that emits queries at build time
(app/lib/MicroOrm there), which is why its AOT binary can be one static file.

.github/workflows/aot-probe.yml re-runs this on the x86-64 runner weekly and
gates only the static-link claim (0 interpreters, 0 NEEDED, static-pie), because
the musl AOT ILC crashes under emulation on Apple Silicon. docker-compose.aot.yml
runs the production smoke against the probe image for whoever wants the failure
in full rather than summarised.
2026-10-06 09:15:29 +02:00

118 lines
5.7 KiB
Docker

# syntax=docker/dockerfile:1.7
#
# NativeAOT probe: the packaging recipe that works for its neighbour project,
# applied to this edge and measured. NOT the shipped image — Dockerfile (chiseled)
# and Dockerfile.scratch (self-contained on no base) are what ship.
#
# What this proves: the AOT build of this program links FULLY STATIC against musl
# — no libc, no interpreter — so a scratch layer holding one binary is reachable
# for openwaf too. What it does not prove: that the binary serves traffic. EF
# refuses to compile a LINQ query at run time in a NativeAOT binary and EF
# 10.0.12's precompile-queries generator cannot produce code for this model;
# docs/ARCHITECTURE.md (NativeAOT entry) carries the four refusal shapes and the
# codegen bug, and scripts/aot-probe.sh reproduces the runtime half.
#
# The recipe is not invented here. ~/work/tskr ships a .NET 10 NativeAOT API FROM
# scratch as one static musl binary (app/api/Dockerfile, app/api/leasevibe.csproj)
# and it gets there by deleting the thing that blocks us: it has no EF Core at
# all — Npgsql plus a Roslyn source generator (app/lib/MicroOrm) that turns
# Where(...) expressions into generated code at build time. The parts that
# transfer regardless of the data layer are here:
# apk add clang build-base cmake zlib-dev zlib-static openssl-dev openssl-libs-static
# RID linux-musl-*, <StaticExecutable>true</StaticExecutable>,
# <StaticOpenSslLinking>true</StaticOpenSslLinking>, <IlcSingleThreaded>true
# scratch + CA bundle + SSL_CERT_FILE, healthcheck answered by the binary itself.
# It also names the wall this host has: the musl AOT ILC crashes under emulation
# on Apple Silicon, so the linux-musl-x64 build belongs on the x86 runner.
ARG DOTNET_VERSION=10.0
ARG DBIP_VERSION=2026-10
ARG DBIP_EDITION=country
FROM mcr.microsoft.com/dotnet/sdk:${DOTNET_VERSION}-alpine AS restore
WORKDIR /src
# The AOT link needs a real toolchain plus the STATIC system libs: libz.a,
# libssl.a, libcrypto.a. cmake is pulled in by the StaticOpenSslLinking step.
RUN apk add --no-cache clang build-base cmake zlib-dev zlib-static openssl-dev openssl-libs-static
COPY dotnet/global.json dotnet/Directory.Build.props dotnet/NuGet.Config dotnet/OpenWaf.slnx ./
COPY dotnet/OpenWaf.Domain/OpenWaf.Domain.csproj OpenWaf.Domain/
COPY dotnet/OpenWaf.Infrastructure/OpenWaf.Infrastructure.csproj OpenWaf.Infrastructure/
COPY dotnet/OpenWaf.Edge/OpenWaf.Edge.csproj OpenWaf.Edge/
COPY dotnet/OpenWaf.Tests.Unit/OpenWaf.Tests.Unit.csproj OpenWaf.Tests.Unit/
COPY dotnet/OpenWaf.Tests.Integration/OpenWaf.Tests.Integration.csproj OpenWaf.Tests.Integration/
ARG TARGETARCH
RUN case "${TARGETARCH}" in \
amd64) RID=linux-musl-x64 ;; \
arm64) RID=linux-musl-arm64 ;; \
*) printf 'no musl RID for architecture %s\n' "${TARGETARCH}" >&2; exit 1 ;; \
esac && printf 'RID=%s\n' "$RID" > /rid && dotnet restore OpenWaf.Edge/OpenWaf.Edge.csproj -r "$RID"
FROM restore AS build
COPY dotnet/ ./
RUN . /rid && dotnet publish OpenWaf.Edge/OpenWaf.Edge.csproj \
-c Release \
-r "$RID" \
--self-contained true \
-p:PublishAot=true \
-p:InvariantGlobalization=true \
-p:DebugType=none \
-p:OpenWafCompiledModel=true \
-p:NoWarn=IL2026%3BIL3050 \
-p:IlcTreatWarningsAsErrors=false \
-p:StaticExecutable=true \
-p:StaticOpenSslLinking=true \
-p:IlcSingleThreaded=true \
-o /publish/api \
&& mkdir -p /publish/data
# The static-link claim, checked at build time rather than asserted in a comment:
# a fully static executable has no PT_INTERP and `file` calls it static.
RUN apk add --no-cache file binutils \
&& BIN=/publish/api/OpenWaf.Edge \
&& printf 'binary bytes: %s\n' "$(wc -c < "$BIN" | tr -d ' ')" \
&& printf 'file says: %s\n' "$(file -b "$BIN")" \
&& printf 'program headers naming an interpreter: %s\n' \
"$(readelf -l "$BIN" 2>/dev/null | grep -c 'program interpreter' )" \
&& printf 'NEEDED shared objects: %s\n' \
"$(readelf -d "$BIN" 2>/dev/null | grep -c '(NEEDED)')"
FROM curlimages/curl:8.10.1 AS geoip
ARG DBIP_VERSION
ARG DBIP_EDITION
RUN mkdir -p /tmp/geoip && \
curl --fail --silent --show-error --location --retry 3 --retry-delay 2 \
"https://download.db-ip.com/free/dbip-${DBIP_EDITION}-lite-${DBIP_VERSION}.mmdb.gz" \
| gunzip > /tmp/geoip/GeoLite2-Country.mmdb
FROM scratch
# Content root is the working directory for a self-contained apphost, and this
# one is the binary itself: without WORKDIR the process starts in / and never
# finds appsettings.json, which leaves the proxy with no routes. Measured on the
# scratch (JIT) image, where it cost 7 of the 368 assertions.
WORKDIR /app
COPY --from=build --chown=1654:1654 /publish/api/OpenWaf.Edge /app/OpenWaf.Edge
COPY --from=build --chown=1654:1654 /publish/api/appsettings*.json /app/
COPY --from=build --chown=1654:1654 /publish/data /app/data
COPY --from=geoip --chown=1654:1654 /tmp/geoip /app/geoip
# Outbound TLS (an https alert webhook, an https upstream) verifies a chain, and
# scratch ships no trust store. Static OpenSSL reads this path when told to.
COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
USER 1654:1654
ENV SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt \
ASPNETCORE_URLS=http://+:8080 \
ASPNETCORE_FORWARDEDHEADERS_ENABLED=false \
ConnectionStrings__OpenWaf="Data Source=/app/data/openwaf.db" \
Database__Provider=sqlite \
GEOIP_MAXMIND_DB_PATH=/app/geoip/GeoLite2-Country.mmdb \
HEALTHCHECK_PORT=8080 \
OPENWAF_SCHEMA=script
EXPOSE 8080
HEALTHCHECK --interval=30s --timeout=5s --retries=3 --start-period=10s \
CMD ["/app/OpenWaf.Edge", "--healthcheck"]
ENTRYPOINT ["/app/OpenWaf.Edge"]