Repository navigation
feat(deploy): add rollback capability to auto-update.sh - #413
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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), butdeploy/auto-update.shstill had zero rollback capability - it pulled:latestand deployed, full stop, with no digest recorded anywhere a rollback could target.docker inspect --format='{{index .RepoDigests 0}}', not the local image-config.Idused for change-detection - those aren't the same thing, and only the repo digest is actually pullable viaimage@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:latestcurrently points to.--clear-rollback-lock- without this, the very next scheduled check would just see the same bad:latestand 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 OKshellcheck 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)