deploy.sh 2.2 KB

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