Files
openwaf/Dockerfile
T
Pavlo Ratushnyi 66df999cdf The country table got a shape, and the page caught me colliding with itself
The console's country view was a column of numbers. "Where is this traffic
coming from" is a comparison, so each row now carries a bar sized against the
busiest country, and the table says what it counted. No tiles, no CDN, no asset
file: the runtime image is distroless and the page has to work at the moment the
site in front of it is being attacked. A geographic map is still not here and
the README now says why plainly — the admin API exposes counts per ISO code, not
coordinates, and an outline drawn from memory would be decoration that misleads.

The first run after the change failed, for a real reason: the class I added was
`.bar`, and the page already had a `.bar` — the toolbar. The toolbar collapsed
to 0.55em tall, `div#summary` started intercepting pointer events, and every
assertion after the token click died on a click timeout. Renamed to
`.sharebar`.

The gate itself got the same treatment as the page. It used to leave a reviewer
with nothing but a stack trace; now it writes a screenshot both when the page
cannot be driven at all and when it is driven and wrong. That path was checked
by making it red on purpose: with seeds that do not match the stack it exits 1
naming 3 failed assertions and writes a 105078-byte picture.

Measured, not assumed, in the same pass:

- `ci-gates.sh` gained a `console` gate and the workflow calls it by that name
  instead of retyping the script: one definition, two callers. It is
  deliberately NOT in `all` — without a Chromium the gate exits 2 ("cannot
  run"), which is a different answer from 1 ("the page is wrong"), and folding
  it in would make the one-command entry point unrunnable off a CI runner.
- `ci-gates.sh all` no longer stops at the last gate for want of an admin
  token: it was dying at compose-smoke with `OPENWAF_ADMIN_TOKEN: set …` before
  it could print a verdict. The throwaway for the stack the gate starts and
  tears down itself is defaulted there; the standalone scripts still refuse to
  invent one, because run by hand they can be pointed at a real deployment.
- The console job publishes the desktop and phone screenshots as artifacts,
  with `if: always()` so the failure case is the one you can look at. The
  relative SCREENSHOT path and the `console-evidence*.png` glob were verified
  locally: 107935 and 86179 bytes written.
- DBIP_VERSION 2026-09 -> 2026-10. Not a cache hit: 8348509 bytes fetched,
  image 261 MB, compose smoke 27/27 afterwards.
- The trap that bump exposes, measured rather than reasoned about: the same
  rebuilt image reported `geoBuiltAt: 2026-09-01T01:32:45Z` against the
  existing `openwaf_openwaf-geoip` volume and `2026-10-01T01:36:12Z` after
  removing it. Docker seeds a named volume from the image only when the volume
  is first created, so a rebuild alone never replaces the geo database.

Gates on this commit: build 0 warnings / 0 errors, unit 54/54, integration
27/27, smoke 19/19, image 261 MB, compose-smoke 27/27, console 16/16 (desktop
bar 513 px inside a 529 px cell; phone pass at 375 px in dark mode: scrollWidth
375, status contrast 11.85:1, bars 67 px), actionlint 0, shellcheck 0. Still
true, and unchanged by any of the above: not one of these jobs has run on a
runner, because the repository has no remote.
2026-10-01 14:26:33 +02:00

114 lines
5.4 KiB
Docker
Raw 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: the reference deployment (~/work/neemle/landing) tried it
# and recorded the reason in its Dockerfile — EF Core under AOT needs every LINQ
# query precompiled and every request/response shape annotated, and the size win
# washes out against the chiseled runtime base. Not relitigated here.
#
# 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) so a
# stale one is visible at runtime, not only at build time. Bumping this argument
# on a schedule from CI is NOT implemented — the pin was moved by hand to
# 2026-10 on 2026-10-01, and the month before that it was 2026-09.
#
# 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"]