diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 729c247..5306138 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -55,8 +55,15 @@ jobs: go vet ./internal/... . go test ./internal/... + - uses: docker/setup-buildx-action@v3 + - 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 run: | @@ -119,6 +126,8 @@ jobs: with: context: db file: db/Dockerfile + build-contexts: | + deploy=deploy/federated platforms: linux/amd64,linux/arm64 push: true tags: | diff --git a/README.md b/README.md index c28a2e0..1e13321 100644 --- a/README.md +++ b/README.md @@ -352,13 +352,13 @@ Authelia + shared postgres + pdns + superpanel), Superbrain is a first-class suite app. On the **core host**, as root: ```bash -git clone https://gitea.federated.computer/Federated_Computer/brain.git /tmp/superbrain-repo -sudo bash /tmp/superbrain-repo/deploy/federated/install.sh +sudo bash -c "$(docker run --rm --pull always federatedcomputer/superbrain-migrate cat /deploy/install.sh)" ``` -(Use whichever repository location you were given access to; the installer -re-clones it onto the host by default — override with `SUPERBRAIN_REPO`, -`SUPERBRAIN_REF`, or stage a local tree with `SUPERBRAIN_SRC`.) +No clone and nothing to copy: the installer and the suite integration files +ship inside the migrate image at `/deploy`. Pin a release with +`SUPERBRAIN_VERSION=1.2.3` (default `latest`), or use a local checkout's +files instead with `SUPERBRAIN_SRC=/path/to/repo`. The installer: @@ -393,19 +393,18 @@ history: [deploy/federated/STRATEGY.md](deploy/federated/STRATEGY.md). in `/federated/services/superbrain/service` to the new release tag and run `/federated/bin/upgrade superbrain` (the pre-hook backs up the database 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 -git clone https://gitea.federated.computer/Federated_Computer/brain.git /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] ``` 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 linux/amd64 and linux/arm64. The migrate image is self-contained: it detects an empty database, applies `schema.sql` as the superbrain user, -then runs the checksummed migration ledger — the host never needs the -source tree. +then runs the checksummed migration ledger, and it carries +`deploy/federated/` at `/deploy` — the host never needs the source tree. ## Publishing release images (Docker Hub) @@ -466,7 +465,7 @@ docker run --privileged --rm tonistiigi/binfmt --install arm64 docker login -u # token prompt # Smoke the migrate image BEFORE publishing (mirrors the CI gate): -docker build -t sb-migrate:smoke db/ +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 @@ -480,19 +479,22 @@ docker buildx build --platform linux/amd64,linux/arm64 --push \ 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/`, both quick. Go builds +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 — -hosts sync the service file via `deploy/federated/update.sh`), then on each +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 diff --git a/db/Dockerfile b/db/Dockerfile index 698ef19..68a5ccf 100644 --- a/db/Dockerfile +++ b/db/Dockerfile @@ -3,13 +3,21 @@ # the source tree. Entrypoint: bootstrap.sh (empty database => schema.sql as # 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; # only the psql client is exercised. Client 16 against a newer server (the # federated suite runs 17.x) is the supported direction. FROM postgres:16.15-alpine 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 CMD ["sh", "/db/bootstrap.sh"] diff --git a/deploy/federated/STRATEGY.md b/deploy/federated/STRATEGY.md index 07eb7b7..0387158 100644 --- a/deploy/federated/STRATEGY.md +++ b/deploy/federated/STRATEGY.md @@ -71,11 +71,14 @@ Authelia required, fcore SMTP credential, fixed-IP collisions with `SUPERBRAIN_*_IP` overrides; installs lib/service/hook; runs `/federated/bin/installapp superbrain`; verifies containers, Authelia 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/ upgrade superbrain` → same-version compose safety pass → health probe). -The registry-mode app dir holds ONLY compose + .env — update.sh therefore -runs from a repo clone, not from the app dir (the source-mode +The registry-mode app dir holds ONLY compose + .env, so both scripts ship +inside the migrate image at `/deploy` (since 1.0.1) and run via +`bash -c "$(docker run --rm federatedcomputer/superbrain-migrate cat +/deploy/