diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 02d1972..c665fb9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -267,6 +267,133 @@ jobs: - name: README assertion counts match what the gate ran run: ./scripts/ci-gates.sh readme-counts scripts/compose-smoke.sh + # The same stack, the same 368 assertions, and an image whose base is nothing: + # scratch plus the shared objects the program was linked against, the NSS + # modules getaddrinfo needs, OpenSSL, and the CA bundle. This is the job that + # answers "will it behave on a production host" for that shape — the first + # scratch image built here passed its own HEALTHCHECK and still failed 7 of the + # 368, because a self-contained apphost with no WORKDIR starts in / and never + # finds its appsettings.json, so the proxy had no routes and every request that + # should have reached the upstream answered the edge's own 404. + scratch-image: + name: the same smoke on an image with no base + runs-on: ubuntu-latest + # Longer than the image job: a self-contained publish carries the runtime + # into the image instead of borrowing a base layer's, and the build cache on + # the shared runner is cold for a second Dockerfile. + timeout-minutes: 40 + steps: + - uses: actions/checkout@v4 + + # The gate below talks to docker, and the runner's job image does not ship + # the docker CLI. Measured, not guessed: the first real run of this file + # (Gitea Actions run 2316, head 6f92d37) died here with + # `./scripts/ci-gates.sh: line 44: docker: command not found`, exit 127. + # /var/run/docker.sock is mounted from the host, so what is missing is the + # client side: the CLI, the compose v2 plugin, and buildx — `docker compose + # up --build` reaches the daemon through buildx, so the compose plugin alone + # does not bring this stack up. The same install the neemle-landing + # pipeline on this instance uses. Pinned to the Debian bookworm docker.com + # repo so the version does not drift with the image. + - name: Install Docker CLI + compose plugin + run: | + set -eu + if command -v docker >/dev/null 2>&1; then + echo "docker already present: $(docker --version)" + else + export DEBIAN_FRONTEND=noninteractive + apt-get update -qq + apt-get install -qq -y ca-certificates curl gnupg >/dev/null + install -m 0755 -d /etc/apt/keyrings + curl -fsSL https://download.docker.com/linux/debian/gpg \ + | gpg --dearmor -o /etc/apt/keyrings/docker.gpg + chmod a+r /etc/apt/keyrings/docker.gpg + echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian bookworm stable" \ + > /etc/apt/sources.list.d/docker.list + apt-get update -qq + apt-get install -qq -y docker-ce-cli docker-compose-plugin docker-buildx-plugin >/dev/null + fi + # compose-smoke.sh calls `docker compose`, and every command in it + # talks to the host daemon over the mounted socket. A missing socket is + # an infrastructure answer, so it says so here rather than failing + # three steps later as a broken product. + docker --version + docker compose version + docker buildx version + [ -S /var/run/docker.sock ] || { echo "no /var/run/docker.sock on this runner"; exit 1; } + docker info --format 'daemon {{.ServerVersion}} on {{.OperatingSystem}}' + + # The scratch build plus both images' sizes, so the difference between + # "chiseled" and "nothing at all" is a number in the run log rather than a + # claim in a README. + - name: docker build -f Dockerfile.scratch and image size + run: ./scripts/ci-gates.sh scratch-image + + # The nginx config reaches the upstream container through a named volume + # here, not through a workspace path — docker-compose.ci.yml explains why + # (the host daemon cannot see the job container's workspace). Compose names + # the volume after the project, so the name is built, not guessed. + - name: Put the upstream config where the host daemon can see it + env: + COMPOSE_PROJECT_NAME: openwafci-scratch + run: | + set -eu + VOL="${COMPOSE_PROJECT_NAME}_openwaf-upstream-conf" + # A run that died mid-scene leaves its bans in the stack's data volume: + # `compose down` keeps named volumes, and the runner reuses the same + # project name every push. Measured on run 2361, where the 502-upstream + # scene opened with the source already banned (expected 502, got 403) + # because runs 2350 and 2355 left state behind. The gate's own scenes + # rely on data outliving `compose down`, so the clean has to happen + # before the stack starts, not in its teardown. + docker volume rm "${COMPOSE_PROJECT_NAME}_openwaf-data" \ + "${COMPOSE_PROJECT_NAME}_openwaf-geoip" >/dev/null 2>&1 || true + docker volume create "$VOL" >/dev/null + docker run --rm -i -v "$VOL:/conf" busybox:1.37 sh -c 'cat > /conf/default.conf' < deploy/upstream.conf + docker run --rm -v "$VOL:/conf" busybox:1.37 sh -c 'wc -c /conf/default.conf' + + # The second half of the same asymmetry: compose publishes the edge's port on + # the HOST, while the job that curls it lives in its own network namespace, so + # 127.0.0.1: is refused there. Measured on run 2350: the edge container + # reached `healthy`, and the gate's first admin call died with curl exit 7. + # The default-route address of the job container is the host's own address on + # that network, and compose publishes on 0.0.0.0, so that is the address the + # gate has to be pointed at. (tskr solves the same platform quirk by running + # its gates in sibling containers — see docker/test/workspace-mount.sh there.) + - name: Name the address the job can reach the published ports on + run: | + set -eu + # `ip` is not in this image (measured: `ip: command not found`, exit 127), + # so the route is read from the kernel's own table. The gateway there is + # hex, little-endian, and bash turns it back into dotted quad. + GWHEX=$(awk '$2=="00000000" {print $3; exit}' /proc/net/route) + [ -n "$GWHEX" ] || { echo "no default route in /proc/net/route"; exit 1; } + GW=$(printf '%d.%d.%d.%d' "0x${GWHEX:6:2}" "0x${GWHEX:4:2}" "0x${GWHEX:2:2}" "0x${GWHEX:0:2}") + echo "OPENWAF_EDGE_HOST=$GW" >> "$GITHUB_ENV" + echo "the gate will ask the edge at $GW" + + # Brings up edge + nginx, waits for the image's own HEALTHCHECK, asserts + # over a socket, and tears the stack down on exit. + - name: Compose smoke — the scratch image + env: + # The CI overlay: the upstream config comes from the volume the step + # above filled. Compose reads COMPOSE_FILE itself, so the gate script + # stays the one an operator runs. + COMPOSE_FILE: docker-compose.yml:docker-compose.ci.yml + # Its own compose project and its own host port. The console job below + # brings up the same file, and on any machine where two jobs share one + # docker daemon (a self-hosted runner, a local act run) the default + # project name and the default 8080 make them the same stack: one + # job's `compose down` is the other's connection refused. Measured, not + # guessed — see the comment in docker-compose.yml. + COMPOSE_PROJECT_NAME: openwafci-scratch + EDGE_PORT: "8081" + EDGE: http://${{ env.OPENWAF_EDGE_HOST }}:8081 + run: ./scripts/ci-gates.sh scratch-smoke + + - name: README assertion counts match what the gate ran + run: ./scripts/ci-gates.sh readme-counts scripts/compose-smoke.sh + # The console is a page, and a page fails in ways curl cannot see: a typo in # the inline script, a fetch that 401s, a table that renders nothing while the # summary looks fine. This drives it in a real Chromium. diff --git a/Dockerfile b/Dockerfile index c231c90..9ee0d25 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,9 +6,18 @@ # 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 and then emitted -# uncompilable C# for every entity materialisation. scripts/aot-probe.sh -# reproduces the verdict in one command; docs/ARCHITECTURE.md carries the numbers. +# 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 diff --git a/Dockerfile.scratch b/Dockerfile.scratch new file mode 100644 index 0000000..5d84084 --- /dev/null +++ b/Dockerfile.scratch @@ -0,0 +1,163 @@ +# syntax=docker/dockerfile:1.7 +# +# openwaf edge — FROM scratch: no base image, no package manager, no shell, no +# distro. The only things in the runtime layer are this program, the shared +# objects it was linked against, the CA bundle it needs to verify an upstream's +# certificate, and the geo database. +# +# What "FROM scratch" actually costs, measured rather than assumed: the runtime +# has no OS to borrow libraries from, so every shared object has to be carried +# in. They are resolved with ldd inside the build stage and copied at their +# absolute paths — the ELF interpreter (/lib64/ld-linux-x86-64.so.2 on x86-64) +# is recorded inside the apphost, so it must land at exactly that path or the +# kernel refuses to start the process. ldd cannot see what a program dlopen()s, +# so the NSS modules getaddinfo() uses to turn "upstream" into an address are +# added by name; without them the compose upstream by service name resolves to +# nothing and every request is a 502. +# +# Why self-contained and not NativeAOT, measured on this tree on 2026-10-06: +# the AOT build compiles and its binary creates its own schema, then refuses +# every EF query ("Query wasn't precompiled and dynamic code isn't supported +# with NativeAOT"), and EF 10.0.12's precompile-queries generator cannot produce +# code for this model — it refuses Contains over a captured collection, refuses +# any method parameter inside a query, throws NullReferenceException on an +# ExecuteUpdate set-list, and for the queries it does accept emits an invalid +# declaration per entity materialisation +# ("var openWaf.Domain.Security.BlockEntryPrimaryKeyProperties = …"). +# scripts/aot-probe.sh reproduces the runtime half; docs/ARCHITECTURE.md carries +# the numbers. A static binary is the right shape for this image, and EF is the +# thing standing in the way, not the Dockerfile. +# +# Stages: +# 1. restore – NuGet layer, cached independently of source changes +# 2. build – self-contained publish for the build architecture, plus the +# /rootfs tree of shared objects the runtime layer will need +# 3. geoip – the database, downloaded by a static curl image +# 4. runtime – scratch + +ARG DOTNET_VERSION=10.0 +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/ ./ +# Predefined ARGs are only substituted in a stage that declares them. +ARG TARGETARCH +# TARGETARCH is supplied by BuildKit; the RID is spelled out from it because +# --self-contained needs one and a scratch layer cannot make up for a wrong one. +RUN case "${TARGETARCH}" in \ + amd64) RID=linux-x64 ;; \ + arm64) RID=linux-arm64 ;; \ + *) printf 'no self-contained RID for architecture %s\n' "${TARGETARCH}" >&2; exit 1 ;; \ + esac && \ + printf 'self-contained RID: %s\n' "$RID" && \ + dotnet publish OpenWaf.Edge/OpenWaf.Edge.csproj \ + -c Release \ + -r "$RID" \ + --self-contained true \ + -p:DebugType=none \ + -p:DebugSymbols=false \ + -o /publish/api \ + && cd /publish/api \ + && rm -f *.pdb \ + && rm -rf BuildHost-net472 BuildHost-netcore + +# The runtime layer's /usr, /lib and /etc, assembled from what the apphost and +# the runtime's own shared objects were linked against. +RUN set -eu; \ + mkdir -p /rootfs; \ + copy_at_path() { \ + mkdir -p "/rootfs$(dirname "$1")"; \ + cp -L "$1" "/rootfs$1"; \ + }; \ + # Every absolute path ldd prints, not just the "name => /path" ones: the + # dynamic loader is printed as a bare "/lib/ld-linux-aarch64.so.1 (0x...)" + # line with no arrow, and filtering on the arrow drops exactly the one file + # the kernel needs to start the process. Measured: the first scratch image + # built here started with `exec /app/api/OpenWaf.Edge: no such file or + # directory` — the ENOENT the kernel reports for a missing interpreter. + { ldd /publish/api/OpenWaf.Edge; \ + find /publish/api -name '*.so' -print0 | xargs -0 ldd; } 2>/dev/null \ + | awk '{ for (i = 1; i <= NF; i++) if ($i ~ /^\//) print $i }' \ + | sort -u > /needed.txt; \ + printf 'loader line: %s\n' "$(grep -c 'ld-linux' /needed.txt)"; \ + # ldd also lists the kernel's vdso (/dev/vdso/…), which is not a file to + # carry; anything it names that is not a regular file is skipped. + while read -r lib; do [ -f "$lib" ] || continue; copy_at_path "$lib"; done < /needed.txt; \ + # dlopen(), so no ldd of anything here shows them: OpenSSL, which + # libSystem.Security.Cryptography.Native.OpenSsl.so probes at first TLS use + # (measured: an image without them starts, warms up, and then answers + # "No usable version of libssl was found" and never turns healthy), and + # getaddrinfo's name-service modules. + for mod in files dns; do \ + for f in /lib/*/libnss_${mod}.so.2 /usr/lib/*/libnss_${mod}.so.2; do \ + [ -e "$f" ] && copy_at_path "$f"; \ + done; \ + done; \ + for mod in ssl crypto; do \ + for f in /lib/*/lib${mod}.so.3 /usr/lib/*/lib${mod}.so.3; do \ + [ -e "$f" ] && copy_at_path "$f"; \ + done; \ + done; \ + # The CA bundle: an https upstream or an https alert webhook verifies a + # certificate, and a scratch image has no /etc/ssl to verify against. + copy_at_path /etc/ssl/certs/ca-certificates.crt; \ + printf 'shared objects carried: %s\n' "$(find /rootfs/lib /rootfs/lib64 -type f 2>/dev/null | wc -l)"; \ + printf 'rootfs bytes: %s\n' "$(du -sk /rootfs | cut -f1)" + +RUN mkdir -p /publish/data + +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 + +# No base image at all. Numeric user: there is no /etc/passwd to look a name up +# in, and the volume mount points are staged with that ownership because there +# is no shell here to mkdir with at start-up. +FROM scratch +# WORKDIR is not cosmetic here. A self-contained apphost takes its content root +# from the process's working directory, and a scratch image has no WORKDIR, so +# without this the process starts in / and never finds appsettings.json next to +# it: the reverse proxy then has no routes and every request that should reach +# the upstream answers the edge's own 404. Measured — the first scratch image +# that passed its own HEALTHCHECK still failed 7 of the 368 compose assertions +# for exactly this reason, and the edge said it in its own log: "Request reached +# the end of the middleware pipeline without being handled by application code." +WORKDIR /app/api +COPY --from=build /rootfs/ / +COPY --from=build --chown=1654:1654 /publish/api /app/api +COPY --from=build --chown=1654:1654 /publish/data /app/data +COPY --from=geoip --chown=1654:1654 /tmp/geoip /app/geoip + +USER 1654:1654 + +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 + +# The binary is the only probe available — there is no shell, no wget, no curl, +# and not even a coreutils `true` to fall back on. +HEALTHCHECK --interval=30s --timeout=5s --retries=3 --start-period=10s \ + CMD ["/app/api/OpenWaf.Edge", "--healthcheck"] + +ENTRYPOINT ["/app/api/OpenWaf.Edge"] diff --git a/README.md b/README.md index 4a0dd21..7eebed6 100644 --- a/README.md +++ b/README.md @@ -333,6 +333,41 @@ after a rebuild**. Measured on 2026-10-01: the same rebuilt image reported `docker volume rm openwaf_openwaf-geoip`. That is the command to reach for when the pin moves. +### Two images, one program, and the same 368 assertions against both + +`Dockerfile` ships the edge on `aspnet:10.0-noble-chiseled`: a distroless +runtime, no shell, no package manager. `Dockerfile.scratch` ships the same +program on **nothing at all** — no base image, no distro, no shell — and carries +the shared objects itself: the ones `ldd` reports, the dynamic loader (the kernel +looks for it at the path recorded inside the binary, so it has to land at exactly +that path), the NSS modules `getaddrinfo` dlopen()s, OpenSSL, and the CA bundle. + +Measured on this tree on 2026-10-06, one host, arm64: chiseled **262 MB**, +scratch **222 MB**, of which 12 shared objects and a CA bundle make **18.7 MB**. +`scripts/compose-smoke.sh` runs unchanged against either one — the only change is +the `docker-compose.scratch.yml` override — and both answer **368 passed, +0 failed**. + +The assertions are the reason the second Dockerfile is worth having, and the +first scratch image built here is the reason they were needed: 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 started 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 the `/boom` 502 the "server errors alert, they never ban" scene is +built on, which turned that 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."* A healthy container was not a working edge. + +``` +scripts/ci-gates.sh scratch-image # build it, print both images' sizes +scripts/ci-gates.sh scratch-smoke # the 368, against it +``` + +Not measured here: the linux-x86-64 scratch image. The `scratch-image` CI job +builds it on the runner, and that run is where the amd64 number will come from. + ## Schema Migrations are the schema of record for PostgreSQL, which is the provider a @@ -1688,7 +1723,8 @@ calls the same script one gate per step, so a local green run and a CI green run cannot mean different things. ``` -scripts/ci-gates.sh all # restore, build, unit, integration, smoke, image, compose-smoke +scripts/ci-gates.sh all # restore, build, unit, integration, smoke, both images, both smokes +scripts/ci-gates.sh scratch-smoke # the 368, against the image with no base scripts/ci-gates.sh unit # or any one gate on its own scripts/ci-gates.sh console # the page, in a real Chromium (not part of `all`) ``` diff --git a/docker-compose.scratch.yml b/docker-compose.scratch.yml new file mode 100644 index 0000000..05b611e --- /dev/null +++ b/docker-compose.scratch.yml @@ -0,0 +1,9 @@ +# Run the production smoke against the scratch image instead of the chiseled one: +# docker compose -f docker-compose.yml -f docker-compose.scratch.yml up -d --build +# Everything else — ports, env, volumes, the nginx upstream — is the shipped +# stack, so the assertions in scripts/compose-smoke.sh are the same 368. +services: + edge: + build: + context: . + dockerfile: Dockerfile.scratch diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index 9793ce0..03f7054 100644 --- a/docs/ARCHITECTURE.md +++ b/docs/ARCHITECTURE.md @@ -47,13 +47,36 @@ classifies the status, and is the only thing that can create an engine ban. binary, and the only alternative, `dotnet ef dbcontext optimize --precompile-queries`, first refused 40 of this tree's queries (parameter-symbol roots and captures, dotnet/efcore#35887 / #38030 / #35494, fixed only in the - 12.0-preview1 line) and, after every one of them was rewritten into a shape it - accepts, emitted 14 declarations with dots in the identifier - (`var openWaf.Domain.Security.BlockEntryPrimaryKeyProperties = …`) — 28 CS1002 - and CS1003 errors, for every entity materialisation in the model. Reproduce with - `scripts/aot-probe.sh`. The query rewrites that attempt required are kept: they - are behaviour-identical (378 unit, 405 integration, 256 smoke at the same commit) - and they are the precondition for trying again when EF's precompiler is fixed. + 12.0-preview1 line). Four refusals remain, and they are not a style to rewrite + around — they are four shapes the 10.0.12 generator cannot translate at all, + each measured with its own exception: + + * `Contains` over a captured collection — a `List` local dies in + `SqlConstantExpression.Quote()` with `ArgumentException: Argument types do not + match`; an array is worse, `Expression of type 'System.Int64[]' cannot be used + for parameter of type 'System.ReadOnlySpan\`1[System.Int64]'`; + * **any method parameter referenced inside a query**, down to the + `CancellationToken` — `UnreachableException: IdentifierName of type + ParameterSymbol: token`. Only locals declared in the querying method work; + * an `ExecuteUpdateAsync` set-list — `NullReferenceException` in + `ExpressionTreeFuncletizer.VisitUnary`, reached from + `PrecompiledQueryCodeGenerator.ProcessCapturedVariables`, whether the value is + a cast literal or a nullable local; + * a literal whose type is not the column's — `p.AlertId >= 0` against a `long` + throws `ArgumentException: Argument types do not match` in + `CSharpToLinqTranslator.VisitLiteralExpression`; `0L` is accepted. + + With those two alert-queue queries taken out the generator reports **0 + precompilation errors** and writes 8 interceptor files — and 14 of their + declarations have dots in the identifier + (`var openWaf.Domain.Security.BlockEntryPrimaryKeyProperties = …`), because the + local is named from the entity type's full name: 28 CS1002 and CS1003 errors, + one pair per entity materialisation in the model. So the wall is EF's + precompiler and its code generator, twice over, not this tree's code. Reproduce + the runtime half with `scripts/aot-probe.sh`. The query rewrites that attempt + required are kept: they are behaviour-identical (378 unit, 405 integration, + 256 smoke at the same commit) and they are the precondition for trying again + when EF's precompiler is fixed. * **Keying the ban on ip+UA** (as the analytics `SessionHash` does): a bot that varies its UA multiplies into many sources and never reaches the threshold. * **Banning on 5xx because the original wording said `> 400`**: turns an outage diff --git a/scripts/ci-gates.sh b/scripts/ci-gates.sh index 3d95875..32341c1 100755 --- a/scripts/ci-gates.sh +++ b/scripts/ci-gates.sh @@ -4,7 +4,8 @@ # the job log still names the gate that failed; `all` runs them in order and # stops at the first failure. # -# scripts/ci-gates.sh restore|build|unit|integration|schema-script|smoke|image|compose-smoke|all +# scripts/ci-gates.sh restore|build|unit|integration|schema-script|smoke +# scripts/ci-gates.sh image|scratch-image|compose-smoke|scratch-smoke|all # scripts/ci-gates.sh console (needs a real Chromium; not part of `all`) # scripts/ci-gates.sh readme-counts scripts/ (compares the README's # assertion count with what that gate printed @@ -58,8 +59,15 @@ schema_script() { local committed=dotnet/OpenWaf.Infrastructure/Persistence/Schema/schema.sqlite.sql local regenerated regenerated="$(mktemp)" - if ! dotnet tool restore >/dev/null 2>&1; then - printf 'the pinned dotnet-ef tool could not be restored: cannot check the schema script\n' >&2 + # --tool-manifest: the manifest lives in dotnet/, and `dotnet tool restore` + # from the repo root finds no manifest, prints "No tools were restored." and + # still exits 0 — measured on the runner at 7c5e1ef, where the gate then died + # on "Run \"dotnet tool restore\" to make the \"dotnet-ef\" command available." + # A successful restore is therefore checked by asking the tool for its version, + # not by trusting the restore's exit code. + if ! dotnet tool restore --tool-manifest dotnet/dotnet-tools.json >/dev/null 2>&1 \ + || ! (cd dotnet && dotnet ef --version) >/dev/null 2>&1; then + printf 'the pinned dotnet-ef tool is not available: cannot check the schema script\n' >&2 return 2 fi # OPENWAF_MIGRATE_PROVIDER=sqlite: the design-time factory defaults to postgres, @@ -87,6 +95,27 @@ image() { banner image; docker build -t openwaf:ci .; docker ima compose_smoke() { banner compose-smoke; ./scripts/compose-smoke.sh; } +# The same program on a base of nothing at all: scratch, plus the shared objects +# it was linked against, plus the CA bundle. Its size is printed next to the +# chiseled one's because the difference between the two is the claim being made. +scratch_image() { + banner scratch-image + docker build -f Dockerfile.scratch -t openwaf-scratch:ci . + # One argument per `docker image ls` — two is a usage error, exit 1. The + # chiseled line prints nothing in a job that never built it (the scratch job + # is its own job), which is why it is a separate call rather than a failure. + docker image ls --format 'scratch {{.Repository}}:{{.Tag}} {{.Size}}' openwaf-scratch:ci + docker image ls --format 'chiseled {{.Repository}}:{{.Tag}} {{.Size}}' openwaf:ci +} + +# The production smoke, unchanged, against the scratch image. COMPOSE_FILE is +# appended to rather than replaced, so a caller that already names the CI +# overlay (the workflow does) keeps it and gains only the dockerfile swap. +scratch_smoke() { + banner scratch-smoke + COMPOSE_FILE="${COMPOSE_FILE:-docker-compose.yml}:docker-compose.scratch.yml" ./scripts/compose-smoke.sh +} + # The browser gate over the operator page. It is a gate, so it lives here too and # CI calls it by the same name. It is NOT part of `all`: it needs a real # Chromium, and a machine without one exits 2 ("cannot run"), which is a @@ -227,7 +256,9 @@ case "${1:-all}" in smoke) smoke ;; schema-script) schema_script ;; image) image ;; + scratch-image) scratch_image ;; compose-smoke) compose_smoke ;; + scratch-smoke) scratch_smoke ;; console) console ;; lint) lint ;; readme-counts) readme_counts "${2:-}" ;; @@ -237,6 +268,10 @@ case "${1:-all}" in # same invocation. export GATE_TOTALS_DIR="${GATE_TOTALS_DIR:-$(mktemp -d)}" restore; build; unit; integration; schema-script; smoke; image; compose_smoke + # The scratch image and the same 368 assertions against it. It is in `all` + # because it is the shipped shape, not an experiment: the only difference a + # caller can see is what is under the program. + scratch_image; scratch_smoke # The two gates `all` actually ran. console is not among them, so its README # number is verified by the console job (or by an operator who ran it and # then calls readme-counts with the same GATE_TOTALS_DIR).