# Federated Suite Deploy Strategy How Superbrain becomes a first-class app in the `/federated` suite on `core`, installable with `/federated/bin/installapp superbrain`, upgradeable with the standard `upgrade` flow, and covered by the suite's monitors, DNS, Authelia SSO, backups and superpanel catalog. ## Current state (verified 2026-10-22) Two parallel, conflicting realities exist on `core`: 1. **Ad-hoc source stack** in `/federated/apps/superbrain/`: an rsync of this repo running the full compose stack (own postgres volume, web published on host port `:3100` because bun holds `:3000`). Not integrated: no traefik labels, no `core` network IP, no pdns record, invisible to `installapp`/`upgrade`/monitors/superpanel. 2. **n8n-shaped placeholders**: `/federated/lib/superbrain.sh` and `/federated/services/superbrain/service` were copied from n8n and describe an app that does not exist — single image `superbrainio/superbrain` on port 5678, n8n's `/rest/owner/setup`, n8n's `deployment_key`/`user_api_keys` schema for the mcpserver link, and `INTERNAL_IP=192.168.0.71` **which collides with the real n8n**. Both files must be rewritten, not patched. `installapp` refuses to run while `/federated/apps/superbrain` exists, so the ad-hoc stack must be migrated and removed (or moved aside) before the federated install can proceed. ## Target architecture Superbrain is **not one image**. It is three artifacts built from this repo: | Artifact | Source | Role | |---|---|---| | `superbrain-app` | `Dockerfile` (scratch, Go) | API on :8080, `--healthcheck`, `--seed` | | `superbrain-web` | `web/Dockerfile` (Next standalone) | UI on :3000, API proxy, NextAuth | | `superbrain-migrate` | NEW: `FROM postgres:16.15-alpine` + `COPY db /db` | one-shot schema bootstrap + migration runner | The federated `upgrade_app` flow only understands **registry images** (`docker pull CONTAINER:VERSION`, btrfs snapshot, compose down/up, health probe). Source-on-host builds fight that machinery, so: **Decision: publish versioned images from CI; the host never builds.** **Registry mode (implemented 2026-10-29):** CI publishes the three images — `federatedcomputer/superbrain-{app,web,migrate}` — on semver tags without a `v` prefix (`.github/workflows/release.yml`, tag filter `[0-9]+.[0-9]+.[0-9]+`, linux/amd64 + linux/arm64, one shared tag per release plus `:latest`; a smoke job bootstraps a throwaway PostgreSQL with the migrate image — fresh schema + full ledger + idempotent re-run — before anything is pushed). The migrate image is self-contained: `db/` is baked in and its entrypoint `db/bootstrap.sh` waits for postgres, applies `schema.sql` **as the superbrain user** on an empty database (object ownership: migrations must be able to ALTER those objects), then always runs the checksummed ledger — so a server never needs the source tree, and fresh install and upgrade are the same command. The dev compose runs the same bootstrap.sh. The generated app-dir compose pulls `federatedcomputer/superbrain-*: ${IMAGE_VERSION}` (`.env`, bookstack quoting style), no `build:` keys, no `IMAGE_VERSION_HOLD`. The service file sets `CONTAINER= federatedcomputer/superbrain-app` (must equal the first `image:` line's repository — `upgrade_app` greps it) and `VERSION=`; the `.env` keeps `IMAGE_VERSION=` as its ONLY line containing `VERSION=` because `upgrade_app`'s rewrite-sed matches every occurrence. `services/superbrain/upgrade/pre` (house hook mechanism, listmonk pattern) takes a pg_dump into `.update-backups/` (5 retained) and pulls web+migrate at the target version, since `upgrade_app` itself pulls only the app image. Install/update for any core: `deploy/federated/install.sh` (preflights — Authelia required, fcore SMTP credential, fixed-IP collisions with `SUPERBRAIN_*_IP` overrides; installs lib/service/hook; runs `/federated/bin/installapp superbrain`; verifies containers, Authelia client + claims markers, HTTPS login) and `deploy/federated/update.sh` (extract /deploy from the migrate image at VERSION, default latest → sync lib/service/hook with parse-checks and backups → re-render compose via `render_superbrain_compose` → `/federated/bin/ upgrade superbrain` → same-version compose safety pass → health probe). The registry-mode app dir holds ONLY compose + .env, so both scripts ship inside the migrate image at `/deploy` (since 1.0.1) and run via `bash -c "$(docker run --rm federatedcomputer/superbrain-migrate cat /deploy/