A weekly, zero-touch updater for a docker-compose stack that refuses to break your services. Written in plain bash + a per-app config file. Runs from cron (here: a Hermes cron NO-AGENT job, Sunday 06:30) and reports one terse line per app to Telegram; full detail goes to a dated report file.
Watchtower just restarts containers when a new image exists. It does not:
- prove the current version works before touching it (baseline test)
- test the new version after the update
- revert automatically to the previous image when the new one fails
- know about your app-specific invariants (feature gates — e.g. "the newsgroups module must still be in the live config after this update")
For a media stack where a broken update means your family's streaming dies, that revert safety net is the whole point.
Per app, every run:
- Detect — compare the registry manifest digest against the digest pinned
in the compose file (digest strategy), or the pulled image ID (pull strategy).
Rolling tags (
nightly) get their tag + digest rewritten together. - Baseline test — prove the CURRENT version answers its healthcheck. If it fails, the app is already broken → abort, do not update.
- Feature gate — optional per-app check that a required capability survived the previous state (e.g. a config option the user depends on).
- Apply — back up the compose file, rewrite the digest,
compose pull+compose up -d --no-deps. - Post-update test — poll the healthcheck (up to 5 min for slow migrations). Guard: verifies the container was actually recreated with the new image (a silent failed pull would otherwise false-pass against the old version).
- Revert — on failure: restore the compose backup (digest/rolltag) or
re-tag the old local image (pull),
upagain, test again. If the revert also fails → CRITICAL, manual intervention (message says so).
Container state is preserved: an app that was stopped before the run is stopped again after. Never auto-upgrades database containers. The script always exits 0 — failures live in the report text, not as a silent cron failure.
stack-update.sh— the engine. Drop it in/usr/local/sbin/.example-app.conf— one app's config. Copy to/etc/stack-update/apps.d/<app>.conf. Each app needs:NAME,COMPOSEpath,SERVICE,CONTAINER,STRATEGY(pull|digest|rolltag),IMAGE,TAG, atest_app()function, and optionallytest_feature()+TEST_TIMEOUT.
/usr/local/sbin/stack-update.sh --check # detect + baseline tests only, no changes
/usr/local/sbin/stack-update.sh # real run (updates immediately)Cron: run it whenever you like; this setup uses Sunday 06:30 (quiet hours, after the heavy nightly scraping window).
docker buildx imagetools inspect <img>:<tag> --format '{{.Manifest.Digest}}'is the reliable way to detect upstream changes. Avoid GHCRtags/listpagination (unreliable past ~1000 tags).buildxreturns digests with asha256:prefix baked in — strip it or your compose rewrite becomes@sha256:sha256:…andcompose upsilently does nothing (a real bug that was caught by the "image actually changed" guard).- If an image moved distro (Alpine→Debian slim),
wget/curlmay disappear from the container — the comet example usespython urllibfor the healthcheck so it works across old and new images. - Give slow apps a bigger
TEST_TIMEOUT(comet's first boot after an update runs a DB migration over millions of rows — 300 s). - The healthcheck in the post-update test polls inside the container against 127.0.0.1, so it works even when the app is behind a reverse proxy.