Skip to content

Compose: ready for a pinned, hands-off homelab deployment - #10

Open
Xalert wants to merge 3 commits into
mainfrom
deploy/homelab-ready
Open

Xalert wants to merge 3 commits into
mainfrom
deploy/homelab-ready

Conversation

@Xalert

@Xalert Xalert commented Dec 2, 2026

Copy link
Copy Markdown
Owner

Why

The app already ran in Docker. What it could not do was fit a server that follows three rules: every image pinned to an exact version, a stack deployed with nothing but docker compose up -d, and an operator without root on the Docker host. This makes deploy/compose.yaml usable there unchanged, configured only from a .env:

EXPENSES_TRACKER_VERSION=1.2.3
POSTGRES_VERSION=17.12-alpine
POSTGRES_PASSWORD=...
EXPENSES_TRACKER_PORT=3000
TRUST_PROXY=1
COMPOSE_PROFILES=backup-scheduled
BACKUP_DIR=/path/on/another/disk

What changes

Gap Change
postgres:17-alpine was hard-coded, a floating tag POSTGRES_VERSION (default 17-alpine) sets the tag of db and the backup services
The backup schedule had to be started by hand (--profile backup up -d backup) and ended at every reboot New backup-scheduled service: the same definition as backup (YAML anchor), restart: unless-stopped, on with COMPOSE_PROFILES=backup-scheduled. It dumps at start and every BACKUP_INTERVAL_HOURS (default 24), and waits for the database after a reboot
Dumps could only go next to the Compose file, on the database's disk BACKUP_DIR (default ./backups)
Dumps are root's (mode 600), so restoring needed sudo Documented: list and restore through the backup service (docker compose run --rm --entrypoint pg_restore backup …)
pg-major-upgrade.sh knew only db and backup It stops a running scheduled backup for the upgrade and moves it to the new image

Docs (docs/SELF-HOSTING.md): pinning every version, Nginx Proxy Manager (works with its defaults), a monitor on /api/health, restoring without root, and moving an instance or a development database to another machine. SPEC.md, DECISIONS.md, CHANGELOG.md and CLAUDE.md follow.

Behaviour change

backup now only takes single dumps. BACKUP_INTERVAL_HOURS with docker compose --profile backup up -d backup used to loop; it now dumps once and exits. The schedule is COMPOSE_PROFILES=backup-scheduled. In return, docker compose run --rm backup is always one dump, whatever .env says. The changelog has the upgrade note.

Not added, on purpose: container_name (breaks a second instance with -p), a variable for a bind-mounted data folder, and health check tuning (Docker 28 keeps probe results in memory, so the 5-second pg_isready writes nothing to disk).

How it was checked

No app code changes, so the published sha-164fb53 image was run with this branch's deploy/compose.yaml and a .env like the one above, under a throwaway project name (Docker 29.10, Compose 5.8, macOS):

  • a plain up -d starts the three services on the pinned images; the scheduled dump, one-shot run --rm backup next to it, and pruning
  • the scheduled container is restarted by Docker after its process ends, waits without failing while the database is down, dumps once it is up, and stops at once during the wait
  • restore and listing through the backup service; turning the schedule off and on
  • pg-major-upgrade.sh 17 → 18 with the schedule running
  • moving: the demo database dumped from the development container and restored into a database started alone, then signed in with the demo account; a 0.1.0 dump restored the same way (migration 0007 applied), and over a database the newer app had already run on (fails, as the guide now warns)
  • behind nginx with the directives of Nginx Proxy Manager 2.17.0's templates plus proxy_request_buffering off, over TLS and HTTP/2, in Chromium: register, Secure session cookie, a 4.6 MB / 40,000-row import, sign out and in
  • npm run typecheck, npm run lint, npm test (1174 tests)

Not checked: Nginx Proxy Manager itself, a real reboot or Docker daemon restart, an unprivileged LXC, Docker 28, and the move with real data. docs/DECISIONS.md ("Not verified") has the full list.

After merging

The deployment needs a release to pin (make release VERSION=0.2.0 PUSH=1); the steps that follow are under "Next steps" in docs/DECISIONS.md.

🤖 Generated with Claude Code

Xalert and others added 3 commits December 2, 2026 15:29
Makes deploy/compose.yaml usable unchanged, with only a .env, on a server
that pins every image and deploys with nothing but `docker compose up -d`.

- POSTGRES_VERSION (default 17-alpine) is the tag of db and the backup
  services, so an exact release can be pinned without editing the file.
- backup-scheduled: the backup definition on a daily loop (YAML anchor),
  restart unless-stopped, turned on with COMPOSE_PROFILES. It waits for the
  database after a reboot. `backup` only takes single dumps now.
- BACKUP_DIR (default ./backups) puts the dumps on another disk.
- pg-major-upgrade.sh stops the scheduled backup for the upgrade and moves
  it to the new image.
- Self-hosting guide: pinning every version, Nginx Proxy Manager, a monitor
  on /api/health, restoring without root on the host, moving an instance
  or a development database to another machine.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
- A restart takes no extra dump: at start the scheduled service waits
  until the newest dump is as old as the interval.
- A database with no accounts is never dumped or pruned, so an empty
  database cannot push the real backups out.
- A failed dump is tried again after 10 minutes (6 in a row, then the
  interval); bad settings fall back with a warning instead of putting
  the container in a restart loop.
- A stop during a dump ends pg_dump and removes its unfinished file.
- pg-major-upgrade.sh installs its recovery before stopping anything.
- Guide: restores stop the scheduled backup, BACKUP_DIR must be a path,
  an unmounted disk, and what a Postgres tag does and does not pin.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…view fixes

- pg-major-upgrade.sh: the recovery is an EXIT trap behind an `armed`
  flag. The ERR trap never ran for a failure inside a function (dc,
  psql_db, up_all) or a subshell, so a new server that did not start or
  a failed restore left the app stopped and the override pointing at the
  new, empty volume.
- Backups: pruning never decides the result (a file that cannot be
  removed is a warning); a failed rename removes the unfinished file;
  the unfinished file is named per container, so two runs in the same
  second never write the same file.
- Guide: a dump made by hand for a move gets a name the backups do not
  prune; from a clone, BACKUP_DIR stays at ./backups or outside it.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
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