Files
Andrew S Erwin 341cdce026
release gate / check (push) Canceled after 4m3s
release / smoke (push) Successful in 10m13s
release / publish (push) Failing after 12m48s
Registry mode: publish app/web/migrate images, drop source builds on hosts
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.
2026-10-29 10:21:10 -05:00

44 lines
1.6 KiB
Bash

#!/bin/sh
# bootstrap.sh — the federatedcomputer/superbrain-migrate entrypoint.
#
# Makes fresh-install and upgrade the SAME command, so a server never needs
# the source tree:
# 1. wait for PostgreSQL,
# 2. if the database has no tables, apply /db/schema.sql AS DB_USER
# (object ownership matters: every later migration must be able to
# ALTER these objects — applying as postgres would strand ownership),
# 3. always run /db/migrate.sh (ordered, checksummed, advisory-locked,
# one transaction per file; idempotent against a bootstrapped schema).
#
# Environment (same contract as migrate.sh):
# PGPASSWORD required
# DB_HOST default "db"
# DB_USER default "superbrain"
# DB_NAME default "superbrain"
set -eu
DB_HOST="${DB_HOST:-db}"
DB_USER="${DB_USER:-superbrain}"
DB_NAME="${DB_NAME:-superbrain}"
[ -n "${PGPASSWORD:-}" ] || { echo "bootstrap: PGPASSWORD is required" >&2; exit 1; }
psql() { command psql -h "$DB_HOST" -U "$DB_USER" -d "$DB_NAME" -v ON_ERROR_STOP=1 "$@"; }
echo "bootstrap: waiting for postgres at $DB_HOST"
i=0
until pg_isready -q -h "$DB_HOST" -U "$DB_USER" 2>/dev/null; do
i=$((i + 1))
[ "$i" -ge 60 ] && { echo "bootstrap: postgres at $DB_HOST never became ready" >&2; exit 1; }
sleep 2
done
TABLES=$(psql -t -A -c "SELECT count(*) FROM information_schema.tables WHERE table_schema='public' AND table_type='BASE TABLE'")
if [ "$TABLES" = "0" ]; then
echo "bootstrap: empty database '$DB_NAME' - applying schema.sql as $DB_USER"
psql -q -f /db/schema.sql
else
echo "bootstrap: database has $TABLES tables - skipping schema.sql"
fi
exec sh /db/migrate.sh