Relay docs

Deployment

Relay is three ASP.NET Core apps (gateway API, control-panel host, and this docs site) plus SQL Server, and optionally ClickHouse/ClickStack and Qdrant. The .NET Aspire AppHost is a local-development orchestrator only and is not deployed.

There are two deployment paths, and both are live for now:

PathWorkflowTriggerTarget
Docker on a Linux VMdeploy-vm.ymlmanual (Actions → Deploy to Azure VM → Run workflow)three containers on an Azure VM, behind the VM's Caddy
IISdeploy_api.yml, deploy_app.yml, deploy_docs.ymlpush to dev (test) or main (prod)IIS sites on a self-hosted runner

The database schema (DACPAC) and the configuration rules further down apply to both.

#Docker on a Linux VM

#How it fits together

GitHub Actions ──build──▶ Azure Container Registry  (relay-panel, relay-gateway, relay-docs : <sha> and :latest)
                            │  pulled by the VM with its managed identity
                            ▼
VM:  Caddy :80/:443 ─┬▶ 127.0.0.1:2002 ──▶ panel   ─┐
                     ├▶ 127.0.0.1:2003 ──▶ gateway ─┼─▶ SQL Server, ClickHouse, Qdrant
                     └▶ 127.0.0.1:2004 ──▶ docs     │
                        (docker compose in /app/relay; the panel reaches the gateway at gateway:2003)

The VM's own Caddy (a system service, shared with other apps on the VM) terminates TLS and proxies each host name to a container listening on 127.0.0.1 only. The three containers are one Docker Compose project named relay, with the services panel, gateway and docs. All three images are built from the root Dockerfile and always run the same image tag, so a panel and a gateway from different builds never run side by side.

#Deploying a new version

Run Deploy to Azure VM from the repository's Actions tab, on main. The workflow:

  1. Builds the three images and pushes them to the registry, tagged with the first 12 characters of the commit SHA and with latest.
  2. Copies deploy/docker-compose.yml to /app/relay on the VM.
  3. Checks that both settings files exist on the VM, and stops if one is missing.
  4. Writes ACR_LOGIN_SERVER and IMAGE_TAG into /app/relay/.env, then runs docker compose pull and docker compose up -d --remove-orphans, and prunes unused images.
  5. Smoke-tests the gateway's /health, the panel and the docs site through their public host names for about two minutes.

The deploy uses the production GitHub environment, so required reviewers can be added there. Two deploys never run at once: a second one waits for the first. Publish the DACPAC first if the build expects new columns (see below). The workflow does not touch the database.

#Files on the VM

Everything lives in /app/relay:

FileWhat it isWho writes it
docker-compose.ymlthe three servicesevery deploy (overwritten)
.envACR_LOGIN_SERVER and IMAGE_TAGevery deploy (those two keys only; other keys are kept)
panel.appsettings.jsonthe panel's configuration and secretsby hand, once, from deploy/panel.settings.example.json
gateway.appsettings.jsonthe gateway's configuration and secretsby hand, once, from deploy/gateway.settings.example.json

The two settings files are mounted read-only into their containers as appsettings.Production.json. No appsettings*.json is baked into any image. Both files are owned by uid 1654 (the non-root user inside the containers) with mode 400, so you need sudo to read or edit them. The docs container has no configuration.

The panel's sign-in key ring (auth cookies, antiforgery) is on the Docker volume relay_panel-keys. Losing it signs everyone out of the panel once. Nothing else is stored on disk; the gateway keeps no local state.

#Running commands on the VM

SSH to the VM, then run every docker compose command from /app/relay so Compose finds the project and its .env:

cd /app/relay

Prefix the commands with sudo if your user is not in the docker group.

#Checking status and logs

docker compose ps
docker compose logs -f gateway

Use panel or docs in place of gateway, or leave the service out to follow all three. Add --since 10m or --tail 200 to limit the output. Logs are capped at 5 files of 10 MB per container, so older output rotates away.

#Restarting

Restart one container:

docker compose restart gateway

Restart all three:

docker compose restart

restart stops and starts the existing container, with the same image and the same Compose settings. It does re-read the mounted settings files, because the app reads them at startup. It does not pick up changes to .env or docker-compose.yml. For those, recreate the containers:

docker compose up -d

Containers use restart: unless-stopped: they come back on their own after a crash or a VM reboot, unless someone stopped them with docker compose stop. After a stop, bring them back with docker compose start or docker compose up -d.

#Changing a setting

  1. Edit the file with sudo, for example sudo nano /app/relay/gateway.appsettings.json. It must stay valid JSON.
  2. Restart the container that reads it: docker compose restart gateway for gateway.appsettings.json, docker compose restart panel for panel.appsettings.json.
  3. Check it started cleanly with docker compose logs --tail 100 gateway.

The deploy never overwrites these files, so a change stays until someone edits it again. Keep Encryption:MasterKey identical in both files: if they differ, the gateway cannot decrypt provider keys the panel stored, and Playground calls are refused.

Environment variables set in docker-compose.yml take precedence over the settings files. The panel's Gateway:InternalBaseUrl is set there to http://gateway:2003, so the Playground reaches the gateway over the Compose network. Setting it in panel.appsettings.json has no effect.

Services that run on the VM itself (ClickHouse/ClickStack, Qdrant) are reached from the containers as host.docker.internal, not localhost or 127.0.0.1, which inside a container mean the container itself. Those services must listen on the Docker bridge, not only on loopback.

#Rolling back

There is no automatic rollback. To go back to an earlier build:

  1. List the tags in the registry: az acr repository show-tags -n <registry> --repository relay-gateway --orderby time_desc.
  2. Set IMAGE_TAG in /app/relay/.env to the earlier tag.
  3. Run docker compose up -d.

All three apps move together. The next deploy writes its own tag back into .env. If the rollback crosses a schema change, check that the older build still works with the newer database.

#When a deploy fails

SymptomCause and fix
/app/relay/<app>.appsettings.json is missingCreate it from the example file in deploy/, then sudo chown 1654:1654 and sudo chmod 400 it.
... is a directoryA container started once without the file, and Docker created an empty directory in its place. Remove it with sudo rm -r, create the file, and re-run the deploy.
Warning that a settings file is not readable by uid 1654Run sudo chown 1654:1654 <file> && sudo chmod 400 <file>. Otherwise the app starts without its configuration.
VM_SSH_KNOWN_HOSTS has no entry for VM_HOSTThe known-hosts secret was scanned from a different address. Re-create it from ssh-keyscan <VM_HOST>.
Azure login fails with AADSTS700213The federated credential's subject does not match. See deploy/README.md, step 5.
Smoke test fails, or a site answers 502The container is not running or not healthy. Check docker compose ps and docker compose logs <app>. A wrong connection string usually shows on the first real call rather than at startup.

#First-time setup

Setting up a new VM is a one-time job documented in the repository's deploy/README.md: creating the settings files, DNS records, adding the Caddy site blocks, SQL firewall rules, the identity redirect URI, and the GitHub variables, secrets and federated credential.

#IIS

Build in Release with --no-restore (running instances can lock Debug DLLs, and the environment restore is restricted):

dotnet build Application.sln -c Release --no-restore

Publish each app you deploy:

dotnet publish Application.Api -c Release -o out/api
dotnet publish Application     -c Release -o out/panel
dotnet publish Application.Doc -c Release -o out/docs

The repo's GitHub Actions workflows (.github/workflows/deploy_api.yml, deploy_app.yml, deploy_docs.yml) do exactly this on a self-hosted runner and copy the output into IIS sites — a push to dev deploys the test environment, a push to main deploys prod, and each workflow triggers only when its projects change. The DACPAC publish is not part of CI.

#Database schema (DACPAC)

Schema is not applied by the apps at runtime — there are no EF migrations for the gateway schema. Publish the Application.Database DACPAC to the relay_gateway database (SqlPackage / Visual Studio) as part of your release, before the new build runs: the gateway selects recently added columns on every request. New tables/columns are authored as .sql there and mirrored in the DbContext model.

ClickHouse needs no schema step: relay_observation and relay_score are created, and new columns added, by the apps at startup.

#Configuration in production

Supply secrets via environment variables or Key Vault — never committed files. On the Docker VM they live in the two settings files in /app/relay (see Changing a setting). At minimum:

  • ConnectionStrings:GatewayDb on both apps; ConnectionStrings:UserManagementDb and the identity-app sign-in settings (Identity:BaseUrl, Identity:ClientId, Identity:ClientSecret) on the panel host, which refuses to start without the secret.
  • Encryption:MasterKey — the same value on the panel host and the gateway, or neither can read what the other encrypted and the Playground delegation fails.
  • Gateway:PublicBaseUrl (and Gateway:InternalBaseUrl when the panel reaches the gateway over a different address) so the panel's Playground, workflow approvals and resume links point at the right place; Gateway:PanelBaseUrl for links in approval notifications.
  • Provider keys are entered in the panel and stored encrypted; set a SecretRef config key only for providers you deliberately keep on the configuration fallback.
  • ClickHouse:ConnectionString on both apps if you want telemetry, dashboards and traces.
  • Qdrant:Url (+ key) if you use knowledge bases.
  • Connectors:RedirectUri only behind a reverse proxy that rewrites the host.

See the full Configuration reference.

#Telemetry and HyperDX

Relay always writes its own observability tables when ClickHouse is configured. For HyperDX dashboards and alerting on the same data, run ClickStack (the all-in-one image bundles ClickHouse + an OpenTelemetry collector + HyperDX), set Gateway:Otlp:Enabled=true, Gateway:Otlp:Endpoint and Gateway:Otlp:ApiKey (the HyperDX ingestion key), and optionally Telemetry:DashboardSource=otel to read the usage dashboard from the collector's otel_traces. Telemetry:Backend is obsolete and ignored. See Telemetry & dashboards and the repo's docs/clickstack.md.

#Networking notes

  • On Windows/dev, prefer 127.0.0.1 over localhost for containerised dependencies (IPv4 vs. IPv6).
  • Restrict the control-plane CORS origins with Cors:PanelOrigins.
  • Serve the gateway over HTTPS: a page served over HTTPS can only open wss:// realtime sockets to a remote host.
  • The gateway API and the panel can scale independently, but several gateway stores are per instance: the response cache and idempotency store, the per-key rate limiter, provider health, and realtime session tokens (mint and connect must reach the same process — use sticky sessions behind a load balancer).

#This docs site

Application.Doc is self-contained (no external packages, content copied to output). Publish and host it like any static-ish ASP.NET app; it serves the Markdown under Docs/ rendered on the fly.