| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- #!/bin/sh
- # Switch the database container to an image tag that already exists on zeus.
- #
- # It does NOT build. The database is built on zeus - the images there are tagged
- # smartbotic-database:<version>, alongside the smartbotic-db-build:<version> the
- # build itself uses. An earlier version of this script built from mulan's binary
- # instead, and would have DOWNGRADED a running 2.10.0 to mulan's packaged 2.9.0,
- # because mulan's package lags what is built on zeus. Hence the check below.
- #
- # ./deploy.sh 2.10.0 switch to that image
- # ./deploy.sh show what is running and what is available
- set -eu
- ZEUS=${ZEUS:-zeus}
- WANT=${1:-}
- running=$(ssh "$ZEUS" 'docker exec smartbotic-db /usr/bin/smartbotic-database --version 2>/dev/null | head -1' || echo "not running")
- echo "running: $running"
- if [ -z "$WANT" ]; then
- echo "available images:"
- ssh "$ZEUS" 'docker image ls --format " {{.Repository}}:{{.Tag}}" | grep -E "smartbotic-database:" | sort'
- echo
- echo "give a tag to switch to it, e.g. ./deploy.sh 2.10.0"
- exit 0
- fi
- ssh "$ZEUS" "docker image inspect smartbotic-database:$WANT >/dev/null 2>&1" || {
- echo "no image smartbotic-database:$WANT on $ZEUS - build it there first" >&2
- exit 1
- }
- # Going backwards is possible and sometimes right, but never by accident.
- case "$running" in
- *"$WANT"*) echo "already running $WANT" ;;
- *) printf 'switch to %s? [y/N] ' "$WANT"; read -r answer
- case "$answer" in y|Y) ;; *) echo "left alone"; exit 0 ;; esac ;;
- esac
- ssh "$ZEUS" "docker tag smartbotic-database:$WANT smartbotic-database:current && \
- cd /data/smartbotic-db && \
- docker rm -f smartbotic-db >/dev/null 2>&1 || true; \
- docker compose up -d >/dev/null && sleep 8 && \
- docker logs --tail 3 smartbotic-db 2>&1 | grep -iE 'recovery complete|error' || true"
- echo "now: $(ssh "$ZEUS" 'docker exec smartbotic-db /usr/bin/smartbotic-database --version 2>&1 | head -1')"
- echo
- echo "The previous image is still on zeus under its own version tag, so a"
- echo "rollback is ./deploy.sh <that version>."
- echo
- echo "mulan's webserver reconnects on its own within a few seconds. Until it"
- echo "does it will report zero workflows - that is the connection, not the data."
|