Skip to content

About

Self-updater for docker-compose stacks: detect -> baseline test -> update -> test -> auto-revert on failure

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

Docker Compose Self-Updater — "detect → baseline test → update → test → revert → test"

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.

Why not Watchtower?

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.

The method

Per app, every run:

  1. 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.
  2. Baseline test — prove the CURRENT version answers its healthcheck. If it fails, the app is already broken → abort, do not update.
  3. Feature gate — optional per-app check that a required capability survived the previous state (e.g. a config option the user depends on).
  4. Apply — back up the compose file, rewrite the digest, compose pull + compose up -d --no-deps.
  5. 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).
  6. Revert — on failure: restore the compose backup (digest/rolltag) or re-tag the old local image (pull), up again, 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.

Files

  • 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, COMPOSE path, SERVICE, CONTAINER, STRATEGY (pull | digest | rolltag), IMAGE, TAG, a test_app() function, and optionally test_feature() + TEST_TIMEOUT.

Usage

/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).

Notes / pitfalls learned

  • docker buildx imagetools inspect <img>:<tag> --format '{{.Manifest.Digest}}' is the reliable way to detect upstream changes. Avoid GHCR tags/list pagination (unreliable past ~1000 tags).
  • buildx returns digests with a sha256: prefix baked in — strip it or your compose rewrite becomes @sha256:sha256:… and compose up silently does nothing (a real bug that was caught by the "image actually changed" guard).
  • If an image moved distro (Alpine→Debian slim), wget/curl may disappear from the container — the comet example uses python urllib for 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.

About

Self-updater for docker-compose stacks: detect -> baseline test -> update -> test -> auto-revert on failure

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages