|
| 1 | +# Deployment reference |
| 2 | + |
| 3 | +The [README](../README.md) covers the recipe for the three supported deployment paths (Render Blueprint, `docker run`, bare binary). This doc is the reference: env vars, init flags, container internals, what each path does and doesn't set up. |
| 4 | + |
| 5 | +## TLS termination |
| 6 | + |
| 7 | +The relay binds plain HTTP. Stand any TLS-terminating reverse proxy in front of it. Providers refuse non-HTTPS endpoints, so this is enforced by the outside world either way. |
| 8 | + |
| 9 | +- **Caddy** — `webhooks.example.com { reverse_proxy localhost:8080 }`. Caddy obtains a Let's Encrypt cert automatically. |
| 10 | +- **nginx** — standard `proxy_pass http://127.0.0.1:8080;` block, plus your existing TLS config. |
| 11 | +- **Cloudflare Tunnel / Render / fly.io** — any platform that gives you HTTPS in front of an HTTP origin. |
| 12 | + |
| 13 | +Wire your load balancer's health check to `/readyz` (it pings SQLite end-to-end). `/healthz` is liveness-only. |
| 14 | + |
| 15 | +## `hooks init` |
| 16 | + |
| 17 | +`hooks init` is the bootstrap command. It writes `hooks.yaml`, creates `hooks.db`, mints a one-time **admin token** (the legacy system credential), and — when the users table is empty — prints a one-time **bootstrap signup URL** (24-hour TTL, single-use, auto-disables once any user exists): |
| 18 | + |
| 19 | +```text |
| 20 | +admin token (shown ONCE): <long base64 string> |
| 21 | +signup: https://webhooks.example.com/signup?code=ABCDEFGH... |
| 22 | + (single-use; expires in 24h; auto-disables once any account exists) |
| 23 | +``` |
| 24 | + |
| 25 | +Save both. The admin token has no recovery path; the signup URL is how the first human creates their admin account. If the bootstrap link expires before it's used, re-run `hooks init --force` against the still-userless DB to mint a fresh 24-hour invite. |
| 26 | + |
| 27 | +Notable flags: |
| 28 | + |
| 29 | +- `--server-url <url>` (or `HOOKS_PUBLIC_URL`) — host to use when printing the signup URL. Skip it and the URL prints with a `localhost` placeholder you'll have to swap by hand. |
| 30 | +- `--dir <path>` — directory for `hooks.yaml` and `hooks.db`. Used by the container entrypoint (`--dir /data`). |
| 31 | +- `--force` — re-mint the bootstrap signup URL on a still-userless DB. Once any user exists, the bootstrap path is closed and `--force` does nothing useful. |
| 32 | +- `--token-name <name>` — name for the generated admin token (default `operator`). Cosmetic only — surfaced in `hooksctl token list`. |
| 33 | + |
| 34 | +What `hooks init` does **not** do: |
| 35 | + |
| 36 | +- Stand up your reverse proxy. That's on you. |
| 37 | +- Register the provider-side webhook. That's a step in the provider's dashboard. |
| 38 | +- Persist the admin token plaintext or the bootstrap signup URL anywhere except standard out. Save them — neither is recoverable. (The token's Argon2id hash lives in the database, but the plaintext is shown only once.) |
| 39 | + |
| 40 | +## Env vars and config precedence |
| 41 | + |
| 42 | +Listen-address precedence: `HOOKS_LISTEN_ADDR` > yaml `listen_addr` > `:$PORT` (when `$PORT` is a valid port — for Render/Heroku/Fly/Cloud Run) > `:8080`. |
| 43 | + |
| 44 | +Other env vars: |
| 45 | + |
| 46 | +- `HOOKS_DATABASE_URL` — SQLite path. Defaults to `./hooks.db`; the Docker image overrides to `/data/hooks.db`. |
| 47 | +- `HOOKS_LOG_LEVEL` — `debug`, `info`, `warn`, `error`. Default `info`. |
| 48 | +- `HOOKS_PUBLIC_URL` *(optional)* — host used when printing the bootstrap signup URL. |
| 49 | +- Provider secrets (e.g. `RENDER_WEBHOOK_SECRET`) — referenced from `hooks.yaml` via `${VAR}` interpolation. |
| 50 | + |
| 51 | +`hooks.yaml` supports `${VAR}` and `${VAR:-default}` interpolation. A `tokens:` field is rejected at load time — listener tokens live in the database, not in YAML. Every source must declare a `verifier:`; unsigned sources are not supported. |
| 52 | + |
| 53 | +Defaults: body size limit 1 MiB, dedupe window 24h, skew window 5m, retention 30d per source. Retention `0` / `forever` / `never` disables auto-prune for that source. |
| 54 | + |
| 55 | +## The container image |
| 56 | + |
| 57 | +The `Dockerfile` is a multi-stage build (Go builder → small Alpine runtime). It runs as UID 65532, mounts `/data` as a volume for the SQLite database, and ships both `hooks` and `hooksctl` so you can `docker exec` to manage tokens, push subscriptions, and pruning. |
| 58 | + |
| 59 | +Image defaults: |
| 60 | + |
| 61 | +- `HOOKS_DATABASE_URL=/data/hooks.db` |
| 62 | +- Listens on `:8080` (or `$PORT` if set) |
| 63 | +- A Dockerfile-level `HEALTHCHECK` polls `/healthz`. Behind a load balancer, prefer `/readyz`. |
| 64 | + |
| 65 | +The image's entrypoint (`docker-entrypoint.sh`) detects an empty `/data` (no `hooks.yaml` and no `hooks.db`) on first boot and runs `hooks init --dir /data` automatically. Without this, Render Blueprint deploys would crash-loop on first boot — the volume is empty, the server can't read `hooks.yaml`, and Render's Shell tab is gated on a running instance, so the documented recovery path would be unreachable. The auto-init prints the one-time admin token and bootstrap signup URL to stdout (which lands in the platform's log stream — treat both as secrets). |
| 66 | + |
| 67 | +Subcommands (`init`, `invite`, `prune`, `verify`, `help`) bypass the bootstrap. |
| 68 | + |
| 69 | +## Render Blueprint specifics |
| 70 | + |
| 71 | +The repo includes a `render.yaml` Blueprint: |
| 72 | + |
| 73 | +- Single instance only. The SQLite store is a single-writer design; two pods against the same disk corrupt it. `numInstances: 1` is intentional. |
| 74 | +- 1 GiB persistent disk mounted at `/data`. |
| 75 | +- `HOOKS_DATABASE_URL=/data/hooks.db` is set in the Blueprint. |
| 76 | +- `HOOKS_PUBLIC_URL` and `RENDER_WEBHOOK_SECRET` are declared `sync: false` — set them in the service's **Environment** tab before the first deploy. |
| 77 | +- No `HOOKS_LISTEN_ADDR`. The server honors `$PORT` (which Render injects) automatically. |
| 78 | +- `/readyz` is the health check. |
| 79 | + |
| 80 | +Both `hooks` and `hooksctl` are on `$PATH` in the Render Shell, so token rotation, push-subscription management, and pruning all work without leaving the platform. |
| 81 | + |
| 82 | +## Single-process / SQLite limitation |
| 83 | + |
| 84 | +The default deployment is one process with SQLite. There is **no** built-in coordination for multi-process; SSE delivery and push dispatch assume a single in-process notifier. The storage interface is shaped to accept a Postgres backend later (and a Redis/NATS pub/sub for cross-process notifications), but that code isn't written yet — running two `hooks` processes against the same SQLite file is unsafe. |
| 85 | + |
| 86 | +## Skew-window semantics on initial backfill |
| 87 | + |
| 88 | +`hooksctl forward` replays from the cursor on connect, then tails live. **Initial backfill is bounded by the source's signature-verification skew window** (`skew_window` per source in `hooks.yaml`, or 5 minutes when unset). Events older than that window are skipped on the initial drain so a verifying consumer doesn't 401 on a stale `webhook-timestamp`. The cursor still advances past skipped events, so reconnects don't reconsider them. |
| 89 | + |
| 90 | +Skipped events remain in the store. Redeliver them via the inspector ("Replay to listeners") or `hooksctl replay`. |
| 91 | + |
| 92 | +This filter is **only on the initial backfill**. Live tail (notifier-triggered or keepalive-triggered drains) is unfiltered, so manual replays via the inspector still reach currently-connected subscribers. |
0 commit comments