Files
inbuxa-installer/e2e/cases/upgrade-containers.sh
T
jcoffey-dev b2b595f496 inbuxa upgrade: what is here, to this installer's releases
`inbuxa upgrade [server|console|webmail] [--dry-run] [--yes] [--no-backup]`
moves what is installed to the releases this installer pins; a newer
installer is what brings newer releases. What is installed is read from
the machine: the image tags in compose.yaml, the server binary's
--version, the console's release marker, the webmail's VERSION. status
now shows each component's version, and what this installer would make
it.

One component at a time, the server first, each checked once it is
running again and put back if not, which stops the upgrade:
- a container by its tag in compose.yaml, and its old tag to undo it;
- the server on the host keeps its old binary as inbuxa-server.<version>;
- the console and the webmail on the host keep their old directory until
  the new one is in and, for the webmail, answering; its environment's
  IHASMAIL_VERSION follows the files.
Before the server, which may convert its store on first start, it is
stopped and its own data archived into <dir>/backups -- the volumes with
the server's own image, or <dir>/server -- unless --no-backup. A store kept
elsewhere is said to be backed up where it lives.

The release marker now records the version beside the checksum, and
"local" for a tarball given by hand, which upgrade always replaces.
Options and components can come in any order.

Tests: the plan read from compose.yaml and the host's files, one image
tag changed and no other, a directory put back when its replacement
fails, options after components. e2e: upgrade-containers 17/17 (installed
by v2026.10.12.1; archive, new images, the same mailbox signing in, a
second run with nothing to do), upgrade-host-server 11/11 (a binary that
won't start put back with the server answering, then the real release
with the old binary kept and the data archived), upgrade-frontends-host
10/10 (older tarballs to the releases, the webmail answering as its new
version, the console still pointed at the server). install-local,
install-host, webmail-host, all-host and interface pass unchanged.
2026-10-12 12:52:22 -07:00

67 lines
3.8 KiB
Bash

#!/bin/bash
# SPDX-FileCopyrightText: 2026 Coffey Labs LLC
# SPDX-License-Identifier: AGPL-3.0-or-later
#
# inbuxa upgrade, everything in containers: installed by an older installer,
# moved to this one's releases, the server's data archived first, and the
# same mailbox still signing in afterwards.
#
# Run from the host with:
# OLD_REF=v2026.10.12.1 e2e/vm/run.sh e2e/cases/upgrade-containers.sh
set -uo pipefail
pass=0; fail=0
ok() { echo " ok $*"; pass=$((pass+1)); }
bad() { echo " FAIL $*"; fail=$((fail+1)); }
DIR=/var/lib/inbuxa
rt() { command -v docker >/dev/null 2>&1 && echo docker || echo podman; }
img() { grep -o "inbuxa-$1:[^ ]*" $DIR/compose.yaml; }
signs_in() {
local user pass
user=$(awk '/^first mailbox/ {print $3}' "$DIR/credentials.txt")
pass=$(awk '/^first mailbox/{getline; print $2}' "$DIR/credentials.txt")
curl -s -X POST http://127.0.0.1:8081/api/auth -H 'Content-Type: application/json' -H 'Accept: application/json' \
-d "{\"type\":\"authCode\",\"accountName\":\"$user\",\"accountSecret\":\"$pass\",\"clientId\":\"ihasmail-inbuxa\",\"redirectUri\":\"http://127.0.0.1:8080/api/auth/callback\",\"codeChallenge\":\"E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM\",\"codeChallengeMethod\":\"S256\"}" \
| grep -q '"client_\{0,1\}[cC]ode"'
}
echo "==> installed by the older installer"
OUT="$(/tmp/inbuxa-old install --local --domain example.test --install-deps --yes 2>&1)"; rc=$?
[ $rc -eq 0 ] && ok "installed with $(/tmp/inbuxa-old version)" || { bad "old install exit $rc"; echo "$OUT" | tail -8 | sed 's/^/ /'; }
BEFORE="$(img server) $(img admin) $(img webmail)"
echo " $BEFORE"
signs_in && ok "the first mailbox signs in" || bad "the first mailbox does not sign in before"
echo
echo "==> what this installer says about it"
STATUS="$(/tmp/inbuxa status 2>&1)"
grep -q "this installer installs" <<<"$STATUS" && ok "status says newer releases are here" || { bad "status says nothing about versions"; echo "$STATUS" | sed 's/^/ /'; }
DRY="$(/tmp/inbuxa upgrade --dry-run 2>&1)"; rc=$?
[ $rc -eq 0 ] && [ "$(grep -c -- ' -> ' <<<"$DRY")" = 3 ] && ok "upgrade --dry-run shows three to move" || { bad "dry run exit $rc"; echo "$DRY" | sed 's/^/ /'; }
grep -q "archived into" <<<"$DRY" && ok "and that the server's data is archived first" || bad "no word of the backup"
[ "$BEFORE" = "$(img server) $(img admin) $(img webmail)" ] && ok "a dry run changed nothing" || bad "a dry run changed the compose file"
echo
echo "==> upgrading"
OUT="$(/tmp/inbuxa upgrade --yes 2>&1)"; rc=$?
echo "$OUT" | grep -v '^ |' | tail -16 | sed 's/^/ /'
[ $rc -eq 0 ] && ok "upgraded (exit 0)" || bad "upgrade exit $rc"
ls $DIR/backups/server-*.tar.gz >/dev/null 2>&1 && ok "the server's data was archived: $(ls $DIR/backups)" || bad "no archive in $DIR/backups"
tar -tzf $DIR/backups/server-*.tar.gz 2>/dev/null | grep -q "config.json" && ok "with its configuration in it" || bad "the archive has no config.json"
AFTER="$(img server) $(img admin) $(img webmail)"
[ "$AFTER" != "$BEFORE" ] && ok "now: $AFTER" || bad "the images did not change"
STATE="$($(rt) compose -f $DIR/compose.yaml ps --format '{{.Service}} {{.State}}')"
for s in server console webmail; do grep -q "^$s running" <<<"$STATE" && ok "$s is running" || bad "$s is not running"; done
signs_in && ok "the same mailbox still signs in" || bad "the first mailbox no longer signs in"
curl -fsS http://127.0.0.1:8080/api/health | grep -q '"ok":true' && ok "the webmail is healthy" || bad "the webmail is not healthy"
echo
echo "==> again"
OUT="$(/tmp/inbuxa upgrade --yes 2>&1)"; rc=$?
[ $rc -eq 0 ] && grep -q "Nothing to do" <<<"$OUT" && ok "a second upgrade has nothing to do" || bad "second upgrade: exit $rc"
/tmp/inbuxa status >/dev/null 2>&1 && ok "status: intent and reality agree" || bad "status disagrees"
echo
echo "==> $pass passed, $fail failed"
[ "$fail" -eq 0 ]