# Deploying dist.town dist.town runs as one Fly app built from this flake: one image, two process groups. The appview is the public edge; the web renderer is internal-only. The repo reference is `git+https://tangled.org/graham.systems/dist-town`. ## Pieces ``` jetstream v2 ──▶ appview (signal) discovery nominates; ingest triggers appview ──▶ publisher's PDS verified fetch: sig + proof, the only writer appview ──▶ SQLite (disposable) read plane + front door appview ──▶ web (internal) human paths proxied to SvelteKit ``` There is no sync middleman: the appview consumes jetstream v2 directly as a signal, verifies every record against the publisher's own PDS itself, and reconciles each tracked repo's rev on the verify interval — healing any missed event by verified CAR resync from the authoritative source. ## Deploying ```sh tools/deploy.sh ``` That script is the deploy. In order it: 1. Writes a temporary `registries.conf` in v2 format and points `CONTAINERS_REGISTRIES_CONF` at it. NixOS ships a v1-format system file that skopeo refuses; without the override the push fails. 2. `nix build .#image` — the layered image, streamed rather than loaded, so no docker daemon and no local container store are involved. 3. `fly auth token | skopeo login registry.fly.io` and `./result | skopeo copy docker-archive:/dev/stdin docker://registry.fly.io/dist-town:latest`. 4. Records the pushed digest with `skopeo inspect`. 5. `fly deploy`. 6. Reads every machine's digest back with `fly image show --json` and fails if any of them differs from the pushed digest. Step 6 is the point of the script. `fly deploy` can exit 0 while machines stay on the old image, so its exit status is not proof that a deploy took. Digest equality is. If the check fails, run `fly deploy` again and re-verify rather than assuming the push was the problem. Run it from inside `nix develop` — `flyctl` and `skopeo` come from the dev shell. ## The Fly app `fly.toml` describes the whole deployment. - **One image, two process groups.** `appview = /bin/appview` and `web = /bin/dist-town-web` are both in the image built by `.#image`; the groups differ only by command. - **Only the appview faces the internet.** `[http_service]` lists `processes = ["appview"]` on internal port 8480, `force_https`, with `auto_stop_machines = "off"` and `min_machines_running = 1` — a sleeping indexer would stop indexing while still looking healthy. - **Web is reached over internal DNS.** The appview proxies to it via `APPVIEW_WEB_UPSTREAM`; nothing external can address it. - **The appview gets 512MB.** Backfill parses whole repo CARs in memory and OOMs at the default on a 10MB repo. Web stays on the default. - **The volume.** `appview_data` mounts at `/data` for the appview process only; `APPVIEW_DB` points inside it. One-time setup, before the first deploy: ```sh fly apps create dist-town fly volumes create appview_data --size 3 # in fly.toml's primary_region fly certs add dist.town # then point DNS at the app ``` ## The edge With `APPVIEW_WEB_UPSTREAM` set, the appview wraps its own routes in a reverse proxy to the web renderer and decides per request which side answers. The rule is a pure URL-shape check (`internal/appview/edge.go`): - `?go-get=1` on **any** path — including `/` — returns the go-import document for the `dist.town` module, before any other check. - `/xrpc/*` — native (the read plane). - `/.well-known/*` — native, including `/.well-known/did.json`, the service's own identity document. - `/disttown.schema.json` — native; editors fetch it for the manifest. - Anything ending in `/__data.json` — proxied. That is SvelteKit's client-side navigation wearing a sub-path shape, so it wins the carve-out; an artifact literally named `__data.json` loses its front-door URL. - Otherwise: any path segment containing `@` **with segments after it** is a machine path and is served natively — the release sub-paths (artifacts, `SHA256SUMS`, `.sha256`). `@` never appears in publisher identifiers or project name segments, which is what makes the shape check sound. - Everything else is proxied to the web renderer. The appview holds the socket, so a web outage degrades pages but never downloads. Without `APPVIEW_WEB_UPSTREAM` the appview serves only its own routes — the standalone development mode. ## AppView environment | Variable | Default | Meaning | | --- | --- | --- | | `APPVIEW_BIND` | `:8480` | Public listen address (the edge). | | `APPVIEW_INTERNAL_BIND` | unset | When set, `/healthz` and `/admin/` move to their own listener on this address. No Fly service exposes it. Unset, the admin surface (still token-gated) rides the public mux — a development convenience. | | `APPVIEW_DB` | `appview.db` | SQLite index path. In production `/data/appview.db`, on the volume. | | `APPVIEW_TRACK` | unset | Comma-separated DIDs to index regardless of discovery. | | `APPVIEW_JETSTREAM_URL` | `wss://jetstream.us-east.bsky.network/subscribe` | The signal stream (jetstream v2). | | `APPVIEW_VERIFY_INTERVAL` | `5m` | Reconcile sweep and re-verification cadence. Any Go duration. | | `APPVIEW_WEB_UPSTREAM` | unset | Web renderer base URL. Set, human paths proxy there; unset, standalone. | | `APPVIEW_ADMINS` | unset | Comma-separated DID allowlist for the moderation surface's service auth. | | `APPVIEW_SERVICE_DID` | `did:web:dist.town#dist_town_appview` | The service's own identity, and the audience admin JWTs must carry. | | `APPVIEW_LABEL_KEY` | unset | Multibase secp256k1 private key for label signing. Unset disables label emission; set, pre-existing suppressions backfill into the label stream once at start. | `/healthz` answers on the public mux in every configuration, and additionally on the internal listener when `APPVIEW_INTERNAL_BIND` is set. `APPVIEW_TRACK` is the one you want first locally: jetstream discovery only sees *new* events, so a repo that published before your appview existed needs a manual on-ramp. The index is disposable. Deleting the database and restarting backfills every tracked repo from its PDS through the verified CAR path — bootstrap and resync are the same code. ## Web environment | Variable | Default | Meaning | | --- | --- | --- | | `HOST` | adapter-node default | Listen host. Production sets `::`, because Fly internal DNS is IPv6-only. | | `PORT` | `3000` | Listen port. | | `ORIGIN` | unset | Public origin, so adapter-node generates correct absolute URLs behind the proxy. `https://dist.town` in production. | | `APPVIEW_URL` | `http://127.0.0.1:8480` | Where SSR reads the read plane. Production uses internal DNS. | | `PUBLIC_FRONTDOOR_URL` | `http://127.0.0.1:8480` | The front door as visitors must type it — the host in every verify command and Copy-URL the pages render. **Required in production.** Unset, the web falls back to its dev default and publishes `127.0.0.1` to the world. | | `NODE_ENV` | — | `production`, set in the image itself. | ## Flake outputs | Output | What it is | | --- | --- | | `.#disttown` | The publisher CLI, version and update source stamped via ldflags (`+nix` marks provenance: a store path is immutable, so `disttown update` reports rather than replaces). | | `.#appview` | The indexer, read plane, and front door. | | `.#admin` | The operator moderation client, deliberately not part of any public release. | | `.#web` | The SvelteKit UI as an adapter-node build. It is a build directory, not an executable — `$out/build`, run with `node`; only node is needed at runtime, since adapter-node bundles the server deps. The image wraps it as `/bin/dist-town-web`. | | `.#image` | The deploy image: both entrypoints in one layered image. **Linux only.** | | default | `.#disttown`. | ## Running locally The appview, standalone: ```sh APPVIEW_BIND=":8480" \ APPVIEW_DB="appview.db" \ APPVIEW_TRACK="did:plc:..." \ APPVIEW_VERIFY_INTERVAL="5m" \ nix run .#appview ``` The web renderer against it — the SvelteKit dev server proxies `/xrpc` to the appview: ```sh nix develop -c pnpm install nix develop -c pnpm --filter @dist-town/web dev ``` Or the packaged production build (`.#web` is a build directory, so node runs it): ```sh nix build .#web APPVIEW_URL="http://127.0.0.1:8480" \ PUBLIC_FRONTDOOR_URL="http://127.0.0.1:3000" \ PORT=3000 \ node ./result/build ``` To exercise the production edge locally, point the appview at the web process and talk only to the appview: ```sh APPVIEW_WEB_UPSTREAM="http://127.0.0.1:3000" nix run .#appview ``` ## Publisher setup ```sh disttown login # browser OAuth; --app-password for the prompt-based path disttown storage setup --base-url https:// \ --upload-cmd 'aws s3 cp {file} s3://bucket/{key}' disttown storage doctor # required checks must pass ``` `storage setup --profile ` saves a named bucket a repo manifest can pick by name; without `--profile` it writes the machine-wide default. The profile name `blobs` is reserved — a manifest declaring it publishes artifact bytes as PDS blobs, no bucket involved, which is what this repo's own manifest does. CI needs no files at all. Set `DISTTOWN_PDS`, `DISTTOWN_IDENTIFIER`, and `DISTTOWN_APP_PASSWORD` for a fresh session per run; add `DISTTOWN_STORAGE_BASE_URL` and `DISTTOWN_STORAGE_UPLOAD_CMD` to define storage without touching the config file. `DISTTOWN_READ_PLANE` redirects the read commands at a local appview, and `DISTTOWN_UPDATE_SOURCE` overrides where `disttown update` looks. ## Cutting a release With the committed `disttown.jsonc` and an annotated tag at HEAD, the release cut takes no arguments: ```sh tools/dist.sh 0.7.0 # cross-compile the matrix into dist/ git tag -a v0.7.0 -m "0.7.0" disttown publish ``` The CLI infers the project, the version, and the artifacts from the manifest and the tag, shows the plan, and asks before anything uploads. The tag must be annotated — a lightweight tag yields "no annotated tag at HEAD". ## Remaining graduation work The open items are tracked in `openspec/changes/foundation-graduation/tasks.md`: the bucket and front-door variant of the release dogfood, publishing the record and view lexicons under the `town.dist.*` authority, and confirming a changelog renders in an external standard.site consumer. The blob variant of the dogfood shipped 2026-08-05.