#!/usr/bin/env bash # Put an earlier deploy back: build the code of a deploy-N tag in a temporary copy and deploy it with scripts/deploy.sh. # scripts/rollback.sh deploy-3 server + agent + runner of that tag (default: all) # scripts/rollback.sh deploy-3 server only the server # git tag -n9 -l 'deploy-*' list the deploys with their details # # It uses the CURRENT deploy.sh (hash checks included) but the OLD source, and makes no new tag. # Notes: everybody is logged out once (the server restarts). Agents on machines are not changed: update them from the # Models page when nothing is downloading. If a newer version changed the format of a file the server keeps in # /opt/wxch (config.json, keys.json), check that the old version can read it. The VPS also keeps the server that was # running before the last switch as /opt/wxch/wxch-server.prev. set -euo pipefail cd "$(dirname "$0")/.." TAG="${1:?usage: scripts/rollback.sh deploy-N [server|agent|runner|all]}"; shift git rev-parse -q --verify "refs/tags/$TAG^{commit}" >/dev/null || { echo "no such tag: $TAG (see: git tag -n9 -l 'deploy-*')" >&2; exit 1; } [ $# -gt 0 ] || set -- all echo "rolling back to $TAG:"; git tag -n9 -l "$TAG" | head -3 TMP="$(mktemp -d)" trap 'git worktree remove --force "$TMP/src" >/dev/null 2>&1 || true; rm -rf "$TMP"' EXIT git worktree add --detach "$TMP/src" "$TAG" >/dev/null bash scripts/deploy.sh --src "$TMP/src" "$@" echo "rolled back to $TAG. The next deploy from the latest code will get a new number."