Ship install/update scripts in the migrate image; no repo clone on hosts
This commit is contained in:
+30
-29
@@ -2,14 +2,14 @@
|
||||
#
|
||||
# Update Superbrain on a federated core host (REGISTRY mode).
|
||||
#
|
||||
# The app dir holds only compose + .env (no source), so this script runs
|
||||
# from a repo clone:
|
||||
# The app dir holds only compose + .env (no source); this script and the
|
||||
# deploy files ship inside the migrate image at /deploy, so no clone:
|
||||
#
|
||||
# git clone <repo> /tmp/superbrain-repo
|
||||
# sudo bash /tmp/superbrain-repo/deploy/federated/update.sh [git-ref]
|
||||
# sudo bash -c "$(docker run --rm --pull always federatedcomputer/superbrain-migrate cat /deploy/update.sh)" update.sh [version]
|
||||
#
|
||||
# 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
|
||||
# hook) with backups and a parse check — the service file carries the
|
||||
# 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
|
||||
# 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
|
||||
|
||||
REPO_DEFAULT="https://gitea.federated.computer/Federated_Computer/brain.git"
|
||||
APP_DIR=/federated/apps/superbrain
|
||||
CLONE=/tmp/superbrain-update-src
|
||||
REF="${1:-${SUPERBRAIN_REF:-main}}"
|
||||
IMAGE="federatedcomputer/superbrain-migrate:${1:-${SUPERBRAIN_VERSION:-latest}}"
|
||||
STAMP=$(date +%Y%m%d-%H%M%S)
|
||||
|
||||
say() { printf '\033[1;34m==>\033[0m %s\n' "$*"; }
|
||||
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"
|
||||
|
||||
if [ -n "${SUPERBRAIN_SRC:-}" ]; then
|
||||
SRC="$SUPERBRAIN_SRC"
|
||||
[ -f "$SRC/deploy/federated/lib-superbrain.sh" ] || die "SUPERBRAIN_SRC lacks deploy/federated files"
|
||||
DEPLOY="$SUPERBRAIN_SRC/deploy/federated"
|
||||
[ -f "$DEPLOY/lib-superbrain.sh" ] || die "SUPERBRAIN_SRC lacks deploy/federated files"
|
||||
SOURCE="$SUPERBRAIN_SRC"
|
||||
else
|
||||
command -v git >/dev/null || die "git not found (or set SUPERBRAIN_SRC=/path/to/repo)"
|
||||
say "Fetching ${SUPERBRAIN_REPO:-$REPO_DEFAULT} @ $REF"
|
||||
rm -rf "$CLONE"
|
||||
if ! git clone --quiet --depth 1 --branch "$REF" "${SUPERBRAIN_REPO:-$REPO_DEFAULT}" "$CLONE" 2>/dev/null; then
|
||||
git clone --quiet "${SUPERBRAIN_REPO:-$REPO_DEFAULT}" "$CLONE" || die "git clone failed — check repository access"
|
||||
git -C "$CLONE" checkout --quiet "$REF" || die "ref $REF not found"
|
||||
fi
|
||||
SRC="$CLONE"
|
||||
say "Pulling $IMAGE for the deploy files"
|
||||
docker pull -q "$IMAGE" >/dev/null || die "could not pull $IMAGE — does the release exist on Docker Hub?"
|
||||
DEPLOY=$(mktemp -d)
|
||||
trap 'rm -rf "$DEPLOY"' EXIT
|
||||
docker run --rm "$IMAGE" tar -C /deploy -c . | tar -x -C "$DEPLOY" \
|
||||
|| die "could not extract /deploy from $IMAGE"
|
||||
SOURCE="$IMAGE"
|
||||
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) ------------------------------
|
||||
say "Syncing suite integration files (revision $NEW_REV)"
|
||||
say "Syncing suite integration files from $SOURCE"
|
||||
LIB=/federated/lib/superbrain.sh
|
||||
cp "$SRC/deploy/federated/lib-superbrain.sh" /tmp/lib-superbrain.sh.new
|
||||
bash -n /tmp/lib-superbrain.sh.new || die "staged lib-superbrain.sh does not parse — aborting"
|
||||
[ -f "$LIB" ] && cp -a "$LIB" "$LIB.bak-$NEW_REV"
|
||||
mv /tmp/lib-superbrain.sh.new "$LIB"
|
||||
bash -n "$DEPLOY/lib-superbrain.sh" || die "staged lib-superbrain.sh does not parse — aborting"
|
||||
[ -f "$LIB" ] && cp -a "$LIB" "$LIB.bak-$STAMP"
|
||||
cp "$DEPLOY/lib-superbrain.sh" "$LIB"
|
||||
|
||||
mkdir -p /federated/services/superbrain/upgrade
|
||||
[ -f /federated/services/superbrain/service ] && cp -a /federated/services/superbrain/service "/federated/services/superbrain/service.bak-$NEW_REV"
|
||||
cp "$SRC/deploy/federated/service" /federated/services/superbrain/service
|
||||
cp "$SRC/deploy/federated/upgrade-pre" /federated/services/superbrain/upgrade/pre
|
||||
[ -f /federated/services/superbrain/service ] && cp -a /federated/services/superbrain/service "/federated/services/superbrain/service.bak-$STAMP"
|
||||
cp "$DEPLOY/service" /federated/services/superbrain/service
|
||||
cp "$DEPLOY/upgrade-pre" /federated/services/superbrain/upgrade/pre
|
||||
chmod 755 /federated/services/superbrain/upgrade/pre
|
||||
|
||||
# --- 3. Re-render the compose from the fresh lib ----------------------------------
|
||||
@@ -115,4 +116,4 @@ if [ "$healthy" != 1 ]; then
|
||||
fi
|
||||
|
||||
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