Registry mode: publish app/web/migrate images, drop source builds on hosts
release gate / check (push) Canceled after 4m3s
release / smoke (push) Successful in 10m13s
release / publish (push) Failing after 12m48s

The federated suite now installs Superbrain like every other house app:
pull images, run installapp, no source tree on the host.

Images (Docker Hub, federatedcomputer namespace, one shared tag per
release + :latest, linux/amd64 + linux/arm64):
  superbrain-app      Go API (scratch)
  superbrain-web      Next.js standalone
  superbrain-migrate  NEW self-contained db image: db/ baked in, entrypoint
                      db/bootstrap.sh waits for postgres, applies
                      schema.sql AS DB_USER on an empty database (object
                      ownership — migrations must be able to ALTER), then
                      always runs the checksummed ledger. Fresh install and
                      upgrade become the same command. The dev compose runs
                      the same bootstrap.sh (verified: non-empty DB skips
                      schema, applies pending migrations).

Release CI (.github/workflows/release.yml): semver tags without v prefix
(the suite's VERSION_RX); a smoke job bootstraps a throwaway PostgreSQL
with the migrate image (fresh schema + complete ledger + idempotent re-run)
and runs Go build/vet/unit BEFORE the publish job pushes — a broken db/
can never reach a tag the upgrade flow will pull. Requires
DOCKERHUB_USERNAME/DOCKERHUB_TOKEN secrets. Dockerfile stays legacy-
builder compatible (no BUILDPLATFORM cross-compile): dev hosts build
locally; CI builds each arch natively under qemu.

Federated integration:
- lib-superbrain.sh: compose pulls federatedcomputer/superbrain-*:
  ${IMAGE_VERSION} (bookstack quoting), no build: keys, no
  IMAGE_VERSION_HOLD; compose generation extracted into
  render_superbrain_compose (install + update share it); schema.sql
  pre-apply and host image builds removed; IMAGE_VERSION is the only
  VERSION= line in the generated .env (upgrade_app's sed matches every
  occurrence — the file says so in words that don't contain the pattern).
- service file: CONTAINER=federatedcomputer/superbrain-app (must equal the
  first image: repository — upgrade_app compares it), VERSION=1.0.0.
- services/superbrain/upgrade/pre hook (listmonk pattern): pre-upgrade
  pg_dump into .update-backups (5 retained) + pulls web/migrate at the
  target version (upgrade_app pulls only the app image).
- install.sh: registry messaging, installs the upgrade hook, clone is only
  for deploy files now.
- update.sh REWRITTEN for registry mode: the app dir no longer contains
  source, so it runs from a repo clone — sync lib/service/hook (parse-
  checked, backed up) -> re-render compose -> /federated/bin/upgrade
  superbrain -> same-version compose safety pass -> health probe.
- STRATEGY.md interim-mode section replaced with the registry-mode record.

README: federated section updated (pulls, not builds; house upgrade flow)
and a new 'Environment variable reference' section — every variable the
stack reads, required/optional, defaults, grouped (core, compose, access
policy, OIDC, SMTP, AI, federated-only, tests-only), so generated .env
files stay correct as features are added.
This commit is contained in:
Andrew S Erwin
2026-10-29 10:21:10 -05:00
parent 0dc48a137f
commit 341cdce026
12 changed files with 582 additions and 295 deletions
+81 -78
View File
@@ -2,29 +2,32 @@
#
# Superbrain Service
#
# Superbrain is a Go API + Next.js web stack. Unlike most suite apps it is
# currently built FROM SOURCE on the host (interim mode, until CI publishes
# federatedcomputer/superbrain-{app,web,migrate} registry images):
# Superbrain is a Go API + Next.js web stack, installed from REGISTRY
# IMAGES (no source on the host):
#
# 1. Sync the release source tree to the staging dir (from the workstation):
# tar czf - --exclude=node_modules --exclude=.next \
# main.go go.mod go.sum Dockerfile internal db web \
# | ssh core 'rm -rf /federated/tmp/superbrain-src \
# && mkdir -p /federated/tmp/superbrain-src \
# && tar xzf - -C /federated/tmp/superbrain-src'
# 2. /federated/bin/installapp superbrain
# federatedcomputer/superbrain-app (Go API, scratch)
# federatedcomputer/superbrain-web (Next.js standalone)
# federatedcomputer/superbrain-migrate (db/ baked in: bootstrap.sh applies
# schema.sql on an empty database,
# then always runs the ledger)
#
# config_superbrain() copies the staged source into the app dir and builds
# superbrain-app:local / superbrain-web:local. The .env carries
# IMAGE_VERSION_HOLD=1 so the generic `upgrade` flow (which pulls registry
# images) skips superbrain until real image releases exist, and the service
# file's CONTAINER matches the first image: line of the generated compose so
# upgrade_app()'s image-rewrite sed can never mangle the file.
# All three share ONE version tag per release (IMAGE_VERSION in .env,
# VERSION in the service file — the generic `upgrade` flow compares them,
# pulls, btrfs-snapshots and rewrites .env). Images are published by the
# repo's release workflow on semver tags without a v prefix (1.0.0).
# Install is the standard house flow: /federated/bin/installapp superbrain.
#
# upgrade_app() pulls only the FIRST image: line of the compose (the app);
# the services/superbrain/upgrade/pre hook pulls web+migrate at the target
# version before the redeploy. CONTAINER in the service file must equal
# that first image's repository, and the web container must be named
# exactly "superbrain" (upgrade_app probes it by name).
#
# Database: the shared suite postgres (container "postgresql",
# postgresql.$DOMAIN on the core network). A fresh database is bootstrapped
# with db/schema.sql applied AS the superbrain user (object ownership!), then
# the migrate one-shot runs the checksummed ledger on top — migrations are NOT
# postgresql.$DOMAIN on the core network). The migrate image owns schema
# lifecycle end to end: empty database => schema.sql applied AS the
# superbrain user (object ownership! migrations must be able to ALTER
# these objects), then the checksummed ledger on top — migrations are NOT
# a full schema by themselves (see db/check-convergence.sh in the repo).
#
# Networking: fixed core IPs — web 192.168.0.93 (traefik target; container
@@ -40,44 +43,26 @@ PATH=$HOME/.docker/cli-plugins:/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sb
get_appvars
. /etc/federated
SUPERBRAIN_SRC="/federated/tmp/superbrain-src"
SUPERBRAIN_WEB_IP="192.168.0.93"
SUPERBRAIN_APP_IP="192.168.0.94"
SUPERBRAIN_MIGRATE_IP="192.168.0.95"
# Release to install; the generic `upgrade` flow keeps .env in step with the
# service file's VERSION afterwards.
SUPERBRAIN_IMAGE_VERSION="1.0.0"
config_superbrain() {
echo -ne "* Configuring Superbrain container.."
[ -f "$SUPERBRAIN_SRC/main.go" ] || failcheck "superbrain source not staged at $SUPERBRAIN_SRC (see lib/superbrain.sh header for the sync command)"
mkdir -p /federated/apps/superbrain
cp -a "$SUPERBRAIN_SRC/." /federated/apps/superbrain/
SUPERBRAIN_DB_PASSWORD=$(create_password)
SUPERBRAIN_AUTH_SECRET=$(create_password)
SUPERBRAIN_ENCRYPTION_KEY=$(create_password)
# Shared house SMTP sender credential (fcore) for the notification
# engine's email channel. Reuse the secret other apps already hold; never
# generate a new one — the mail server is LDAP-provisioned and
# `setup email add` does not exist there (ACCOUNT_PROVISIONER is not
# FILE). Verified end-to-end 2026-10-26: net/smtp STARTTLS + AUTH PLAIN
# to mail.$DOMAIN:587 from the core network delivers with a per-app From
# address (sender != login user is allowed; authelia does the same).
if [ -f /federated/apps/authelia/data/secrets/NOTIFIER_SMTP_PASSWORD ]; then
SUPERBRAIN_SMTP_PASSWORD=$(cat /federated/apps/authelia/data/secrets/NOTIFIER_SMTP_PASSWORD)
else
SUPERBRAIN_SMTP_PASSWORD=$(sed -n 's/^EMAIL_HOST_PASSWORD=//p' /federated/apps/superpanel/.env | tail -1)
fi
[ -n "$SUPERBRAIN_SMTP_PASSWORD" ] || failcheck "could not find the fcore SMTP password (authelia secret or superpanel .env)"
# render_superbrain_compose writes the app-dir compose file. Called by
# config_superbrain (install) and by deploy/federated/update.sh after a lib
# sync, so a release that changes the compose shape can be applied without
# reinstalling. Requires DOMAIN, EXTERNALIP (get_appvars / /etc/federated)
# and the SUPERBRAIN_*_IP constants below.
render_superbrain_compose() {
# app is deliberately the FIRST service with an image: key — upgrade_app()
# reads the first image: line and compares it to CONTAINER in the service file.
# reads the first image: line and compares it to CONTAINER in the service
# file (federatedcomputer/superbrain-app).
cat > /federated/apps/superbrain/docker-compose.yml <<EOF
services:
app:
build: .
image: superbrain-app:local
image: federatedcomputer/superbrain-app:\${IMAGE_VERSION}
container_name: superbrain-app
restart: always
depends_on:
@@ -97,8 +82,7 @@ services:
ipv4_address: $SUPERBRAIN_APP_IP
web:
build: ./web
image: superbrain-web:local
image: federatedcomputer/superbrain-web:\${IMAGE_VERSION}
# MUST be named exactly "superbrain": upgrade_app() probes
# `docker container inspect superbrain` and skips apps whose primary
# container it cannot find under the app name.
@@ -135,16 +119,14 @@ services:
- "traefik.http.services.superbrain.loadbalancer.server.port=3000"
migrate:
# Reuse the suite's postgres image (already on host; psql client major
# version matches the shared server).
image: federatedcomputer/federated-postgres:17.6
# Self-contained: db/ is baked into the image (bootstrap.sh applies
# schema.sql on an empty database, then always runs the ledger).
# DB_HOST/DB_USER/DB_NAME/PGPASSWORD arrive via the env_file.
image: federatedcomputer/superbrain-migrate:\${IMAGE_VERSION}
container_name: superbrain-migrate
restart: "no"
env_file:
- ./.env
volumes:
- ./db:/db:ro
command: [sh, /db/migrate.sh]
networks:
core:
ipv4_address: $SUPERBRAIN_MIGRATE_IP
@@ -153,12 +135,42 @@ networks:
core:
external: true
EOF
}
config_superbrain() {
echo -ne "* Configuring Superbrain container.."
mkdir -p /federated/apps/superbrain
SUPERBRAIN_DB_PASSWORD=$(create_password)
SUPERBRAIN_AUTH_SECRET=$(create_password)
SUPERBRAIN_ENCRYPTION_KEY=$(create_password)
# Shared house SMTP sender credential (fcore) for the notification
# engine's email channel. Reuse the secret other apps already hold; never
# generate a new one — the mail server is LDAP-provisioned and
# `setup email add` does not exist there (ACCOUNT_PROVISIONER is not
# FILE). Verified end-to-end 2026-10-26: net/smtp STARTTLS + AUTH PLAIN
# to mail.$DOMAIN:587 from the core network delivers with a per-app From
# address (sender != login user is allowed; authelia does the same).
if [ -f /federated/apps/authelia/data/secrets/NOTIFIER_SMTP_PASSWORD ]; then
SUPERBRAIN_SMTP_PASSWORD=$(cat /federated/apps/authelia/data/secrets/NOTIFIER_SMTP_PASSWORD)
else
SUPERBRAIN_SMTP_PASSWORD=$(sed -n 's/^EMAIL_HOST_PASSWORD=//p' /federated/apps/superpanel/.env | tail -1)
fi
[ -n "$SUPERBRAIN_SMTP_PASSWORD" ] || failcheck "could not find the fcore SMTP password (authelia secret or superpanel .env)"
# app is deliberately the FIRST service with an image: key — upgrade_app()
# reads the first image: line and compares it to CONTAINER in the service file.
render_superbrain_compose
cat > /federated/apps/superbrain/.env <<EOF
# Interim source-build mode: no registry version yet. IMAGE_VERSION_HOLD
# makes the generic upgrade flow skip this app (see lib/superbrain.sh header).
IMAGE_VERSION=local
IMAGE_VERSION_HOLD=1
# Registry mode: one shared version tag for app/web/migrate. The generic
# `upgrade` flow compares this against the service file, pulls, snapshots
# and rewrites this line. NOTE: upgrade_app's sed rewrites EVERY line
# whose text contains that variable name plus "=" — this must stay the
# only such line in this file (comments included).
IMAGE_VERSION="$SUPERBRAIN_IMAGE_VERSION"
# --- Database (shared suite postgres; user+db created below) ---
DB_HOST=postgresql.$DOMAIN
@@ -217,27 +229,18 @@ NETGUARD_TRUSTED_HOSTS=mail.$DOMAIN
EOF
chmod 600 /federated/apps/superbrain/.env
# Create PostgreSQL database and user (house pattern)
# Create PostgreSQL database and user (house pattern). Schema lifecycle
# belongs to the migrate image: bootstrap.sh detects the empty database
# and applies schema.sql as the superbrain user, then runs the ledger.
docker exec postgresql psql -U postgres -c "CREATE USER superbrain WITH PASSWORD '$SUPERBRAIN_DB_PASSWORD'" &>/dev/null
docker exec postgresql psql -U postgres -c "CREATE DATABASE superbrain" &>/dev/null
docker exec postgresql psql -U postgres -c "GRANT ALL PRIVILEGES ON DATABASE superbrain TO superbrain" &>/dev/null
docker exec postgresql psql -U postgres -c "ALTER DATABASE superbrain OWNER TO superbrain" &>/dev/null
# Bootstrap a fresh database with schema.sql, applied AS the superbrain
# user so every object is owned by it (later migrations must be able to
# ALTER these). Empty-database gate: never re-runs over live data. The
# migrate one-shot then records the ledger chain on top at first start.
SB_TABLES=$(docker exec postgresql psql -U postgres -d superbrain -t -A -c "SELECT count(*) FROM information_schema.tables WHERE table_schema='public'" 2>/dev/null)
if [ "${SB_TABLES:-0}" = "0" ]; then
docker exec -e PGPASSWORD="$SUPERBRAIN_DB_PASSWORD" -i postgresql \
psql -h 127.0.0.1 -U superbrain -d superbrain -v ON_ERROR_STOP=1 -q \
< /federated/apps/superbrain/db/schema.sql || failcheck "superbrain schema.sql failed to apply"
fi
# Build app+web images from the staged source (a few minutes on first
# build, layer-cached afterwards).
echo -ne "\n* Building superbrain images (this takes a few minutes)..\n"
(cd /federated/apps/superbrain && docker compose build) || failcheck "superbrain image build failed"
# Pull the release images up front so registry/auth problems fail here
# with a clear message instead of mid-`up`.
echo -ne "\n* Pulling superbrain images ($SUPERBRAIN_IMAGE_VERSION)..\n"
(cd /federated/apps/superbrain && docker compose pull) || failcheck "could not pull federatedcomputer/superbrain-*:$SUPERBRAIN_IMAGE_VERSION - does the release exist on Docker Hub?"
echo -ne "done.\n"
}
@@ -267,7 +270,7 @@ uninstall_superbrain() {
echo -ne "* Uninstalling superbrain container.."
docker compose -f /federated/apps/superbrain/docker-compose.yml -p superbrain down &>/dev/null
docker image rm superbrain-app:local superbrain-web:local &>/dev/null || true
docker images --format '{{.Repository}}:{{.Tag}}' | grep '^federatedcomputer/superbrain-' | xargs -r docker image rm &>/dev/null || true
docker exec postgresql psql -U postgres -c "DROP DATABASE IF EXISTS superbrain" &>/dev/null
docker exec postgresql psql -U postgres -c "DROP USER IF EXISTS superbrain" &>/dev/null