Repository navigation
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.
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.
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.
sudo bash deploy/readiness-check.shChecks 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.
docker compose -f deploy/compose.prod.yml up -dmigrate 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.
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.servicereportsactivemore readily than it should.Type=oneshotwithRemainAfterExit=yesmeans "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 saidactive, containers running: 0.systemctl startwill not fix it — systemd believes the job is done, so onlysystemctl restartre-runs ExecStart.Never treat
systemctl is-active printorian.serviceas a health signal. The honest checks are/health/readyon 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.
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.ruIt 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:
- 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.
- Add the printers and their credentials.
- Add materials and mount them.
- Create the staff accounts.
- Verify WAL archiving is actually working — see Backup and Restore.
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.
| 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.
- Operations — health checks, logs, the daily reality
- Backup and Restore — and the thing to verify on day one
- Configuration — every variable
Printorian wiki · the code is the source of truth · open work lives in issues · current state in HANDOFF.md
Concepts
Workflow
Lifecycles
- Order Lifecycle
- Job Lifecycle
- Scheduling and Dispatch
- Materials and Inventory
- Fleet and Drivers
- Post-Production and Packing
Money
Running it
- Installation
- Configuration
- Deployment
- Operations
- Backup and Restore
- Database Maintenance
- Troubleshooting
Building it