Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1dfd41986c | ||
|
|
fc9b6c2c42 | ||
|
|
d914a87e98 |
@@ -55,8 +55,15 @@ jobs:
|
|||||||
go vet ./internal/... .
|
go vet ./internal/... .
|
||||||
go test ./internal/...
|
go test ./internal/...
|
||||||
|
|
||||||
|
- uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
- name: Build the migrate image
|
- name: Build the migrate image
|
||||||
run: docker build -t superbrain-migrate:smoke db/
|
run: |
|
||||||
|
docker buildx build --load --build-context deploy=deploy/federated \
|
||||||
|
-t superbrain-migrate:smoke db/
|
||||||
|
# Hosts install/update from these baked files — they must be there.
|
||||||
|
docker run --rm superbrain-migrate:smoke sh -c \
|
||||||
|
'for f in install.sh update.sh lib-superbrain.sh service upgrade-pre; do test -f /deploy/$f || { echo "missing /deploy/$f"; exit 1; }; done'
|
||||||
|
|
||||||
- name: Bootstrap a fresh database with the image
|
- name: Bootstrap a fresh database with the image
|
||||||
run: |
|
run: |
|
||||||
@@ -119,6 +126,8 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
context: db
|
context: db
|
||||||
file: db/Dockerfile
|
file: db/Dockerfile
|
||||||
|
build-contexts: |
|
||||||
|
deploy=deploy/federated
|
||||||
platforms: linux/amd64,linux/arm64
|
platforms: linux/amd64,linux/arm64
|
||||||
push: true
|
push: true
|
||||||
tags: |
|
tags: |
|
||||||
|
|||||||
@@ -352,13 +352,13 @@ Authelia + shared postgres + pdns + superpanel), Superbrain is a
|
|||||||
first-class suite app. On the **core host**, as root:
|
first-class suite app. On the **core host**, as root:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
git clone https://gitea.federated.computer/Federated_Computer/brain.git /tmp/superbrain-repo
|
sudo bash -c "$(docker run --rm --pull always federatedcomputer/superbrain-migrate cat /deploy/install.sh)"
|
||||||
sudo bash /tmp/superbrain-repo/deploy/federated/install.sh
|
|
||||||
```
|
```
|
||||||
|
|
||||||
(Use whichever repository location you were given access to; the installer
|
No clone and nothing to copy: the installer and the suite integration files
|
||||||
re-clones it onto the host by default — override with `SUPERBRAIN_REPO`,
|
ship inside the migrate image at `/deploy`. Pin a release with
|
||||||
`SUPERBRAIN_REF`, or stage a local tree with `SUPERBRAIN_SRC`.)
|
`SUPERBRAIN_VERSION=1.2.3` (default `latest`), or use a local checkout's
|
||||||
|
files instead with `SUPERBRAIN_SRC=/path/to/repo`.
|
||||||
|
|
||||||
The installer:
|
The installer:
|
||||||
|
|
||||||
@@ -393,19 +393,112 @@ history: [deploy/federated/STRATEGY.md](deploy/federated/STRATEGY.md).
|
|||||||
in `/federated/services/superbrain/service` to the new release tag and run
|
in `/federated/services/superbrain/service` to the new release tag and run
|
||||||
`/federated/bin/upgrade superbrain` (the pre-hook backs up the database
|
`/federated/bin/upgrade superbrain` (the pre-hook backs up the database
|
||||||
and pulls all three images). Or one command, which also syncs the suite
|
and pulls all three images). Or one command, which also syncs the suite
|
||||||
files from the repo:
|
files from the release's migrate image (version defaults to `latest`):
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
git clone https://gitea.federated.computer/Federated_Computer/brain.git /tmp/superbrain-repo
|
sudo bash -c "$(docker run --rm --pull always federatedcomputer/superbrain-migrate cat /deploy/update.sh)" update.sh [version]
|
||||||
sudo bash /tmp/superbrain-repo/deploy/federated/update.sh [git-ref]
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Releases are semver tags without a `v` prefix (`1.0.0`); CI builds and
|
Releases are semver tags without a `v` prefix (`1.0.0`); CI builds and
|
||||||
pushes all three images under the same tag (plus `:latest`) for
|
pushes all three images under the same tag (plus `:latest`) for
|
||||||
linux/amd64 and linux/arm64. The migrate image is self-contained: it
|
linux/amd64 and linux/arm64. The migrate image is self-contained: it
|
||||||
detects an empty database, applies `schema.sql` as the superbrain user,
|
detects an empty database, applies `schema.sql` as the superbrain user,
|
||||||
then runs the checksummed migration ledger — the host never needs the
|
then runs the checksummed migration ledger, and it carries
|
||||||
source tree.
|
`deploy/federated/` at `/deploy` — the host never needs the source tree.
|
||||||
|
|
||||||
|
## Publishing release images (Docker Hub)
|
||||||
|
|
||||||
|
Releases are three multi-arch images sharing **one semver tag without a `v`
|
||||||
|
prefix** (the suite's `VERSION_RX` is `^[0-9][0-9\.]*$`), plus `:latest`:
|
||||||
|
|
||||||
|
```
|
||||||
|
federatedcomputer/superbrain-app:<version> Go API (context ., Dockerfile)
|
||||||
|
federatedcomputer/superbrain-web:<version> Next.js UI (context web, web/Dockerfile)
|
||||||
|
federatedcomputer/superbrain-migrate:<version> DB bootstrap (context db, db/Dockerfile)
|
||||||
|
```
|
||||||
|
|
||||||
|
Platforms: `linux/amd64,linux/arm64`. Source of truth: this Gitea repo
|
||||||
|
(`https://gitea.federated.computer/Federated_Computer/brain.git`) at the
|
||||||
|
matching tag. The repositories auto-create on first push under the
|
||||||
|
`federatedcomputer` namespace; keep them **public** so cores can pull
|
||||||
|
without registry credentials. Never move an existing tag — cut a new
|
||||||
|
version instead.
|
||||||
|
|
||||||
|
### Option A — CI (preferred): push a tag
|
||||||
|
|
||||||
|
`.github/workflows/release.yml` runs on Gitea Actions for tags matching
|
||||||
|
`[0-9]+.[0-9]+.[0-9]+`. A smoke job first builds the migrate image and
|
||||||
|
bootstraps a throwaway PostgreSQL with it (fresh schema, complete ledger,
|
||||||
|
idempotent re-run) and runs Go build/vet/unit tests; only then does the
|
||||||
|
publish job build and push all three images. Prerequisites (one-time,
|
||||||
|
instance admin):
|
||||||
|
|
||||||
|
1. An **act_runner** registered against `https://gitea.federated.computer`
|
||||||
|
with access to a docker socket.
|
||||||
|
2. Repo/org **Actions secrets** `DOCKERHUB_USERNAME` and `DOCKERHUB_TOKEN`
|
||||||
|
(an access token with write permission on the `federatedcomputer`
|
||||||
|
namespace).
|
||||||
|
|
||||||
|
Then releasing is:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git checkout main && git pull
|
||||||
|
git tag -a 1.2.3 -m "release 1.2.3"
|
||||||
|
git push origin 1.2.3
|
||||||
|
```
|
||||||
|
|
||||||
|
Watch the run under the repo's Actions tab; verify with
|
||||||
|
`docker manifest inspect federatedcomputer/superbrain-app:1.2.3`.
|
||||||
|
|
||||||
|
### Option B — manual build & push (no runner required)
|
||||||
|
|
||||||
|
From any Linux machine with Docker, buildx and login rights:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git clone https://gitea.federated.computer/Federated_Computer/brain.git
|
||||||
|
cd brain && git checkout 1.2.3 # always build from the tag
|
||||||
|
|
||||||
|
# One-time per machine: buildx builder + cross-arch emulation
|
||||||
|
docker buildx create --use --name multiarch
|
||||||
|
docker run --privileged --rm tonistiigi/binfmt --install arm64
|
||||||
|
|
||||||
|
docker login -u <dockerhub-user> # token prompt
|
||||||
|
|
||||||
|
# Smoke the migrate image BEFORE publishing (mirrors the CI gate):
|
||||||
|
docker buildx build --load --build-context deploy=deploy/federated -t sb-migrate:smoke db/
|
||||||
|
docker run -d --name sb-smoke-pg -e POSTGRES_USER=superbrain \
|
||||||
|
-e POSTGRES_PASSWORD=x -e POSTGRES_DB=superbrain postgres:16.15-alpine
|
||||||
|
docker run --rm --link sb-smoke-pg -e DB_HOST=sb-smoke-pg -e PGPASSWORD=x sb-migrate:smoke
|
||||||
|
docker run --rm --link sb-smoke-pg -e DB_HOST=sb-smoke-pg -e PGPASSWORD=x sb-migrate:smoke # re-run: "up to date"
|
||||||
|
docker rm -f sb-smoke-pg
|
||||||
|
|
||||||
|
# Build + push all three (each command pushes <version> and latest):
|
||||||
|
V=1.2.3
|
||||||
|
docker buildx build --platform linux/amd64,linux/arm64 --push \
|
||||||
|
-t federatedcomputer/superbrain-app:$V -t federatedcomputer/superbrain-app:latest .
|
||||||
|
docker buildx build --platform linux/amd64,linux/arm64 --push \
|
||||||
|
-t federatedcomputer/superbrain-web:$V -t federatedcomputer/superbrain-web:latest web
|
||||||
|
docker buildx build --platform linux/amd64,linux/arm64 --push \
|
||||||
|
--build-context deploy=deploy/federated \
|
||||||
|
-t federatedcomputer/superbrain-migrate:$V -t federatedcomputer/superbrain-migrate:latest db
|
||||||
|
```
|
||||||
|
|
||||||
|
Notes: the arm64 web build runs under qemu and is the slow step (tens of
|
||||||
|
minutes on modest hardware); the app image is a static Go binary and the
|
||||||
|
migrate image is `postgres:16.15-alpine` + `db/` + `deploy/federated/`
|
||||||
|
(supplied as the named `deploy` build context), both quick. Go builds
|
||||||
|
must stay legacy-builder compatible (no `$BUILDPLATFORM` tricks) so local
|
||||||
|
`docker compose build` keeps working on hosts without BuildKit defaults.
|
||||||
|
|
||||||
|
### After publishing
|
||||||
|
|
||||||
|
Bump `VERSION=` in `deploy/federated/service` to the new tag (commit it —
|
||||||
|
and release it — hosts sync the service file via `update.sh` from the
|
||||||
|
migrate image), then on each
|
||||||
|
core: `/federated/bin/upgrade superbrain` (or update.sh, which syncs the
|
||||||
|
service file first). The pre-upgrade hook takes a pg_dump and pulls all
|
||||||
|
three images; `upgrade_app` snapshots, redeploys and rewrites
|
||||||
|
`IMAGE_VERSION` in the app `.env`.
|
||||||
|
|
||||||
## Environment variable reference
|
## Environment variable reference
|
||||||
|
|
||||||
|
|||||||
+9
-1
@@ -3,13 +3,21 @@
|
|||||||
# the source tree. Entrypoint: bootstrap.sh (empty database => schema.sql as
|
# the source tree. Entrypoint: bootstrap.sh (empty database => schema.sql as
|
||||||
# DB_USER, then always the checksummed migration ledger).
|
# DB_USER, then always the checksummed migration ledger).
|
||||||
#
|
#
|
||||||
|
# Also ships deploy/federated/ at /deploy (install.sh, update.sh and the
|
||||||
|
# suite integration files), so a core host needs nothing but this image:
|
||||||
|
# docker run --rm federatedcomputer/superbrain-migrate cat /deploy/install.sh
|
||||||
|
# The files arrive via a named build context (BuildKit/buildx only; the dev
|
||||||
|
# compose never builds this image):
|
||||||
|
# docker buildx build --build-context deploy=deploy/federated db/
|
||||||
|
#
|
||||||
# Base image = the same postgres alpine the dev stack's migrate service uses;
|
# Base image = the same postgres alpine the dev stack's migrate service uses;
|
||||||
# only the psql client is exercised. Client 16 against a newer server (the
|
# only the psql client is exercised. Client 16 against a newer server (the
|
||||||
# federated suite runs 17.x) is the supported direction.
|
# federated suite runs 17.x) is the supported direction.
|
||||||
FROM postgres:16.15-alpine
|
FROM postgres:16.15-alpine
|
||||||
|
|
||||||
COPY . /db
|
COPY . /db
|
||||||
RUN chmod +x /db/bootstrap.sh /db/migrate.sh
|
COPY --from=deploy . /deploy
|
||||||
|
RUN chmod +x /db/bootstrap.sh /db/migrate.sh /deploy/install.sh /deploy/update.sh
|
||||||
|
|
||||||
WORKDIR /db
|
WORKDIR /db
|
||||||
CMD ["sh", "/db/bootstrap.sh"]
|
CMD ["sh", "/db/bootstrap.sh"]
|
||||||
|
|||||||
@@ -71,11 +71,14 @@ Authelia required, fcore SMTP credential, fixed-IP collisions with
|
|||||||
`SUPERBRAIN_*_IP` overrides; installs lib/service/hook; runs
|
`SUPERBRAIN_*_IP` overrides; installs lib/service/hook; runs
|
||||||
`/federated/bin/installapp superbrain`; verifies containers, Authelia
|
`/federated/bin/installapp superbrain`; verifies containers, Authelia
|
||||||
client + claims markers, HTTPS login) and `deploy/federated/update.sh`
|
client + claims markers, HTTPS login) and `deploy/federated/update.sh`
|
||||||
(clone at ref → sync lib/service/hook with parse-checks and backups →
|
(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/
|
re-render compose via `render_superbrain_compose` → `/federated/bin/
|
||||||
upgrade superbrain` → same-version compose safety pass → health probe).
|
upgrade superbrain` → same-version compose safety pass → health probe).
|
||||||
The registry-mode app dir holds ONLY compose + .env — update.sh therefore
|
The registry-mode app dir holds ONLY compose + .env, so both scripts ship
|
||||||
runs from a repo clone, not from the app dir (the source-mode
|
inside the migrate image at `/deploy` (since 1.0.1) and run via
|
||||||
|
`bash -c "$(docker run --rm federatedcomputer/superbrain-migrate cat
|
||||||
|
/deploy/<script>)"` — no repo clone on the host (the source-mode
|
||||||
self-location of the old update.sh died with interim mode).
|
self-location of the old update.sh died with interim mode).
|
||||||
|
|
||||||
A deliberate non-goal remains: an in-app "update" button — the scratch
|
A deliberate non-goal remains: an in-app "update" button — the scratch
|
||||||
|
|||||||
+29
-32
@@ -3,10 +3,10 @@
|
|||||||
# Install Superbrain into a federated "core" suite host (REGISTRY mode).
|
# Install Superbrain into a federated "core" suite host (REGISTRY mode).
|
||||||
#
|
#
|
||||||
# For operators running their own copy of the federated suite. On the
|
# For operators running their own copy of the federated suite. On the
|
||||||
# CORE HOST, as root:
|
# CORE HOST, as root — no clone, no copying files around; this script and
|
||||||
|
# the deploy files ship inside the migrate image at /deploy:
|
||||||
#
|
#
|
||||||
# git clone <this-repo> /tmp/superbrain-repo
|
# sudo bash -c "$(docker run --rm --pull always federatedcomputer/superbrain-migrate cat /deploy/install.sh)"
|
||||||
# sudo bash /tmp/superbrain-repo/deploy/federated/install.sh
|
|
||||||
#
|
#
|
||||||
# No source is built or stored on the host: the three release images
|
# No source is built or stored on the host: the three release images
|
||||||
# (federatedcomputer/superbrain-{app,web,migrate}, one shared version tag,
|
# (federatedcomputer/superbrain-{app,web,migrate}, one shared version tag,
|
||||||
@@ -18,7 +18,7 @@
|
|||||||
# 1. Preflights the suite (installapp, functions.sh, /etc/federated, the
|
# 1. Preflights the suite (installapp, functions.sh, /etc/federated, the
|
||||||
# core docker network, Authelia — REQUIRED because the core tier is
|
# core docker network, Authelia — REQUIRED because the core tier is
|
||||||
# Authelia-only — and the fcore SMTP credential for notification mail).
|
# Authelia-only — and the fcore SMTP credential for notification mail).
|
||||||
# 2. Gets the deploy files from a repo clone (or $SUPERBRAIN_SRC).
|
# 2. Gets the deploy files from the migrate image (or $SUPERBRAIN_SRC).
|
||||||
# 3. Installs the suite integration: /federated/lib/superbrain.sh,
|
# 3. Installs the suite integration: /federated/lib/superbrain.sh,
|
||||||
# /federated/services/superbrain/{service,upgrade/pre}, with fixed-IP
|
# /federated/services/superbrain/{service,upgrade/pre}, with fixed-IP
|
||||||
# collision checks and SUPERBRAIN_*_IP overrides.
|
# collision checks and SUPERBRAIN_*_IP overrides.
|
||||||
@@ -29,21 +29,21 @@
|
|||||||
# 5. Verifies and prints first-login steps.
|
# 5. Verifies and prints first-login steps.
|
||||||
#
|
#
|
||||||
# Environment overrides:
|
# Environment overrides:
|
||||||
# SUPERBRAIN_REPO git URL to clone (default: this repo's origin)
|
# SUPERBRAIN_VERSION release whose deploy files to use (default: latest;
|
||||||
# SUPERBRAIN_REF branch/tag to clone (default: main)
|
# the service file inside it pins the image version)
|
||||||
# SUPERBRAIN_SRC local repo checkout to take the deploy files from
|
# SUPERBRAIN_SRC local repo checkout to take the deploy files from
|
||||||
|
# instead of the image (development)
|
||||||
# SUPERBRAIN_WEB_IP / SUPERBRAIN_APP_IP / SUPERBRAIN_MIGRATE_IP
|
# SUPERBRAIN_WEB_IP / SUPERBRAIN_APP_IP / SUPERBRAIN_MIGRATE_IP
|
||||||
# fixed core-network IPs (default .93/.94/.95 — the
|
# fixed core-network IPs (default .93/.94/.95 — the
|
||||||
# installer refuses if they are already allocated)
|
# installer refuses if they are already allocated)
|
||||||
# SKIP_VERIFY=1 skip the post-install HTTPS probe
|
# SKIP_VERIFY=1 skip the post-install HTTPS probe
|
||||||
#
|
#
|
||||||
# Updates after install: sudo bash <repo>/deploy/federated/update.sh
|
# Updates after install: update.sh from the same image (syncs the service
|
||||||
# (syncs the service file's VERSION, then runs the house upgrade flow).
|
# file's VERSION, then runs the house upgrade flow).
|
||||||
#
|
#
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
REPO_DEFAULT="https://gitea.federated.computer/Federated_Computer/brain.git"
|
IMAGE="federatedcomputer/superbrain-migrate:${SUPERBRAIN_VERSION:-latest}"
|
||||||
CLONE=/tmp/superbrain-install-src
|
|
||||||
LIB_DST=/federated/lib/superbrain.sh
|
LIB_DST=/federated/lib/superbrain.sh
|
||||||
SVC_DST_DIR=/federated/services/superbrain
|
SVC_DST_DIR=/federated/services/superbrain
|
||||||
|
|
||||||
@@ -56,7 +56,7 @@ warn() { printf '\033[1;33mwarning:\033[0m %s\n' "$*" >&2; }
|
|||||||
die() { printf '\033[1;31merror:\033[0m %s\n' "$*" >&2; exit 1; }
|
die() { printf '\033[1;31merror:\033[0m %s\n' "$*" >&2; exit 1; }
|
||||||
|
|
||||||
# --- 0. Preflights -----------------------------------------------------------
|
# --- 0. Preflights -----------------------------------------------------------
|
||||||
[ "$(id -u)" = 0 ] || die "run as root on the core host (sudo bash $0)"
|
[ "$(id -u)" = 0 ] || die "run as root on the core host"
|
||||||
[ -x /federated/bin/installapp ] || die "/federated/bin/installapp missing — this does not look like a federated suite host"
|
[ -x /federated/bin/installapp ] || die "/federated/bin/installapp missing — this does not look like a federated suite host"
|
||||||
[ -f /federated/lib/functions.sh ] || die "/federated/lib/functions.sh missing"
|
[ -f /federated/lib/functions.sh ] || die "/federated/lib/functions.sh missing"
|
||||||
[ -f /etc/federated ] || die "/etc/federated missing"
|
[ -f /etc/federated ] || die "/etc/federated missing"
|
||||||
@@ -87,27 +87,25 @@ ip_taken() { # $1 = ip
|
|||||||
}
|
}
|
||||||
for ip in "$WEB_IP" "$APP_IP" "$MIGRATE_IP"; do
|
for ip in "$WEB_IP" "$APP_IP" "$MIGRATE_IP"; do
|
||||||
if ip_taken "$ip"; then
|
if ip_taken "$ip"; then
|
||||||
die "IP $ip is already allocated on this host. Pick free addresses and re-run with e.g.:
|
die "IP $ip is already allocated on this host. Pick free addresses and re-run with them in the environment, e.g.:
|
||||||
sudo SUPERBRAIN_WEB_IP=192.168.0.193 SUPERBRAIN_APP_IP=192.168.0.194 SUPERBRAIN_MIGRATE_IP=192.168.0.195 bash $0"
|
sudo SUPERBRAIN_WEB_IP=192.168.0.193 SUPERBRAIN_APP_IP=192.168.0.194 SUPERBRAIN_MIGRATE_IP=192.168.0.195 bash -c \"\$(docker run --rm $IMAGE cat /deploy/install.sh)\""
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
# --- 2. Get the deploy files ----------------------------------------------------
|
# --- 2. Get the deploy files ----------------------------------------------------
|
||||||
if [ -n "${SUPERBRAIN_SRC:-}" ]; then
|
if [ -n "${SUPERBRAIN_SRC:-}" ]; then
|
||||||
SRC="$SUPERBRAIN_SRC"
|
DEPLOY="$SUPERBRAIN_SRC/deploy/federated"
|
||||||
[ -f "$SRC/deploy/federated/lib-superbrain.sh" ] || die "SUPERBRAIN_SRC=$SRC lacks deploy/federated files"
|
[ -f "$DEPLOY/lib-superbrain.sh" ] || die "SUPERBRAIN_SRC=$SUPERBRAIN_SRC lacks deploy/federated files"
|
||||||
else
|
else
|
||||||
command -v git >/dev/null || die "git not found (or set SUPERBRAIN_SRC=/path/to/repo)"
|
say "Pulling $IMAGE for the deploy files"
|
||||||
REPO="${SUPERBRAIN_REPO:-$REPO_DEFAULT}"
|
docker pull -q "$IMAGE" >/dev/null || die "could not pull $IMAGE — does the release exist on Docker Hub?"
|
||||||
REF="${SUPERBRAIN_REF:-main}"
|
DEPLOY=$(mktemp -d)
|
||||||
say "Cloning $REPO ($REF) for the deploy files"
|
trap 'rm -rf "$DEPLOY"' EXIT
|
||||||
rm -rf "$CLONE"
|
docker run --rm "$IMAGE" tar -C /deploy -c . | tar -x -C "$DEPLOY" \
|
||||||
git clone --depth 1 --branch "$REF" "$REPO" "$CLONE" \
|
|| die "could not extract /deploy from $IMAGE"
|
||||||
|| die "git clone failed — check repository access/credentials"
|
|
||||||
SRC="$CLONE"
|
|
||||||
fi
|
fi
|
||||||
for f in deploy/federated/lib-superbrain.sh deploy/federated/service deploy/federated/upgrade-pre; do
|
for f in lib-superbrain.sh service upgrade-pre; do
|
||||||
[ -e "$SRC/$f" ] || die "source is missing $f — wrong repo/ref?"
|
[ -e "$DEPLOY/$f" ] || die "deploy files are missing $f — wrong image/version?"
|
||||||
done
|
done
|
||||||
|
|
||||||
# --- 3. Install the suite integration files --------------------------------------
|
# --- 3. Install the suite integration files --------------------------------------
|
||||||
@@ -116,11 +114,11 @@ if [ -f "$LIB_DST" ]; then
|
|||||||
cp -a "$LIB_DST" "$LIB_DST.bak-$(date +%Y%m%d-%H%M%S)"
|
cp -a "$LIB_DST" "$LIB_DST.bak-$(date +%Y%m%d-%H%M%S)"
|
||||||
warn "backed up an existing $LIB_DST"
|
warn "backed up an existing $LIB_DST"
|
||||||
fi
|
fi
|
||||||
cp "$SRC/deploy/federated/lib-superbrain.sh" "$LIB_DST"
|
cp "$DEPLOY/lib-superbrain.sh" "$LIB_DST"
|
||||||
mkdir -p "$SVC_DST_DIR/upgrade"
|
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)"
|
[ -f "$SVC_DST_DIR/service" ] && cp -a "$SVC_DST_DIR/service" "$SVC_DST_DIR/service.bak-$(date +%Y%m%d-%H%M%S)"
|
||||||
cp "$SRC/deploy/federated/service" "$SVC_DST_DIR/service"
|
cp "$DEPLOY/service" "$SVC_DST_DIR/service"
|
||||||
cp "$SRC/deploy/federated/upgrade-pre" "$SVC_DST_DIR/upgrade/pre"
|
cp "$DEPLOY/upgrade-pre" "$SVC_DST_DIR/upgrade/pre"
|
||||||
chmod 755 "$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
|
# Apply IP overrides (defaults match the shipped files, so this is a no-op
|
||||||
@@ -190,8 +188,7 @@ $(say "Superbrain installed (registry mode, version $WANT_VERSION)")
|
|||||||
Other users are provisioned upstream (Superpanel -> LDAP -> Authelia) and
|
Other users are provisioned upstream (Superpanel -> LDAP -> Authelia) and
|
||||||
appear in Superbrain on their first SSO login.
|
appear in Superbrain on their first SSO login.
|
||||||
|
|
||||||
Updates: bump VERSION in $SVC_DST_DIR/service (or sync it from a repo
|
Updates: bump VERSION in $SVC_DST_DIR/service and run
|
||||||
clone) and run /federated/bin/upgrade superbrain — or one command:
|
/federated/bin/upgrade superbrain — or one command (default: latest):
|
||||||
git clone <repo> /tmp/superbrain-repo
|
sudo bash -c "\\$(docker run --rm --pull always federatedcomputer/superbrain-migrate cat /deploy/update.sh)" update.sh [version]
|
||||||
sudo bash /tmp/superbrain-repo/deploy/federated/update.sh [git-ref]
|
|
||||||
EOF
|
EOF
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ SUPERBRAIN_APP_IP="192.168.0.94"
|
|||||||
SUPERBRAIN_MIGRATE_IP="192.168.0.95"
|
SUPERBRAIN_MIGRATE_IP="192.168.0.95"
|
||||||
# Release to install; the generic `upgrade` flow keeps .env in step with the
|
# Release to install; the generic `upgrade` flow keeps .env in step with the
|
||||||
# service file's VERSION afterwards.
|
# service file's VERSION afterwards.
|
||||||
SUPERBRAIN_IMAGE_VERSION="1.0.0"
|
SUPERBRAIN_IMAGE_VERSION="1.0.1"
|
||||||
|
|
||||||
# render_superbrain_compose writes the app-dir compose file. Called by
|
# render_superbrain_compose writes the app-dir compose file. Called by
|
||||||
# config_superbrain (install) and by deploy/federated/update.sh after a lib
|
# config_superbrain (install) and by deploy/federated/update.sh after a lib
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ NAME=superbrain
|
|||||||
DESCRIPTION="Bookmark & Knowledge Base"
|
DESCRIPTION="Bookmark & Knowledge Base"
|
||||||
DOCS=https://github.com/andrew/superbrain
|
DOCS=https://github.com/andrew/superbrain
|
||||||
CONTAINER=federatedcomputer/superbrain-app
|
CONTAINER=federatedcomputer/superbrain-app
|
||||||
VERSION=1.0.0
|
VERSION=1.0.1
|
||||||
INTERNAL_IP=192.168.0.93
|
INTERNAL_IP=192.168.0.93
|
||||||
DEPENDS="postgresql"
|
DEPENDS="postgresql"
|
||||||
PORTS=3000
|
PORTS=3000
|
||||||
|
|||||||
+43
-29
@@ -2,14 +2,14 @@
|
|||||||
#
|
#
|
||||||
# Update Superbrain on a federated core host (REGISTRY mode).
|
# Update Superbrain on a federated core host (REGISTRY mode).
|
||||||
#
|
#
|
||||||
# The app dir holds only compose + .env (no source), so this script runs
|
# The app dir holds only compose + .env (no source); this script and the
|
||||||
# from a repo clone:
|
# deploy files ship inside the migrate image at /deploy, so no clone:
|
||||||
#
|
#
|
||||||
# git clone <repo> /tmp/superbrain-repo
|
# sudo bash -c "$(docker run --rm --pull always federatedcomputer/superbrain-migrate cat /deploy/update.sh)" update.sh [version]
|
||||||
# sudo bash /tmp/superbrain-repo/deploy/federated/update.sh [git-ref]
|
|
||||||
#
|
#
|
||||||
# What it does:
|
# What it does:
|
||||||
# 1. Clones the repo at REF (default main) — or uses $SUPERBRAIN_SRC.
|
# 1. Pulls federatedcomputer/superbrain-migrate:VERSION (default latest)
|
||||||
|
# and extracts its /deploy files — or uses $SUPERBRAIN_SRC.
|
||||||
# 2. Syncs the suite integration files (lib, service file, upgrade/pre
|
# 2. Syncs the suite integration files (lib, service file, upgrade/pre
|
||||||
# hook) with backups and a parse check — the service file carries the
|
# hook) with backups and a parse check — the service file carries the
|
||||||
# desired VERSION, which is how a release reaches the host.
|
# desired VERSION, which is how a release reaches the host.
|
||||||
@@ -21,14 +21,14 @@
|
|||||||
# 5. compose up -d safety pass (applies same-version compose-only
|
# 5. compose up -d safety pass (applies same-version compose-only
|
||||||
# changes), then health-probes app + web.
|
# changes), then health-probes app + web.
|
||||||
#
|
#
|
||||||
# Environment: SUPERBRAIN_REPO, SUPERBRAIN_REF (or $1), SUPERBRAIN_SRC.
|
# Environment: SUPERBRAIN_VERSION (or $1), SUPERBRAIN_SRC (local repo
|
||||||
|
# checkout instead of the image; development).
|
||||||
#
|
#
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
REPO_DEFAULT="https://gitea.federated.computer/Federated_Computer/brain.git"
|
|
||||||
APP_DIR=/federated/apps/superbrain
|
APP_DIR=/federated/apps/superbrain
|
||||||
CLONE=/tmp/superbrain-update-src
|
IMAGE="federatedcomputer/superbrain-migrate:${1:-${SUPERBRAIN_VERSION:-latest}}"
|
||||||
REF="${1:-${SUPERBRAIN_REF:-main}}"
|
STAMP=$(date +%Y%m%d-%H%M%S)
|
||||||
|
|
||||||
say() { printf '\033[1;34m==>\033[0m %s\n' "$*"; }
|
say() { printf '\033[1;34m==>\033[0m %s\n' "$*"; }
|
||||||
die() { printf '\033[1;31merror:\033[0m %s\n' "$*" >&2; exit 1; }
|
die() { printf '\033[1;31merror:\033[0m %s\n' "$*" >&2; exit 1; }
|
||||||
@@ -40,32 +40,33 @@ die() { printf '\033[1;31merror:\033[0m %s\n' "$*" >&2; exit 1; }
|
|||||||
|| die "$APP_DIR does not look installed (compose/.env missing) — run deploy/federated/install.sh first"
|
|| die "$APP_DIR does not look installed (compose/.env missing) — run deploy/federated/install.sh first"
|
||||||
|
|
||||||
if [ -n "${SUPERBRAIN_SRC:-}" ]; then
|
if [ -n "${SUPERBRAIN_SRC:-}" ]; then
|
||||||
SRC="$SUPERBRAIN_SRC"
|
DEPLOY="$SUPERBRAIN_SRC/deploy/federated"
|
||||||
[ -f "$SRC/deploy/federated/lib-superbrain.sh" ] || die "SUPERBRAIN_SRC lacks deploy/federated files"
|
[ -f "$DEPLOY/lib-superbrain.sh" ] || die "SUPERBRAIN_SRC lacks deploy/federated files"
|
||||||
|
SOURCE="$SUPERBRAIN_SRC"
|
||||||
else
|
else
|
||||||
command -v git >/dev/null || die "git not found (or set SUPERBRAIN_SRC=/path/to/repo)"
|
say "Pulling $IMAGE for the deploy files"
|
||||||
say "Fetching ${SUPERBRAIN_REPO:-$REPO_DEFAULT} @ $REF"
|
docker pull -q "$IMAGE" >/dev/null || die "could not pull $IMAGE — does the release exist on Docker Hub?"
|
||||||
rm -rf "$CLONE"
|
DEPLOY=$(mktemp -d)
|
||||||
if ! git clone --quiet --depth 1 --branch "$REF" "${SUPERBRAIN_REPO:-$REPO_DEFAULT}" "$CLONE" 2>/dev/null; then
|
trap 'rm -rf "$DEPLOY"' EXIT
|
||||||
git clone --quiet "${SUPERBRAIN_REPO:-$REPO_DEFAULT}" "$CLONE" || die "git clone failed — check repository access"
|
docker run --rm "$IMAGE" tar -C /deploy -c . | tar -x -C "$DEPLOY" \
|
||||||
git -C "$CLONE" checkout --quiet "$REF" || die "ref $REF not found"
|
|| die "could not extract /deploy from $IMAGE"
|
||||||
fi
|
SOURCE="$IMAGE"
|
||||||
SRC="$CLONE"
|
|
||||||
fi
|
fi
|
||||||
NEW_REV=$(git -C "$SRC" rev-parse --short HEAD 2>/dev/null || echo "$REF")
|
for f in lib-superbrain.sh service upgrade-pre; do
|
||||||
|
[ -e "$DEPLOY/$f" ] || die "deploy files are missing $f — wrong image/version?"
|
||||||
|
done
|
||||||
|
|
||||||
# --- 2. Sync suite files (parse-checked, backed up) ------------------------------
|
# --- 2. Sync suite files (parse-checked, backed up) ------------------------------
|
||||||
say "Syncing suite integration files (revision $NEW_REV)"
|
say "Syncing suite integration files from $SOURCE"
|
||||||
LIB=/federated/lib/superbrain.sh
|
LIB=/federated/lib/superbrain.sh
|
||||||
cp "$SRC/deploy/federated/lib-superbrain.sh" /tmp/lib-superbrain.sh.new
|
bash -n "$DEPLOY/lib-superbrain.sh" || die "staged lib-superbrain.sh does not parse — aborting"
|
||||||
bash -n /tmp/lib-superbrain.sh.new || die "staged lib-superbrain.sh does not parse — aborting"
|
[ -f "$LIB" ] && cp -a "$LIB" "$LIB.bak-$STAMP"
|
||||||
[ -f "$LIB" ] && cp -a "$LIB" "$LIB.bak-$NEW_REV"
|
cp "$DEPLOY/lib-superbrain.sh" "$LIB"
|
||||||
mv /tmp/lib-superbrain.sh.new "$LIB"
|
|
||||||
|
|
||||||
mkdir -p /federated/services/superbrain/upgrade
|
mkdir -p /federated/services/superbrain/upgrade
|
||||||
[ -f /federated/services/superbrain/service ] && cp -a /federated/services/superbrain/service "/federated/services/superbrain/service.bak-$NEW_REV"
|
[ -f /federated/services/superbrain/service ] && cp -a /federated/services/superbrain/service "/federated/services/superbrain/service.bak-$STAMP"
|
||||||
cp "$SRC/deploy/federated/service" /federated/services/superbrain/service
|
cp "$DEPLOY/service" /federated/services/superbrain/service
|
||||||
cp "$SRC/deploy/federated/upgrade-pre" /federated/services/superbrain/upgrade/pre
|
cp "$DEPLOY/upgrade-pre" /federated/services/superbrain/upgrade/pre
|
||||||
chmod 755 /federated/services/superbrain/upgrade/pre
|
chmod 755 /federated/services/superbrain/upgrade/pre
|
||||||
|
|
||||||
# --- 3. Re-render the compose from the fresh lib ----------------------------------
|
# --- 3. Re-render the compose from the fresh lib ----------------------------------
|
||||||
@@ -79,6 +80,19 @@ grep -q "container_name: superbrain-app" "$APP_DIR/docker-compose.yml" \
|
|||||||
|
|
||||||
# --- 4. House upgrade flow ----------------------------------------------------------
|
# --- 4. House upgrade flow ----------------------------------------------------------
|
||||||
WANT_VERSION=$(sed -n 's/^VERSION=//p' /federated/services/superbrain/service | tr -d '"' | head -1)
|
WANT_VERSION=$(sed -n 's/^VERSION=//p' /federated/services/superbrain/service | tr -d '"' | head -1)
|
||||||
|
|
||||||
|
# Source-mode migration: interim installs (2026-10-25..29) carry
|
||||||
|
# IMAGE_VERSION=local plus IMAGE_VERSION_HOLD=1, which makes upgrade_app
|
||||||
|
# skip the app entirely — and the re-rendered compose would try to pull a
|
||||||
|
# nonexistent :local tag. Convert .env to the registry version the service
|
||||||
|
# file wants before upgrading.
|
||||||
|
if grep -q '^IMAGE_VERSION_HOLD=' "$APP_DIR/.env"; then
|
||||||
|
say "Migrating .env from source-build mode to registry mode ($WANT_VERSION)"
|
||||||
|
sed -i '/^IMAGE_VERSION_HOLD=/d' "$APP_DIR/.env"
|
||||||
|
sed -i "s#^IMAGE_VERSION=.*#IMAGE_VERSION=\"$WANT_VERSION\"#" "$APP_DIR/.env"
|
||||||
|
fi
|
||||||
|
grep -q '^IMAGE_VERSION=' "$APP_DIR/.env" || echo "IMAGE_VERSION=\"$WANT_VERSION\"" >> "$APP_DIR/.env"
|
||||||
|
|
||||||
HAVE_VERSION=$(sed -n 's/^IMAGE_VERSION=//p' "$APP_DIR/.env" | tr -d '"' | tail -1)
|
HAVE_VERSION=$(sed -n 's/^IMAGE_VERSION=//p' "$APP_DIR/.env" | tr -d '"' | tail -1)
|
||||||
say "Running the house upgrade flow (have $HAVE_VERSION, service file wants $WANT_VERSION)"
|
say "Running the house upgrade flow (have $HAVE_VERSION, service file wants $WANT_VERSION)"
|
||||||
/federated/bin/upgrade superbrain || die "upgrade failed — inspect the output above"
|
/federated/bin/upgrade superbrain || die "upgrade failed — inspect the output above"
|
||||||
@@ -102,4 +116,4 @@ if [ "$healthy" != 1 ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
NOW_VERSION=$(sed -n 's/^IMAGE_VERSION=//p' "$APP_DIR/.env" | tr -d '"' | tail -1)
|
NOW_VERSION=$(sed -n 's/^IMAGE_VERSION=//p' "$APP_DIR/.env" | tr -d '"' | tail -1)
|
||||||
say "Superbrain is at image version $NOW_VERSION (repo revision $NEW_REV), healthy"
|
say "Superbrain is at image version $NOW_VERSION (deploy files from $SOURCE), healthy"
|
||||||
|
|||||||
Reference in New Issue
Block a user