The stack no longer talks to any specific external proxy. Removed traefik.* labels and the shared `traefik` external network from kong + app, and dropped TRAEFIK_NETWORK / TRAEFIK_ENTRYPOINT / TRAEFIK_CERTRESOLVER from the .env template and the deploy-script bootstrap. Internal edge is a `caddy:2-alpine` container on the `colectivo` network, publishing host port 3000. `infra/Caddyfile.erosi` does the path split: /rest|/auth|/realtime|/storage|/graphql|/pg -> kong:8000, everything else -> app:3000. Global block sets `auto_https off` + `admin off` so :3000 is the only listener. Whatever proxy fronts the host (NetBird's Traefik, nginx, anything) just terminates TLS for erosi.limonia.net and forwards plain HTTP to ambrosio:3000. Off-stack and out of this repo. Docs (CLAUDE.md + docs/deployment.md) updated to describe the two-layer edge. Includes the gotcha that bind-mounted file edits (Caddyfile) need `docker compose restart caddy` since `up -d` won't recreate the container on file-only changes. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
7.7 KiB
Deployment
Production stack — ambrosio (OVH VPS)
Live URL: https://erosi.limonia.net (app + Supabase API, single-domain). Keycloak is external — its URL is set via PUBLIC_KEYCLOAK_URL in /opt/colectivo/.env. OVH VPS, Ubuntu 24, Docker 29.
infra/docker-compose.erosi.yml— full stack (db, auth, rest, realtime, storage, imgproxy, kong, app, caddy).studio,meta, and the bundledkeycloakservice are intentionally absent. All services live on a single internal Docker network (colectivo); nothing on the stack is bound to a public network or labeled for an external reverse proxy.- Internal edge — Caddy on
:3000:infra/Caddyfile.erosidoes the path split —/rest/v1,/auth/v1,/realtime/v1,/storage/v1,/graphql/v1,/pg→kong:8000; everything else →app:3000. WebSockets pass through (Caddy'sreverse_proxyhandles upgrade headers). Plain HTTP, no TLS. The container publishes host port 3000 (ports: ["3000:3000"]). Global block setsauto_https off+admin off, so the only listening socket is:3000— no ACME, no admin API. - External reverse proxy + TLS are owned outside this repo (originally NetBird's self-hosted Traefik on ambrosio). Whatever proxy fronts the host terminates TLS for
erosi.limonia.netand forwards plain HTTP toambrosio:3000. Repo has no labels, no Traefik network attachment, no cert config — only the bind on:3000. infra/scripts/deploy-erosi.sh— idempotent redeploy: rsync → on first run generate secrets + write/opt/colectivo/.envwith placeholders the operator fills in (PUBLIC_KEYCLOAK_URL,KEYCLOAK_CLIENT_SECRET) → subsequent runs fail fast if any placeholder is unfilled → docker compose build + up → apply pending migrations. Never touches/etc/caddy/*, never runssudo. Note: bind-mounted files (e.g.Caddyfile.erosi) requiredocker compose restart caddyafter editing — the script'sup -donly recreates services whose compose definition changed.keycloak/realm-export.erosi.json— not imported by this stack (no bundled Keycloak). Kept as reference for what the external Keycloak client must have — realm name, client id, and client secret are operator-chosen and wired in via.env(PUBLIC_KEYCLOAK_REALM,PUBLIC_KEYCLOAK_CLIENT_ID,KEYCLOAK_CLIENT_SECRET), so the file's literalcolectivo-web/colectivovalues are illustrative, not required. What the client must actually have:redirectUris: ["https://erosi.limonia.net/*", "https://erosi.limonia.net/auth/v1/callback"],webOrigins: ["https://erosi.limonia.net"], confidential,openidas a default client scope withinclude.in.token.scope=true..env.erosi.example— committed template. The real/opt/colectivo/.envon ambrosio is 600 and stays on the server.
Pre-deploy prerequisites
- External Keycloak reachable from ambrosio's Docker network (outbound HTTPS). Realm + confidential client configured as described above;
.envgetsPUBLIC_KEYCLOAK_URL,PUBLIC_KEYCLOAK_REALM,PUBLIC_KEYCLOAK_CLIENT_ID,KEYCLOAK_CLIENT_SECRET. If the Keycloak deployment uses the legacy/auth/base path (Keycloak ≤ 16 default; some distributions still carry it —auth.fosil.euis one) thenPUBLIC_KEYCLOAK_URLmust include it, e.g.https://auth.example.com/auth. Verify by opening${PUBLIC_KEYCLOAK_URL}/realms/${PUBLIC_KEYCLOAK_REALM}/.well-known/openid-configuration— it should return 200 JSON; 404 means the base path is wrong. - Users in the external Keycloak must match existing
auth.usersUUIDs (auth.users.id = keycloak sub) or the stack starts fresh with no prior users. Re-registering produces new sub UUIDs; either re-seedauth.users+auth.identitiesor wipe and start over. - External proxy idle timeout — Realtime WebSockets stay open for the entire shopping session, so whatever fronts the host must allow long-lived idle connections. NetBird's installer sets
--entryPoints.websecure.transport.respondingTimeouts.idleTimeout=0(unlimited) by default; if the external proxy is something else, configure ≥3600s on the relevant entrypoint. Symptom of a too-short timeout: client reconnects continuously mid-session. - External proxy upstream — forward
erosi.limonia.net(HTTPS, terminate TLS there) toambrosio:3000(plain HTTP). One upstream is enough; Caddy inside the stack does the kong-vs-app path split. - DNS for
erosi.limonia.net→ ambrosio (A/AAAA). - Host Caddy disabled:
sudo systemctl stop caddy && sudo systemctl disable caddy. Withoutdisable, the unit comes back on reboot and races the external proxy for 80/443. Remove any# BEGIN colectivo-erosi … # ENDblock from/etc/caddy/Caddyfilefor tidiness. (The internal Caddy inside the stack runs in a container on:3000and is unrelated to this host unit.)
Prod-specific fixes
Had to be made for the stack to boot cleanly on a fresh volume:
infra/db-init/00-role-passwords.sh— rewrote as idempotent bootstrap (see the "supabase/postgres doesn't bootstrap Supabase roles" gotcha inCLAUDE.md): creates all Supabase service roles if absent, enablespg_cron+pgcrypto+uuid-ossp, createsauth/storage/graphql_public/_realtime/realtimeschemas + emptysupabase_realtimepublication, setssupabase_auth_adminsearch_path toauth. The old00-role-passwords.sql(ALTER-only) has been removed.apps/web/vite.config.ts— PWA strategy switchedinjectManifest→generateSW(see the "injectManifest hardcoded filename" gotcha inCLAUDE.md).
Runbook
App build hang / PostHog timeout
The app image's final build stage (pnpm --filter @colectivo/web build → vite SSR) occasionally stalls during transforming... and ~9 minutes later dies with UnhandledPromiseRejection: "Timeout while shutting down PostHog". Intermittent; reproducible across rebuilds with the same layer cache.
Fix: rebuild with --no-cache once:
ssh ambrosio 'cd /opt/colectivo && docker compose --env-file .env -f infra/docker-compose.erosi.yml build --no-cache app'
Subsequent normal builds succeed. Run inside tmux if you're on a flaky SSH link — the no-cache build takes 5–15 minutes and losing the connection kills BuildKit.
Changing PUBLIC_* env values (URL, realm, client id)
Any change to PUBLIC_APP_URL, PUBLIC_SUPABASE_URL, PUBLIC_KEYCLOAK_URL, PUBLIC_KEYCLOAK_REALM, PUBLIC_KEYCLOAK_CLIENT_ID requires an app rebuild (those values are baked into the client bundle at build time via docker-compose.erosi.yml build args). After editing .env:
ssh ambrosio 'cd /opt/colectivo && docker compose --env-file .env -f infra/docker-compose.erosi.yml build app && docker compose --env-file .env -f infra/docker-compose.erosi.yml up -d'
KEYCLOAK_CLIENT_SECRET is runtime-only (GoTrue reads it) — for that one a docker compose restart auth is enough.
Wipe all app + auth data (keep schema, keep migrations)
When switching Keycloak realms or starting fresh:
BEGIN;
TRUNCATE TABLE public.notes, public.tasks, public.task_lists,
public.shopping_items, public.shopping_lists, public.item_frequency,
public.collective_invitations, public.collective_members, public.collectives,
public.users
RESTART IDENTITY CASCADE;
TRUNCATE TABLE auth.refresh_tokens, auth.sessions, auth.identities, auth.users
RESTART IDENTITY CASCADE;
COMMIT;
CASCADE also empties auth.mfa_factors, auth.mfa_amr_claims, auth.mfa_challenges, auth.one_time_tokens — expected. Never touch auth.schema_migrations or public._applied_migrations (they track what DDL has been applied).
Not yet configured on ambrosio
- SMTP (Resend)
- Automated backups — script exists at
infra/scripts/backup.sh, not scheduled - Lighthouse run against prod URL
- Final production icons