Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions frameworks/_shared/authsvc/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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/<package>/<hash>/, 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
Expand Down
9 changes: 5 additions & 4 deletions frameworks/aspnet-minimal_caddy/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
17 changes: 16 additions & 1 deletion frameworks/aspnet-minimal_caddy/Program.cs
Original file line number Diff line number Diff line change
@@ -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<DatabaseService>();
builder.Services.AddSingleton<DatasetService>();
builder.Services.AddSingleton<ItemService>();

builder.WebHost.ConfigureKestrel(options =>
{
options.ListenAnyIP(8080, lo =>
Expand All @@ -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<DatasetService>();
_ = app.Services.GetRequiredService<ItemService>();

app.MapGet("/baseline2", Handlers.Sum);
app.MapGet("/json/{count}", Handlers.Json);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
<ItemGroup>
<PackageReference Include="Microsoft.Data.Sqlite" Version="10.0.5" />
<PackageReference Include="Npgsql" Version="10.0.2" />
<PackageReference Include="StackExchange.Redis" Version="3.0.17" />
</ItemGroup>
</Project>
7 changes: 4 additions & 3 deletions frameworks/aspnet-minimal_nginx/Dockerfile
Original file line number Diff line number Diff line change
@@ -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

Expand Down
29 changes: 22 additions & 7 deletions frameworks/aspnet-minimal_nginx/Program.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<DatabaseService>();
builder.Services.AddSingleton<DatasetService>();
builder.Services.AddSingleton<ItemService>();

builder.WebHost.ConfigureKestrel(options =>
{
options.ListenAnyIP(8080, lo =>
Expand Down Expand Up @@ -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<DatasetService>();
_ = app.Services.GetRequiredService<ItemService>();
var pg = app.Services.GetRequiredService<DatabaseService>().Postgres;

// ── gateway-64 routes (unchanged) ───────────────────────────────────────────

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion frameworks/aspnet-minimal_nginx/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
20 changes: 20 additions & 0 deletions scripts/validate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading