Skip to content

Deployment

Dmitri Chudinov edited this page Aug 28, 2026 · 1 revision

Deployment

Standing the stack up on a real host. The development setup is Installation; running it day to day is Operations.

Where this stands honestly: the farm host exists and runs in production mode, and every step of getting it there was manual. The host is not yet reproducible — there is no Ansible role, the edge does not exist, and nothing monitors any of it. See Project Status.


1. The target

Debian stable or Ubuntu LTS. WAL archiving, systemd timers, UPS integration and unattended upgrades all assume it, and running the farm on Windows because the development machine is Windows would be a decision made for the wrong reason.

┌──────── FARM HOST — Docker Compose under systemd ────────┐
│  caddy      console bundle (LAN) + /api                  │
│  api        the image, `uvicorn`                         │
│  workers    the same image, `python -m printorian.workers`│
│  postgres   17, on the data disk                          │
│  redis                                                    │
│  migrate    one-shot, runs before api and workers         │
│                                                           │
│  systemd timers: reconcile · backup · drill               │
│  volumes: /srv/printorian/{storage,pgdata}                │
│           /mnt/backup  ← a SEPARATE PHYSICAL DISK         │
└───────────────┬─────────────────────────┬─────────────────┘
                │ MQTT:8883, FTPS:990     │ HTTPS
                ▼                         ▼
          Bambu printers            staff browsers,
                                    kiosk wall display

Everything on the host is one deploy/compose.prod.yml under one systemd unit.

2. One image, many commands

The CI image job builds, scans, SBOMs, signs (cosign keyless, via the job's OIDC identity — no key to store, rotate or lose) and pushes to GHCR from main.

The same image is the API, the workers and the migration runner; only the command differs. That is what makes "the thing CI tested" and "the thing the farm runs" the same artefact.

The image CI job runs the containers rather than only building them — against the same deploy/compose.prod.yml the farm uses: migrations forwards, backwards and forwards again; readiness reporting its dependencies; the console's same-origin proxy; every worker loop proven to be sweeping rather than merely running; and a live event raised in one container proven to reach the other. The source-tree jobs cannot see a missing system library, a wrong entrypoint, a migration that only runs with a dev dependency present, or a base image that moved underneath us.

3. Pre-flight

sudo bash deploy/readiness-check.sh

Checks what the deployment assumes — disks, RAM, CPU, the backup mount, secrets, and optionally the MQTT/FTPS ports on a real printer — and prints one line per check tagged [PASS] / [WARN] / [FAIL], then the concrete fix for anything that failed.

Exit code 0 when nothing failed (warnings are allowed), 1 otherwise, so it works as a gate in front of a deploy. Every threshold is tunable:

PRINTORIAN_REPO_DIR=/srv/printorian/repo
PRINTORIAN_BACKUP_ROOT=/mnt/backup
PRINTORIAN_PROBE_PRINTER=192.168.29.10
PRINTORIAN_MIN_RAM_GB=8   PRINTORIAN_MIN_CPUS=2

A host that scores zero FAIL is ready to have the stack brought up.

4. Bringing it up

docker compose -f deploy/compose.prod.yml up -d

migrate runs first as a one-shot; api and workers wait on it. The console is published on 8080 and the storefront on 8081 by default (PRINTORIAN_CONSOLE_PORT, PRINTORIAN_STOREFRONT_PORT, and the matching _BIND variables).

Set PRINTORIAN_SECRET_KEY to something real. The default is dev-only-not-a-real-secret and it is exactly as safe as it sounds.

5. systemd

Units live in deploy/systemd/ as files, so they are reviewable and testable without the Ansible role that is supposed to install them.

sudo install -m 0644 deploy/systemd/*.service deploy/systemd/*.timer /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable --now printorian.service
sudo systemctl enable --now printorian-backup.timer printorian-drill.timer printorian-ensure.timer
Unit What it does
printorian.service The stack
printorian-backup.timer 03:00 daily, Persistent=true
printorian-drill.timer Sundays 04:00 — the restore drill
printorian-ensure.timer Every 5 min, reconciles running services against intent

printorian.service reports active more readily than it should. Type=oneshot with RemainAfterExit=yes means "ExecStart returned 0 once", not "the farm is running". The two came apart on the first farm host within an hour of the unit existing: systemd said active, containers running: 0. systemctl start will not fix it — systemd believes the job is done, so only systemctl restart re-runs ExecStart.

Never treat systemctl is-active printorian.service as a health signal. The honest checks are /health/ready on the API and the running container count.

printorian-ensure.timer closes that gap: it compares the number of running services against what should be up and brings the stack back if it is short. It reconciles toward systemd's intent — a farm deliberately stopped stays stopped, because a service that cannot be switched off is a worse problem than the one being fixed. Docker's own restart: unless-stopped already covers a crashed container; the reconciler is for containers that are absent — after a compose down, a failed pull mid-deploy, or a partial up.

deploy/reconcile.sh must stay executable. It is committed 100755, and a mode lost in transit turns the reconciliation timer into a unit that fails every five minutes.

Timers rather than cron, for two reasons: OnCalendar with Persistent=true catches up a run the machine slept through, and a farm host is powered down more often than a server — a backup silently skipped because the shop was closed on Monday is the failure mode this whole directory exists to prevent. And a failed timer unit is visible to systemctl --failed with its exit status and journal, where cron's answer to a failed job is an email to a mailbox nobody reads.

Check the timers actually took:

systemctl list-timers 'printorian-*'

Both should show a next elapse. A timer that is enabled but has no next elapse will never fire.

6. First boot

The only point in the system's life where an account is created without an authenticated person behind it. Ten minutes, once per deployment — full procedure in docs/RUNBOOK-FIRST-BOOT.md.

Before you start: an address for the owner that can receive mail (every password reset goes through it), and a password from a generator, in the farm's password manager before you type it. You will not be shown it again — it is Argon2-hashed on the way in and cannot be read back out by anyone, including you.

Step 1 — check the database is empty of people.

docker compose -f deploy/compose.prod.yml exec postgres psql -U printorian -c "SELECT email, role FROM users;"

Expect zero rows. If there are rows, stop. A fresh farm has no accounts, so anything here means this database came from somewhere else — and one of the somewhere-elses ships with a published owner password.

Step 2 — create the owner.

docker compose -f deploy/compose.prod.yml exec api python tools/provision_owner.py --email owner@yourfarm.ru

It prompts twice and never takes the password as an argument — a password on a command line is in the shell history, in ps output, and in the container's process list for as long as the command runs. It refuses if an owner already exists.

Step 3 — sign in and close the loop. In this order:

  1. Set the farm's real rates. Every rate is currently the compiled default. Quotes issued before you fix them are honest quotes at the wrong price, and they do not silently correct themselves later.
  2. Add the printers and their credentials.
  3. Add materials and mount them.
  4. Create the staff accounts.
  5. Verify WAL archiving is actually working — see Backup and Restore.

7. Secrets

Today: environment variables plus a gitignored backend/printers.local.toml. SOPS + age is the decided target and is not adopted — there is no .sops.yaml (#17).

Printer access codes are encrypted at rest in the database (ADR-0014). Settings marked Kind.SECRET are write-only.

8. What is not built

State Issue
Host configuration as code (Ansible) The units exist as files; the role that installs them does not #15
The storefront edge (VPS + WireGuard + Caddy) deploy/storefront.Caddyfile is written against it. No customer can reach the system today — only the console, on the LAN #18
Continuous deployment Deployment is manual #19
Off-site backup Every copy of the farm's data is on one machine #16
Metrics and alerting No /metrics, no alerts. The only monitor is a person looking at a screen #20, #22

printorian-deploy.timer is deliberately absent: it needs cosign verification, and a deploy timer without signature verification just moves the trust rather than establishing it.

Related

Clone this wiki locally