Skip to content

feat(deploy): add rollback capability to auto-update.sh - #413

Merged
neuromechanist merged 3 commits into
developfrom
fix/deploy-rollback
Sep 19, 2026
Merged

neuromechanist merged 3 commits into
developfrom
fix/deploy-rollback

Conversation

@neuromechanist

Copy link
Copy Markdown
Member

Summary

Closes the remaining open part of #379. docker-build.yml's tagging race and missing versioned images are already fixed (PR #380, in the pending release PR #403), but deploy/auto-update.sh still had zero rollback capability - it pulled :latest and deployed, full stop, with no digest recorded anywhere a rollback could target.

  • Records each successful deployment's registry digest (the repo digest from docker inspect --format='{{index .RepoDigests 0}}', not the local image-config .Id used for change-detection - those aren't the same thing, and only the repo digest is actually pullable via image@digest).
  • --rollback [N] redeploys the image from N deployments ago (default 1), pinned by digest so it runs the exact prior image regardless of what :latest currently points to.
  • After a rollback, writes a lock file that pauses the hourly auto-update cron until an operator runs --clear-rollback-lock - without this, the very next scheduled check would just see the same bad :latest and immediately undo the rollback.

Deliberately out of scope per discussion: backfilling historical versioned images for 0.7.x-0.8.9 (nobody but this project uses those tags, not worth the registry churn).

Test plan

  • bash -n deploy/auto-update.sh - syntax OK
  • shellcheck deploy/auto-update.sh - only pre-existing warnings unrelated to this change (unquoted $ENV_ARGS/$ENV_OVERRIDE, indirect $? check, unused loop var - all present before this PR)
  • Rollback line-arithmetic verified standalone against a fake multi-entry history file
  • Not exercised against a live Docker daemon/registry - this script runs on the production host, not available from this environment

Addresses the still-open part of issue #379 (the release-image
tagging/rollback follow-up): auto-update.sh had no way to recover from a
bad :latest short of manually finding a sha- tag. Records each successful
deployment's registry digest, adds --rollback [N] to redeploy a prior one
pinned by digest (not :latest), and a rollback lock so the next hourly
check doesn't immediately re-pull the bad image and undo the rollback.
--clear-rollback-lock resumes normal auto-updates once the registry is
fixed.

Not tested against a live registry/Docker daemon (this runs on the
production host, not this dev machine); verified with bash -n, shellcheck,
and a standalone check of the rollback line-arithmetic logic.
- rollback_target_digest no longer relies on error_exit (log + exit) inside
  a $(...) command substitution: that exit only killed the subshell, and
  the error text got silently captured as the "digest" instead of stopping
  the script. It now returns 1 and callers use `|| error_exit`.
- do_rollback no longer appends the rollback target back onto
  deploy-history.log. Doing so shifted "N deployments ago" on every
  rollback, so a second --rollback 1 during the same incident bounced back
  to the image just escaped instead of going further back in time. The
  cumulative offset for the current incident is now tracked in
  ROLLBACK_LOCK_FILE and reconciled into history by --clear-rollback-lock.
- deploy_update now sets a DEPLOY_HEALTHY flag; do_rollback uses it so a
  rollback whose container never becomes healthy is reported as UNHEALTHY /
  needs manual investigation, not silently as "Rollback complete".
- check_for_updates captures the pulled digest from `docker pull`'s own
  "Digest: sha256:..." output instead of `docker inspect
  --format='{{index .RepoDigests 0}}'`, which belongs to the local image
  object rather than the specific tag just pulled and has no guaranteed
  correspondence when this host pulls more than one tag of the same image.
  Also now checks docker pull's own exit status.
- LOCK_FILE is now scoped per container (prod/dev), so a routine auto-update
  in one environment can no longer silently swallow (exit 0) an operator's
  --rollback in the other.
- --rollback --check-only now resolves and prints the target without
  deploying, instead of silently performing a real rollback despite the
  flag name. --force's inability to override an active rollback lock is now
  documented and logged explicitly.
- --rollback rejects a non-positive step count.

Verified the offset fix against a simulated two-rollback incident (walks
d3->d2->d1, not d3->d2->d3) and the subshell-exit fix (failure now
propagates via `|| error_exit` instead of being swallowed).
do_rollback's internal messaging already distinguished a healthy rollback
from one whose container never became healthy, but the caller in main
execution didn't check DEPLOY_HEALTHY: it always logged "Rollback completed
successfully!" and exited 0 regardless, contradicting do_rollback's own
"did NOT resolve the incident" warning immediately above it and giving
nothing external (monitoring, a wrapper script) a way to detect failure.
@neuromechanist
neuromechanist merged commit a30080a into develop Sep 19, 2026
8 checks passed
@neuromechanist
neuromechanist deleted the fix/deploy-rollback branch September 19, 2026 20:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant