Files
Pavlo Ratushnyi be6c608ada
ci / the operator page in a real browser (push) Successful in 2m38s
ci / lint the workflow and the shell (push) Successful in 13s
geo-freshness / the pinned geo database vs the vendor (push) Successful in 4s
ci / build, test, smoke (push) Successful in 2m48s
ci / build the image and smoke it (push) Successful in 4m23s
ci / the same smoke on an image with no base (push) Successful in 5m3s
the edge ships on an image with no base, and the 368 assertions agree it behaves
Dockerfile.scratch builds the same program self-contained and puts it on
scratch: 12 shared objects and the CA bundle — 18.7 MB — carried at their
absolute paths, because a scratch layer has nothing to borrow them from, and the
dynamic loader has to land at the path recorded inside the binary or the kernel
refuses to start the process. Measured on one arm64 host: chiseled 262 MB,
scratch 222 MB. scripts/compose-smoke.sh runs against it unchanged through
docker-compose.scratch.yml: 368 passed, 0 failed, and 368/0 again when the same
gate is called as scripts/ci-gates.sh scratch-smoke.

The first scratch image built here is why that second run matters. It started,
its own HEALTHCHECK reported healthy, and it still failed 7 of the 368. A
self-contained apphost takes its content root from the process's working
directory, a scratch image has no WORKDIR, so the process began in /, never found
the appsettings.json next to it, the reverse proxy had no routes, and every
request that should have reached the upstream answered the edge's own 404 —
including /boom's 502, which turned the "server errors alert, they never ban"
scene into a streak ban. The edge said it in its own log: "Request reached the
end of the middleware pipeline without being handled by application code."

The schema-script gate was red on the runner at 7c5e1ef (run 2462, exit 2):
`dotnet tool restore` from the repo root finds no manifest, prints "No tools were
restored." and exits 0, so the gate's own restore check passed vacuously and
`dotnet ef` then died. It now restores dotnet/dotnet-tools.json by path and asks
the tool for its version before trusting it.

NativeAOT, measured further: with the two alert-queue queries taken out,
`dotnet ef dbcontext optimize --precompile-queries` on EF 10.0.12 reports 0
precompilation errors and writes 8 interceptor files — 14 of whose declarations
have dots in the identifier, because the local is named from the entity type's
full name. The 4 refusals that remain are four shapes the generator cannot
translate at all: Contains over a captured collection, any method parameter
referenced inside a query (down to the CancellationToken), an ExecuteUpdate
set-list, and a literal whose type is not the column's. docs/ARCHITECTURE.md
carries the exception for each. No C# changed in this commit: the experiments
that produced those numbers were reverted, and the query rewrites kept at
7c5e1ef are the ones that made 40 refusals into 4.

Gates: scratch-image and scratch-smoke in scripts/ci-gates.sh and in `all`, and a
fifth CI job that runs the 368 against the scratch image on the runner.
2026-10-06 06:38:07 +02:00

133 lines
6.6 KiB
Docker
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# syntax=docker/dockerfile:1.7
#
# openwaf edge — framework-dependent publish on a chiseled distroless runtime.
#
# Why not NativeAOT: measured here on 2026-10-06 rather than inherited from the
# reference deployment. The AOT build compiles and the binary creates its own
# schema from the DDL it carries, and then never serves: EF cannot compile a LINQ
# query at run time in a NativeAOT binary, and EF 10.0.12's precompile-queries
# generator cannot precompile this model — it refused 40 queries, the 4 that
# remain are shapes it cannot translate at all (Contains over a captured
# collection, any method parameter inside a query, an ExecuteUpdate set-list),
# and for the queries it does accept it emits an uncompilable declaration per
# entity materialisation. scripts/aot-probe.sh reproduces the verdict in one
# command; docs/ARCHITECTURE.md carries the numbers.
#
# The static-binary shape is not abandoned, it is blocked upstream. Meanwhile
# Dockerfile.scratch ships this same program on an image with no base at all, and
# scripts/compose-smoke.sh runs against it unchanged — the README's "Two images"
# section has both sizes, and the 7 assertions the first scratch image failed for
# a reason its own HEALTHCHECK could not see.
#
# Stages:
# 1. restore – NuGet layer, cached independently of source changes
# 2. build – framework-dependent publish, debug artefacts stripped
# 3. runtime – mcr.microsoft.com/dotnet/aspnet:10.0-noble-chiseled, no shell
#
# HEALTHCHECK re-executes the binary in --healthcheck mode: a chiseled base has
# no shell, no wget and no curl, so the binary is the only probe available.
ARG DOTNET_VERSION=10.0
# Global scope on purpose: an ARG declared inside a stage is not visible to a
# later stage, and the geoip stage re-declares these without defaults to pick
# these values up. Declaring them after the build stage is what made the URL
# expand to dbip-city-lite-.mmdb.gz and 404 in the geoip stage.
ARG DBIP_VERSION=2026-10
ARG DBIP_EDITION=country
FROM mcr.microsoft.com/dotnet/sdk:${DOTNET_VERSION} AS restore
WORKDIR /src
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/
RUN dotnet restore OpenWaf.Edge/OpenWaf.Edge.csproj
FROM restore AS build
COPY dotnet/ ./
RUN dotnet publish OpenWaf.Edge/OpenWaf.Edge.csproj \
-c Release \
-p:DebugType=none \
-p:DebugSymbols=false \
-o /publish/api \
&& cd /publish/api \
&& rm -f *.pdb \
&& rm -rf BuildHost-net472 BuildHost-netcore
# Stage the volume mount points with app:app ownership — a chiseled image has
# no shell, so there is no mkdir at runtime.
RUN mkdir -p /publish/data /publish/geoip
# GeoIP: dbip lite editions, free and redistributable, same MMDB binary format as
# MaxMind. Kept under the legacy GeoLite2-Country.mmdb name so one env var
# covers both, and the reader sniffs Metadata.DatabaseType rather than trusting
# the filename — a database stored under a country name is exactly the
# trap the reference repo documented. MaxMindGeoIpLookup reads DatabaseType,
# never the name, so either edition below works without a code change.
#
# DBIP_VERSION is pinned, which means the database ages with the image. /healthz
# reports the loaded database's build date and a geoStale flag (90 days), but the
# 90 days is an alarm, not the policy: measured 2026-10-01, a container running a
# one-month-old database reported geoBuiltAt 2026-09-01 and geoStale:false while
# this ARG asked for 2026-10. A month behind is invisible at runtime.
#
# So the build-time half exists: scripts/geo-db-freshness.sh compares this pin
# with the newest release the vendor serves (exit 0 current, 1 behind, 2 cannot
# tell), scripts/geo-db-bump.sh rewrites it and refuses to write anything when
# the check could not run, and .github/workflows/geo-freshness.yml runs the check
# on a schedule. The pin was moved by hand to 2026-10 on 2026-10-01; the check
# says 2026-10 is what the vendor serves today.
#
# One trap with the bump: docker-compose.yml mounts a named volume at
# /app/geoip, and Docker seeds a named volume from the image only the first
# time it is created. An existing deployment keeps the OLD database after a
# rebuild; `docker volume rm <project>_openwaf-geoip` is what makes the new one
# land. /healthz's geoBuiltAt is how you check which one you are actually
# running.
#
# DBIP_EDITION=country is the default: the geo pillar decides on the ISO country
# code, and country-lite is 4 MB compressed / 6 MB on disk. city-lite is 60 MB
# compressed / 127 MB on disk and buys only the city+region columns on
# observations (the map UI). Build --build-arg DBIP_EDITION=city for that.
#
# Downloaded in its own stage with a static curl image: doing it in the SDK
# stage means apt-get update on every cache miss, and that is the slowest and
# least reproducible part of the build (observed: it stalls, the download
# itself takes two seconds). gunzip is part of curlimages/curl's busybox.
# The image runs as uid 100 (curl_user), so the download lands in /tmp, the
# only world-writable directory in it; COPY re-owns the file as app:app.
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 && \
ls -la /tmp/geoip/GeoLite2-Country.mmdb
FROM mcr.microsoft.com/dotnet/aspnet:${DOTNET_VERSION}-noble-chiseled AS runtime
# Chiseled ships a non-root `app` user (UID 1654) and no shell.
WORKDIR /app/api
COPY --from=build --chown=app:app /publish/api /app/api
COPY --from=build --chown=app:app /publish/data /app/data
COPY --from=geoip --chown=app:app /tmp/geoip /app/geoip
USER app:app
ENV 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
EXPOSE 8080
HEALTHCHECK --interval=30s --timeout=5s --retries=3 --start-period=10s \
CMD ["dotnet", "/app/api/OpenWaf.Edge.dll", "--healthcheck"]
ENTRYPOINT ["dotnet", "/app/api/OpenWaf.Edge.dll"]