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
+54 -53
View File
@@ -1,41 +1,49 @@
#!/usr/bin/env bash
#
# Install Superbrain into a federated "core" suite host.
# Install Superbrain into a federated "core" suite host (REGISTRY mode).
#
# For operators running their own copy of the federated suite who have
# access to this repository. Run ON THE CORE HOST as root:
# For operators running their own copy of the federated suite. On the
# CORE HOST, as root:
#
# git clone <this-repo> /tmp/superbrain-repo
# sudo bash /tmp/superbrain-repo/deploy/federated/install.sh
#
# No source is built or stored on the host: the three release images
# (federatedcomputer/superbrain-{app,web,migrate}, one shared version tag,
# linux/amd64 + linux/arm64) are pulled from Docker Hub, and the migrate
# image owns the database lifecycle (empty database => schema.sql as the
# superbrain user, then the checksummed migration ledger).
#
# What it does:
# 1. Preflights the suite (installapp, functions.sh, /etc/federated,
# docker network 'core', Authelia — required because the core tier is
# Authelia-only — and the fcore SMTP credential sources).
# 2. Stages the source at /federated/tmp/superbrain-src (git clone of
# this repo, or a copy of $SUPERBRAIN_SRC when set).
# 3. Installs the suite integration files:
# lib-superbrain.sh -> /federated/lib/superbrain.sh
# service -> /federated/services/superbrain/service
# 4. Runs /federated/bin/installapp superbrain, which performs the house
# flow: config_superbrain (compose/.env/db/images), start_superbrain
# (DNS + operator seed), configsso_superbrain (Authelia client +
# claims policy), monitors and superpanel catalog.
# 5. Verifies the result and prints the operator's next steps.
# 1. Preflights the suite (installapp, functions.sh, /etc/federated, the
# core docker network, Authelia — REQUIRED because the core tier is
# Authelia-only — and the fcore SMTP credential for notification mail).
# 2. Gets the deploy files from a repo clone (or $SUPERBRAIN_SRC).
# 3. Installs the suite integration: /federated/lib/superbrain.sh,
# /federated/services/superbrain/{service,upgrade/pre}, with fixed-IP
# collision checks and SUPERBRAIN_*_IP overrides.
# 4. Runs /federated/bin/installapp superbrain (the standard house flow:
# compose/.env generation with TIER=core, image pulls, database +
# user on shared postgres, pdns record, Authelia client + claims
# policy, monitors, superpanel catalog).
# 5. Verifies and prints first-login steps.
#
# Environment overrides:
# SUPERBRAIN_REPO git URL to clone (default: this repo's origin)
# SUPERBRAIN_REF branch/tag to clone (default: main)
# SUPERBRAIN_SRC local directory to stage INSTEAD of cloning
# SUPERBRAIN_SRC local repo checkout to take the deploy files from
# SUPERBRAIN_WEB_IP / SUPERBRAIN_APP_IP / SUPERBRAIN_MIGRATE_IP
# fixed core-network IPs (default .93/.94/.95 — the
# installer refuses if they are already allocated)
# SKIP_VERIFY=1 skip the post-install HTTPS probe
#
# Updates after install: sudo bash <repo>/deploy/federated/update.sh
# (syncs the service file's VERSION, then runs the house upgrade flow).
#
set -euo pipefail
REPO_DEFAULT="https://gitea.federated.computer/Federated_Computer/brain.git"
STAGE=/federated/tmp/superbrain-src
CLONE=/tmp/superbrain-install-src
LIB_DST=/federated/lib/superbrain.sh
SVC_DST_DIR=/federated/services/superbrain
@@ -71,14 +79,7 @@ if [ ! -f /federated/apps/authelia/data/secrets/NOTIFIER_SMTP_PASSWORD ] \
die "cannot find the fcore SMTP credential (authelia NOTIFIER_SMTP_PASSWORD secret or superpanel .env). The notification engine's email channel needs it; see deploy/federated/STRATEGY.md."
fi
# Source staging needs git unless a local source dir was given.
if [ -z "${SUPERBRAIN_SRC:-}" ]; then
command -v git >/dev/null || die "git not found (or set SUPERBRAIN_SRC=/path/to/source)"
fi
# --- 1. Fixed-IP allocation check ---------------------------------------------
# The compose file pins static IPs on the core network. Refuse collisions
# instead of letting docker fail obscurely mid-install.
ip_taken() { # $1 = ip
docker network inspect core -f '{{range .Containers}}{{.IPv4Address}} {{end}}' 2>/dev/null | grep -q "$1/" && return 0
grep -rqs "^INTERNAL_IP=$1\$" /federated/services/*/service && return 0
@@ -91,37 +92,36 @@ for ip in "$WEB_IP" "$APP_IP" "$MIGRATE_IP"; do
fi
done
# --- 2. Stage the source -------------------------------------------------------
# --- 2. Get the deploy files ----------------------------------------------------
if [ -n "${SUPERBRAIN_SRC:-}" ]; then
[ -f "$SUPERBRAIN_SRC/main.go" ] || die "SUPERBRAIN_SRC=$SUPERBRAIN_SRC does not look like a superbrain source tree"
say "Staging source from $SUPERBRAIN_SRC"
rm -rf "$STAGE"; mkdir -p "$STAGE"
# Same payload as the workstation tar-sync in lib-superbrain.sh's header.
(cd "$SUPERBRAIN_SRC" && tar cf - --exclude=node_modules --exclude=.next --exclude=.git \
main.go go.mod go.sum Dockerfile internal db web deploy) | tar xf - -C "$STAGE"
SRC="$SUPERBRAIN_SRC"
[ -f "$SRC/deploy/federated/lib-superbrain.sh" ] || die "SUPERBRAIN_SRC=$SRC lacks deploy/federated files"
else
command -v git >/dev/null || die "git not found (or set SUPERBRAIN_SRC=/path/to/repo)"
REPO="${SUPERBRAIN_REPO:-$REPO_DEFAULT}"
REF="${SUPERBRAIN_REF:-main}"
say "Cloning $REPO ($REF) into $STAGE"
rm -rf "$STAGE"
git clone --depth 1 --branch "$REF" "$REPO" "$STAGE" \
say "Cloning $REPO ($REF) for the deploy files"
rm -rf "$CLONE"
git clone --depth 1 --branch "$REF" "$REPO" "$CLONE" \
|| die "git clone failed — check repository access/credentials"
SRC="$CLONE"
fi
for f in main.go Dockerfile db/schema.sql web/Dockerfile \
deploy/federated/lib-superbrain.sh deploy/federated/service; do
[ -e "$STAGE/$f" ] || die "staged source is missing $f — wrong repo/ref?"
for f in deploy/federated/lib-superbrain.sh deploy/federated/service deploy/federated/upgrade-pre; do
[ -e "$SRC/$f" ] || die "source is missing $f — wrong repo/ref?"
done
# --- 3. Install the suite integration files ------------------------------------
# --- 3. Install the suite integration files --------------------------------------
say "Installing suite files"
if [ -f "$LIB_DST" ]; then
cp -a "$LIB_DST" "$LIB_DST.bak-$(date +%Y%m%d-%H%M%S)"
warn "backed up an existing $LIB_DST"
fi
cp "$STAGE/deploy/federated/lib-superbrain.sh" "$LIB_DST"
mkdir -p "$SVC_DST_DIR"
cp "$SRC/deploy/federated/lib-superbrain.sh" "$LIB_DST"
mkdir -p "$SVC_DST_DIR/upgrade"
[ -f "$SVC_DST_DIR/service" ] && cp -a "$SVC_DST_DIR/service" "$SVC_DST_DIR/service.bak-$(date +%Y%m%d-%H%M%S)"
cp "$STAGE/deploy/federated/service" "$SVC_DST_DIR/service"
cp "$SRC/deploy/federated/service" "$SVC_DST_DIR/service"
cp "$SRC/deploy/federated/upgrade-pre" "$SVC_DST_DIR/upgrade/pre"
chmod 755 "$SVC_DST_DIR/upgrade/pre"
# Apply IP overrides (defaults match the shipped files, so this is a no-op
# unless the operator chose different addresses). INTERNAL_IP in the service
@@ -135,11 +135,12 @@ if [ "$WEB_IP" != "192.168.0.93" ] || [ "$APP_IP" != "192.168.0.94" ] || [ "$MIG
fi
bash -n "$LIB_DST" || die "$LIB_DST does not parse — refusing to continue"
# --- 4. House install ------------------------------------------------------------
say "Running /federated/bin/installapp superbrain (builds images — several minutes)"
/federated/bin/installapp superbrain || die "installapp failed; inspect the output above. The staged source and suite files remain in place; fix the cause and re-run installapp (or uninstall and re-run this script)."
# --- 4. House install -------------------------------------------------------------
WANT_VERSION=$(sed -n 's/^VERSION=//p' "$SVC_DST_DIR/service" | tr -d '"' | head -1)
say "Running /federated/bin/installapp superbrain (pulls federatedcomputer/superbrain-*:$WANT_VERSION)"
/federated/bin/installapp superbrain || die "installapp failed; inspect the output above. The suite files remain in place; fix the cause and re-run installapp (or uninstall and re-run this script)."
# --- 5. Verify ---------------------------------------------------------------------
# --- 5. Verify ------------------------------------------------------------------------
DOMAIN_HOST=$(grep -m1 '^DOMAIN=' /etc/federated | cut -d'"' -f2)
[ -n "$DOMAIN_HOST" ] || DOMAIN_HOST=$(sed -n 's/^DOMAIN=//p' /etc/federated | tr -d '"' | head -1)
@@ -163,15 +164,15 @@ if [ "${SKIP_VERIFY:-0}" != 1 ] && [ -n "$DOMAIN_HOST" ]; then
[ "$code" = 200 ] && { ok=1; break; }
sleep 3
done
[ "$ok" = 1 ] || { warn "https://superbrain.$DOMAIN_HOST/login did not answer 200 yet (traefik may still be provisioning the certificate)"; }
[ "$ok" = 1 ] || warn "https://superbrain.$DOMAIN_HOST/login did not answer 200 yet (traefik may still be provisioning the certificate)"
fi
[ "$fail" = 0 ] || warn "install completed with warnings — review them before use"
cat <<EOF
$(say "Superbrain installed")
$(say "Superbrain installed (registry mode, version $WANT_VERSION)")
App: https://superbrain.$DOMAIN_HOST (traefik -> web 192.168.0.93-style fixed IP $WEB_IP)
App: https://superbrain.$DOMAIN_HOST (traefik -> web at $WEB_IP)
Data: shared suite postgres, database 'superbrain'
Tier: TIER=core (Authelia-only; password login/signup/reset are disabled)
@@ -189,8 +190,8 @@ $(say "Superbrain installed")
Other users are provisioned upstream (Superpanel -> LDAP -> Authelia) and
appear in Superbrain on their first SSO login.
Upgrades (interim source-build mode): one command on the host —
sudo bash /federated/apps/superbrain/deploy/federated/update.sh [git-ref]
(clone -> pg_dump -> rebuild -> recreate -> health probe -> auto-rollback
on failure). See deploy/federated/STRATEGY.md.
Updates: bump VERSION in $SVC_DST_DIR/service (or sync it from a repo
clone) and run /federated/bin/upgrade superbrain — or one command:
git clone <repo> /tmp/superbrain-repo
sudo bash /tmp/superbrain-repo/deploy/federated/update.sh [git-ref]
EOF