D-125 (owner decision 2026-10-20, landed6e5981d): the Kvitt Pi runs Kvitt from /home/jacobhagstedt/kvitt, a self-contained compose project with relative bind mounts, both containers as the owner's uid/gid, the seven .env keys compose reads, no scripts and nothing under /opt; operations are plain docker compose commands. Revises D-103, D-105, D-117 point 5 and D-120 point 6. SPEC §10.2, §10.6, §10.8 to §10.10, §11.2 and §14.7 rewritten; KVITT_PI_HOST placeholders become <kvitt-pi-address>. §10.3 records the Gitea workflow's first results (run 69: v1.0.0, backup 5 min 20 s, server 2 h 42 min; v1.0.1 from the sparse-checkout push) and the sparse checkout of3820f9c. HANDOFF, prompts/README.md and notes in PLAN-M11.md and PLAN-M2c-pi.md follow. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TQd3pEP9UeN2uifbHknQ7B
16 KiB
PLAN-M2c-pi: Infra on the Pi (D-001)
Superseded in part by D-120 (SPEC v0.21, 2026-10-19). TLS terminates in the owner's Nginx Proxy Manager on the Home Assistant Pi: Caddy, cert-sync, the Caddyfile, the Home Assistant SSH key and the router forward to the Kvitt Pi are gone. Where this plan names them, SPEC §10 and
infra/README.mdare current; the plan is kept as the record of what M2c-pi was briefed with. Also superseded by D-125 (SPEC v0.24, 2026-10-20): the Pi runs Kvitt from/home/jacobhagstedt/kvitt, a self-contained compose project with relative bind mounts, both containers as the owner's uid, no install, deploy or other scripts and nothing under/opt/kvitt; operations are plaindocker composecommands (SPEC §10.2, §10.10).
Runs after M8 lands and before M10 (D-001, §11.1).
1. Goal
Deploy Kvitt's production stack on the Raspberry Pi 3: Caddy with the Let's Encrypt certificate synced from the Home Assistant Pi, the server, cert-sync and nightly Drive backups, with images in the Gitea registry at http://gitea.lan. Write the runbooks so the owner can provision, deploy, publish the APK and restore without an agent.
2. Read first
- SPEC §10 Deployment & ops, all of it: intro "Development first (D-001)", §10.1 Hosts and network, §10.2 Compose stack, §10.3 Images, registry and build, §10.4 Server configuration and CLI, §10.5 TLS (10.5.1 Certificate sync, 10.5.2 Caddyfile, 10.5.3 Fallback), §10.6 APK hosting and release, §10.7 Firebase setup (step 7), §10.9 Backups and restore, §10.10 Operations.
- SPEC §8.5 Transport, §8.9 Server hardening, §8.7 Privacy and logging.
- SPEC §4 FR-18 Backups and restore, FR-20 Health (AC-20.2).
- SPEC §11.2 (rows M2c-dev, M2c-pi, M10), §11.3 (note M2c-dev / M2c-pi), §12 (OQ-1, OQ-3, OQ-4), §14.7.
docs/decisions.mdD-001, D-002, D-022, D-023, D-025.- Files: everything under
infra/from M2c-dev (infra/dev/**,infra/backup/**,infra/README.md,infra/.shellcheckrc;infra/env.exampledoes not exist yet and is this plan's),server/Dockerfile,.gitignore,CLAUDE.md(EXECUTION PROTOCOLS: Stay inside the repository, Stop and ask; THE OWNER).
3. Already established
- Hosts: Kvitt Pi (Raspberry Pi 3, 1 GB, 64-bit Raspberry Pi OS Lite, Docker Engine with compose plugin, static LAN address); Home Assistant Pi owns 80/443 and the certificate; ASUS router forwards external TCP 8443 to Kvitt Pi 8443; the Pi never builds anything (§10.1).
- Registry: Gitea at
http://gitea.lan, plain HTTP, home Wi-Fi only; the Pi's Docker daemon trusts it viainsecure-registries(its own HUMAN step, D-023); images will be built by Gitea Actions from the owner's example workflow; until theninfra/build-images.shon the Mac pushes togitea.lan(D-001, §10.1, §10.3). Gitea credentials, if needed, come from the owner and live ininfra/secrets/(§10.1). - Compose stack exactly as §10.2: services
caddy,server,cert-sync,backup, their images, volumes, memory limits, healthchecks,depends_on,restart: unless-stopped, json-file logging 10m × 3,TZ=Europe/Stockholm, networkkvitt;.envkeys exactlyKVITT_REGISTRY,KVITT_TAG,HA_HOST,HA_PORT,HA_USER,HA_CERT_DIR,RCLONE_REMOTE(defaultgdrive:),RCLONE_FOLDER_ID. - Files deployed to
/opt/kvitt/compose.yaml,/opt/kvitt/.env, secrets in/opt/kvitt/secrets/(§10.2, §10 intro). - Images:
serverper §10.3 (M2a's Dockerfile);cert-sync=alpine+openssh-client,curl,infra/cert-sync/sync.shundercrond;backupfrom M2c-dev (§10.3). - Scripts:
infra/build-images.sh [tag](buildxlinux/arm64 --push, tag default short SHA, alsolatest, refuses a dirty tree);infra/deploy.sh <tag>(copy compose and Caddyfile over SSH, setKVITT_TAG, pull, up, wait healthy, print/health; triggers a backup and waits forlast-successbefore a deploy with a migration);infra/publish-apk.sh(assembleRelease viatools/gradle-serial.sh, SHA-256 and size, copy toapk/kvitt-<version_code>.apk, atomicapk/latest.json, keep newest 5) (§10.3, §10.6, §10.10). - cert-sync: at start and daily 04:00; SSH with
StrictHostKeyChecking=yes;restrict,command="tar -C <cert dir> -cf - fullchain.pem privkey.pem"where the HA SSH setup allows it, and the plan records which variant the add-on supports; installs only valid, newer, changed PEMs with mode 0640, reloads Caddy through its admin API; failures keep the old certificate (§10.5.1). - Caddyfile exactly §10.5.2; Caddy must not log
Authorization(verify); fallback §10.5.3 documented ininfra/README.md, not deployed (§10.5). - Backups: daily 03:30; Drive root folder id
1jDp1dGE5R3H2DBcXCqIPN1iWzQnPkdlVasRCLONE_FOLDER_ID/--drive-root-folder-id;rclone copy --immutable, neversync, never delete on Drive; local files deleted as soon as both are confirmed on Drive withrclone lsf(D-002, §10.9, OQ-4). rclone remote[gdrive],type = drive,scope = drive, token fromrclone authorize "drive"(§10.9). - FCM key on the Pi at
/opt/kvitt/secrets/fcm-service-account.json, mode 0440, group 10001 (§10.7 step 7). - The
cert-syncandbackupcontainers run as uid 1000;ha_ssh_key,ha_known_hostsandrclone.confon the Pi have mode 0600, owned by uid 1000 (§10.2, D-023). - The
serverservice mounts/opt/kvitt/import:/import:rofor the one-off Splitwise import (§10.2, §10.8, D-025); the directory exists and is empty outside the import. rcloneis needed on the Mac for H-7 only; installing it is the owner's decision (D-022 leaves it to this plan).- Restore steps are §10.9 1 to 7, documented in
infra/RESTORE.md(§10.9).
4. Owned paths
From SPEC §14.7 (v0.3): infra/** (owner "M2c-dev, then M2c-pi (D-001)"; after landing: "M10 updates runbooks"), .gitea/workflows/** (D-023), and the git-ignored infra/secrets/** in the main checkout.
Edit nothing outside these paths; a needed change elsewhere is a contract request to the orchestrator. Never edit SPEC.md or docs/decisions.md: put proposed decision entries in the report.
Resolved open points (SPEC v0.3, D-023):
- (a) Key-based SSH from the Mac to the Kvitt Pi is a HUMAN step (H-0). The allowances to act on the Kvitt Pi, the Home Assistant Pi, Gitea and Google Drive are requested from the owner by the orchestrator at the start of this sprint and stated in the start prompt; without them, stop before step 7.
- (b) The Gitea Actions workflow lives at
.gitea/workflows/at the repository root, owned by this plan. Mirroring or pushing the repository to Gitea needs the owner's explicit ask; without it, write the workflow and report it as not yet run. - (c)
ha_ssh_key,ha_known_hosts,rclone.confon the Pi: mode 0600, owned by uid 1000, the uid thecert-syncandbackupcontainers run as. Verify thatbackupcan read thedatavolume written by uid 10001 and record how ininfra/README.md. - Gitea credentials are a HUMAN step (H-2).
5. Deliverables
infra/compose.yaml: the §10.2 stack, including the/opt/kvitt/import:/import:romount onserverand uid 1000 forcert-syncandbackup.infra/Caddyfile: §10.5.2 verbatim.infra/env.example: written for the Pi (KVITT_REGISTRYongitea.lan,RCLONE_FOLDER_ID1jDp1dGE5R3H2DBcXCqIPN1iWzQnPkdlV; no secrets).infra/cert-sync/Dockerfile,infra/cert-sync/sync.sh: §10.5.1.infra/backup/backup.sh: D-002 deletion after Drive confirmation (kept local mode from M2c-dev).infra/build-images.sh,infra/deploy.sh,infra/publish-apk.sh: §10.3, §10.6, §10.10..gitea/workflows/<name>.yaml: the image build from the owner's example (resolved point b).infra/README.md(extend M2c-dev's file; keep its dev and Firebase sections): Pi provisioning, Docker install,gitea.lanregistry trust, router forwarding, HA SSH add-on key setup and whichauthorized_keysvariant it supports, the §10.5.3 fallback, deploy and publish, operations of §10.10.infra/RESTORE.md: §10.9 restore steps 1 to 7, with exact commands.- On the Pi (not in git):
/opt/kvitt/compose.yaml,/opt/kvitt/.env,/opt/kvitt/secrets/{fcm-service-account.json, ha_ssh_key, ha_known_hosts, rclone.conf}, the empty directory/opt/kvitt/import/. - In
infra/secrets/on the Mac (git-ignored, main checkout):ha_ssh_key,ha_ssh_key.pub,ha_known_hosts,rclone.conf, Gitea credentials if any.
6. Steps
- Worktree. From the main checkout
/Users/jhag/projects/kvitt:git worktree add .claude/worktrees/agent-m2c-pi -b agent-m2c-pi main, then in.claude/worktrees/agent-m2c-pi:git reset --hard main. Copyinfra/secrets/from the main checkout (mkdir -p infra/secrets && cp -R /Users/jhag/projects/kvitt/infra/secrets/. infra/secrets/) andandroid/local.properties(needed bypublish-apk.shonly). Runtools/install-git-hooks.sh. - Read §2 in order. Confirm OQ-3 is answered in the start prompt (or SPEC §12); without it only steps 3 to 6 can run; stop before step 7 and report.
- Versions: resolve from official sources and record:
caddyimage version and digest (Docker Hub official image),alpinetag and digest,openssh-clientandcurlpackage versions in that Alpine release, Docker Engine install method for Raspberry Pi OS (docs.docker.com, Debian/Raspberry Pi OS page). - Write
infra/compose.yaml,infra/Caddyfile,infra/cert-sync/**, the D-002 change ininfra/backup/backup.sh, the three scripts,infra/README.md,infra/RESTORE.md. Generate the dedicated cert-sync key in the main checkout:ssh-keygen -t ed25519 -N '' -C kvitt-cert-sync -f /Users/jhag/projects/kvitt/infra/secrets/ha_ssh_key. - Run
docker compose -f infra/compose.yaml config(with a.envmade frominfra/env.examplein a temp location, never committed) andshellcheck $(find infra -name '*.sh'). - Gitea Actions: write the workflow from the owner's example (H-2); until it exists, build with
infra/build-images.shon the Mac (no Gradle build running) and push togitea.lan. - Pi provisioning over SSH (needs OQ-3, the allowances of resolved point a, H-0, H-1, H-3, H-4): create
/opt/kvitt/,/opt/kvitt/secrets/and/opt/kvitt/import/; copy the secrets with the modes of resolved point (c) and §10.7 step 7; the owner addsinsecure-registriesforgitea.lan(H-4). - cert-sync:
ssh-keyscan -p <HA port> <HA host> > /Users/jhag/projects/kvitt/infra/secrets/ha_known_hosts; the owner installs the public key (H-6); test the tar-stream variant first, fall back to plain copy if the add-on refusesauthorized_keysoptions, and record the variant. - rclone: after H-7, write
/Users/jhag/projects/kvitt/infra/secrets/rclone.confwith[gdrive],type = drive,scope = drive, the token; copy to the Pi. - Deploy:
infra/deploy.sh <tag>; on the Pidocker compose psshows all four services healthy. - Router: the owner sets the forward (H-5); then check
https://icehack.asuscomm.com:8443/healthfrom the phone on mobile data (H-8). - Backup:
docker compose exec backup /backup.shon the Pi;rclone lsfshows the new files in the Drive folder; local files are gone afterwards (D-002). - Verify Caddy logs contain no
Authorizationheader (one authenticated request, then grepdocker compose logs caddy). - Run the gate (§7). Commit on
agent-m2c-pi(never a secret),git rebase main, rerun the gate. Never merge, push or remove the worktree.
7. Gate
From SPEC §11.2 (v0.3), verbatim: "docker compose -f infra/compose.yaml config succeeds; shellcheck $(find infra -name '*.sh') clean; on the Pi: cert-sync fetched a valid certificate, https://icehack.asuscomm.com:8443/health answers from the phone on mobile data; one backup file appears in the Drive folder".
Green means: config exits 0; shellcheck clean; docker compose exec cert-sync shows /certs/fullchain.pem with a not-after in the future and openssl s_client -connect icehack.asuscomm.com:8443 (from the Mac) presents that certificate; the phone on mobile data gets "status":"ok" (H-8); rclone lsf lists the new kvitt-*.sqlite.gz and pictures-*.tar.gz in folder 1jDp1dGE5R3H2DBcXCqIPN1iWzQnPkdlV.
8. HUMAN steps
From SPEC §11.2 (v0.3), verbatim: "Answer OQ-3; grant at the start of the sprint the allowances to act on the Kvitt Pi, the Home Assistant Pi, Gitea and Google Drive (D-023); set up key-based SSH from the Mac to the Kvitt Pi; provide the example Gitea Actions workflow and the Gitea credentials; install Docker on the Pi if missing; add gitea.lan to insecure-registries on the Pi; set the router forward 8443 → Kvitt Pi; add the cert-sync public key to the Home Assistant SSH add-on; rclone authorize "drive"".
Each with where it is needed, the exact command, and what blocks it (OQ-1 and OQ-4 are answered; OQ-3 is the only open question):
- H-A, at the start of the sprint (through the orchestrator): grant the allowances to act on the Kvitt Pi, the Home Assistant Pi, Gitea and Google Drive. Blocks steps 7 to 13.
- H-0, before step 7, on the owner's Mac: key-based SSH login to the Kvitt Pi, for example
ssh-copy-id <ssh user>@<Kvitt Pi address>, thenssh <ssh user>@<Kvitt Pi address> truesucceeds without a password prompt. Blocked by OQ-3. - H-1, before step 7: answer OQ-3 (Kvitt Pi LAN address and SSH user; HA Pi LAN address, SSH port and user; certificate directory; which SSH add-on). Blocks H-3, H-5, H-6 and steps 7 to 13.
- H-2, step 6: provide the example Gitea Actions workflow and the Gitea credentials (written by the owner into a file the agent names inside
infra/secrets/, never pasted into chat). Not blocked by an open question; blocks the Gitea Actions part and any push togitea.lanthat needs credentials. - H-3, step 7, on the Kvitt Pi (only if
docker versionfails there), using the method from docs.docker.com for Raspberry Pi OS, for example:curl -fsSL https://get.docker.com -o get-docker.sh && sudo sh get-docker.sh && sudo usermod -aG docker <ssh user>, then log out and in. Blocked by OQ-3. - H-4, step 7, on the Kvitt Pi (sudo; its own HUMAN step, §10.3, D-023): add
{"insecure-registries": ["gitea.lan"]}to/etc/docker/daemon.jsonand runsudo systemctl restart docker. Blocked by OQ-3. - H-5, step 11, in the ASUS router web interface: WAN, Virtual Server / Port Forwarding: add a TCP rule, external port 8443, internal IP = the Kvitt Pi's LAN address, internal port 8443; Apply. Blocked by OQ-3.
- H-6, step 8, in Home Assistant: Settings, Add-ons, , Configuration: add the one line from
infra/secrets/ha_ssh_key.pub(with therestrict,command=…prefix the agent gives) toauthorized_keys; Save; restart the add-on. Blocked by OQ-3. - H-7, step 9, on the owner's Mac:
rclone authorize "drive", sign in with the owner's Google account in the browser, and leave the terminal output for the agent (the agent reads the token from the terminal session or the owner pastes it into a file the agent names insideinfra/secrets/). Not blocked (OQ-4 answered). Needsrcloneinstalled on the Mac. - H-8, step 11 (needed by the gate): on the phone with Wi-Fi off, open
https://icehack.asuscomm.com:8443/healthin Chrome; answer yes/no: the page shows"status":"ok"without a certificate warning. Blocked by H-5.
9. Out of scope
- The development stack
infra/dev/**(M2c-dev; do not break it). - Firebase project and app creation (done in M2c-dev); only copying the key to the Pi is here.
- Release keystore, signed release, publishing the first real APK, pairing both phones, restore drill, memory check (M10).
- Server or Android code changes; the Splitwise import (M11).
- Changing the Home Assistant Pi beyond adding the one
authorized_keysline; touching certbot there.
10. Report
- Branch
agent-m2c-pi, head commit hash after rebasing onmain. - Gate output lines:
configexit status, shellcheck result, certificate not-after and issuer, phone health result (H-8),rclone lsflines (file names only). - Versions chosen (images with digests, packages, Docker install method) with sources.
- The
authorized_keysvariant the HA add-on supports. - Image tag deployed;
docker compose pssummary. - Paths of secrets written (never contents), modes set on the Pi.
- How resolved points (a) to (c) were applied; which allowances the start prompt granted.
- Proposed decision entries (never written to
SPEC.mdordocs/decisions.mdby this agent) orTODO(spec)occurrences. - HUMAN steps done and outstanding, worded for relay.
- Contract requests, open questions, spec gaps (with section numbers).
11. Numbering
Decision ids, spec version and schema version are assigned by the orchestrator in the start prompt; use TODO(spec) if none was given.