diff --git a/frameworks/_shared/authsvc/Dockerfile b/frameworks/_shared/authsvc/Dockerfile index bd5ecae961..d8173a283b 100644 --- a/frameworks/_shared/authsvc/Dockerfile +++ b/frameworks/_shared/authsvc/Dockerfile @@ -10,15 +10,27 @@ RUN apk add --no-cache musl-dev pkgconfig # Prime the dep cache: build against an empty main.rs so cargo downloads # and compiles the dependency graph once. Actual src/ changes below don't # invalidate this layer. +# +# `cargo clean -p authsvc` then drops the placeholder's own artifacts, and only +# those, wherever this cargo keeps them. This step used to delete +# target/release/deps/authsvc* by hand. Cargo 1.100 moved each package's +# artifacts to target/release/build///, the glob stopped +# matching, and the build below found the placeholder up to date and shipped +# it: an authsvc that exits 0 at once without a word, so every +# production-stack run failed before measuring anything. COPY Cargo.toml . RUN mkdir src && echo 'fn main() {}' > src/main.rs && \ cargo build --release && \ - rm -rf src target/release/deps/authsvc* + cargo clean --release -p authsvc && \ + rm -rf src -# Now add the real source and rebuild. +# Now add the real source and rebuild. The grep fails the build if the +# placeholder is ever shipped again: the server's startup line is in the +# real binary and nowhere in the empty one. COPY src ./src RUN cargo build --release && \ - strip target/release/authsvc + strip target/release/authsvc && \ + grep -q "authsvc listening on" target/release/authsvc FROM alpine:3.20 # ca-certificates are needed if authsvc ever connects to something over diff --git a/frameworks/aspnet-minimal_caddy/Dockerfile b/frameworks/aspnet-minimal_caddy/Dockerfile index 51f9a0698c..44ba3473ed 100644 --- a/frameworks/aspnet-minimal_caddy/Dockerfile +++ b/frameworks/aspnet-minimal_caddy/Dockerfile @@ -2,13 +2,14 @@ FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build WORKDIR /app # Copy project file and shared source from aspnet-minimal. We reuse the -# same Handlers/AppData/Models as aspnet-minimal_nginx — the only thing -# specific to this entry is the Caddy proxy config. +# same Handlers and the Services/Types they are written against as +# aspnet-minimal_nginx — the only thing specific to this entry is the Caddy +# proxy config. COPY frameworks/aspnet-minimal_caddy/aspnet-minimal_caddy.csproj . COPY frameworks/aspnet-minimal_caddy/Program.cs . COPY frameworks/aspnet-minimal/Handlers.cs . -COPY frameworks/aspnet-minimal/AppData.cs . -COPY frameworks/aspnet-minimal/Models.cs . +COPY frameworks/aspnet-minimal/Services ./Services +COPY frameworks/aspnet-minimal/Types ./Types RUN dotnet publish -c Release -o out diff --git a/frameworks/aspnet-minimal_caddy/Program.cs b/frameworks/aspnet-minimal_caddy/Program.cs index 16e1e4648e..1195328e1b 100644 --- a/frameworks/aspnet-minimal_caddy/Program.cs +++ b/frameworks/aspnet-minimal_caddy/Program.cs @@ -1,8 +1,20 @@ +using HttpArena.Services; +using HttpArena.Types; + using Microsoft.AspNetCore.Server.Kestrel.Core; var builder = WebApplication.CreateBuilder(args); builder.Logging.ClearProviders(); +// The handlers are aspnet-minimal's, written against its services; they are +// registered here the way aspnet-minimal registers them. +builder.Services.ConfigureHttpJsonOptions(o => + o.SerializerOptions.TypeInfoResolverChain.Insert(0, AppJsonContext.Default)); + +builder.Services.AddSingleton(); +builder.Services.AddSingleton(); +builder.Services.AddSingleton(); + builder.WebHost.ConfigureKestrel(options => { options.ListenAnyIP(8080, lo => @@ -13,7 +25,10 @@ var app = builder.Build(); -AppData.Load(); +// Load the dataset and open the Postgres pool at startup instead of on the +// first request. +_ = app.Services.GetRequiredService(); +_ = app.Services.GetRequiredService(); app.MapGet("/baseline2", Handlers.Sum); app.MapGet("/json/{count}", Handlers.Json); diff --git a/frameworks/aspnet-minimal_caddy/aspnet-minimal_caddy.csproj b/frameworks/aspnet-minimal_caddy/aspnet-minimal_caddy.csproj index 2fbebb32af..f675f10348 100644 --- a/frameworks/aspnet-minimal_caddy/aspnet-minimal_caddy.csproj +++ b/frameworks/aspnet-minimal_caddy/aspnet-minimal_caddy.csproj @@ -8,5 +8,6 @@ + diff --git a/frameworks/aspnet-minimal_nginx/Dockerfile b/frameworks/aspnet-minimal_nginx/Dockerfile index 77bed4dc41..f454c57bdb 100644 --- a/frameworks/aspnet-minimal_nginx/Dockerfile +++ b/frameworks/aspnet-minimal_nginx/Dockerfile @@ -1,12 +1,13 @@ FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build WORKDIR /app -# Copy project file and shared source from aspnet-minimal +# Copy project file and shared source from aspnet-minimal: its Handlers and +# the Services/Types they are written against COPY frameworks/aspnet-minimal_nginx/aspnet-minimal_nginx.csproj . COPY frameworks/aspnet-minimal_nginx/Program.cs . COPY frameworks/aspnet-minimal/Handlers.cs . -COPY frameworks/aspnet-minimal/AppData.cs . -COPY frameworks/aspnet-minimal/Models.cs . +COPY frameworks/aspnet-minimal/Services ./Services +COPY frameworks/aspnet-minimal/Types ./Types RUN dotnet publish -c Release -o out diff --git a/frameworks/aspnet-minimal_nginx/Program.cs b/frameworks/aspnet-minimal_nginx/Program.cs index f7079585b1..36c02a7277 100644 --- a/frameworks/aspnet-minimal_nginx/Program.cs +++ b/frameworks/aspnet-minimal_nginx/Program.cs @@ -1,4 +1,6 @@ using System.Text.Json; +using HttpArena.Services; +using HttpArena.Types; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.HttpResults; using Microsoft.AspNetCore.Server.Kestrel.Core; @@ -9,6 +11,15 @@ var builder = WebApplication.CreateBuilder(args); builder.Logging.ClearProviders(); +// The gateway handlers are aspnet-minimal's, written against its services; +// they are registered here the way aspnet-minimal registers them. +builder.Services.ConfigureHttpJsonOptions(o => + o.SerializerOptions.TypeInfoResolverChain.Insert(0, AppJsonContext.Default)); + +builder.Services.AddSingleton(); +builder.Services.AddSingleton(); +builder.Services.AddSingleton(); + builder.WebHost.ConfigureKestrel(options => { options.ListenAnyIP(8080, lo => @@ -67,7 +78,11 @@ var app = builder.Build(); -AppData.Load(); +// Load the dataset and open the Postgres pool at startup instead of on the +// first request. The /api routes below run their queries on the same pool. +_ = app.Services.GetRequiredService(); +_ = app.Services.GetRequiredService(); +var pg = app.Services.GetRequiredService().Postgres; // ── gateway-64 routes (unchanged) ─────────────────────────────────────────── @@ -133,9 +148,9 @@ async cancel => { wasMiss = true; - if (AppData.PgDataSource is null) return ""; + if (pg is null) return ""; - await using var cmd = AppData.PgDataSource.CreateCommand( + await using var cmd = pg.CreateCommand( "SELECT id, name, category, price, quantity, active, rating_score, rating_count " + "FROM items WHERE id = $1 LIMIT 1"); cmd.Parameters.AddWithValue(id); @@ -195,13 +210,13 @@ return; } - if (AppData.PgDataSource is null) + if (pg is null) { ctx.Response.StatusCode = 503; return; } - await using var cmd = AppData.PgDataSource.CreateCommand( + await using var cmd = pg.CreateCommand( "UPDATE items SET name = $1, price = $2, quantity = $3 WHERE id = $4"); cmd.Parameters.AddWithValue(update.Name); cmd.Parameters.AddWithValue(update.Price); @@ -242,9 +257,9 @@ async cancel => { wasMiss = true; - if (AppData.PgDataSource is null) return ""; + if (pg is null) return ""; - await using var cmd = AppData.PgDataSource.CreateCommand( + await using var cmd = pg.CreateCommand( "SELECT id, name, email, plan FROM users WHERE id = $1 LIMIT 1"); cmd.Parameters.AddWithValue(uid); diff --git a/frameworks/aspnet-minimal_nginx/README.md b/frameworks/aspnet-minimal_nginx/README.md index 01f1f08abd..485fe81224 100644 --- a/frameworks/aspnet-minimal_nginx/README.md +++ b/frameworks/aspnet-minimal_nginx/README.md @@ -87,4 +87,4 @@ Empirically tuned for this entry: - `libgssapi-krb5-2` installed in the runtime image — required by `StackExchange.Redis` for TLS/auth layer initialization (crashes without it even on plain TCP) - Routes behind `/api/*` are only registered when `REDIS_URL` is set (guarded by `if (!string.IsNullOrWhiteSpace(redisUrl))`) — otherwise ASP.NET's endpoint builder fails to resolve `HybridCache` as a DI dependency and every route returns 500 - Postgres runs on tmpfs (`--tmpfs /var/lib/postgresql/data`) for write performance -- Shares `Handlers.cs`, `AppData.cs`, `Models.cs` from `aspnet-minimal/` via Dockerfile COPY +- Shares `Handlers.cs`, `Services/` and `Types/` from `aspnet-minimal/` via Dockerfile COPY diff --git a/scripts/validate.sh b/scripts/validate.sh index f10af4413c..09a3719c5f 100755 --- a/scripts/validate.sh +++ b/scripts/validate.sh @@ -2469,6 +2469,26 @@ if has_test "echo-ws" || has_test "echo-ws-pipeline" || has_test "echo-ws-limite fi fi +# ───── Hand the host's ports to the compose stacks ───── +# +# Any compose profile puts the standalone container on --network host (see +# docker_args above), and nothing stopped it before the stacks below came up. +# It keeps 8080 and, for an entry with an h2 or h3 profile, 8443: the ports +# the stack's server and edge bind. The edge then failed to bind, shared +# localhost with the standalone server, or (with h3 enabled) exited on the +# QUIC port, and the checks below described whichever process answered. The +# gateway checks can pass against a server with no proxy in front of it, and +# production-stack fails its auth wall, which the edge enforces and the +# server does not. libuvcpp works around it in the entry (main.cc, near +# init_database, and proxy-production/nginx.conf). +# +# Stopped rather than removed so the final dump_logs can still inspect it; the +# EXIT trap removes it. +if [ "$GATEWAY_ONLY" = "false" ] && { has_test "gateway-64" || has_test "gateway-h3" || has_test "production-stack"; }; then + echo "[compose] stopping $CONTAINER_NAME: the compose stacks bind the same host ports" + docker stop "$CONTAINER_NAME" >/dev/null 2>&1 || true +fi + # ───── Gateway profiles (reverse proxy + server, shared validation flow) ───── # # Both gateway-64 (h2) and gateway-h3 (h3 at the edge) use the same endpoint