From 086b799158959b88051e44286d6146f2a85d6e46 Mon Sep 17 00:00:00 2001 From: Julian Cuni Date: Sun, 12 Jul 2026 10:32:57 +0200 Subject: [PATCH] =?UTF-8?q?docs(wiki):=20deployment=20entity=20page=20?= =?UTF-8?q?=E2=80=94=20Docker/Gitea=20CI/Komodo/Traefik;=20CLAUDE.md=20dep?= =?UTF-8?q?loy=20pointers?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CLAUDE.md | 2 ++ wiki/entities/backend.md | 3 ++- wiki/entities/deployment.md | 37 +++++++++++++++++++++++++++++++++++++ wiki/index.md | 3 ++- wiki/log.md | 4 ++++ wiki/overview.md | 4 ++-- 6 files changed, 49 insertions(+), 4 deletions(-) create mode 100644 wiki/entities/deployment.md diff --git a/CLAUDE.md b/CLAUDE.md index d5f9fb8..04c735f 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -6,3 +6,5 @@ Four parts: - **`frontend/`** — the React control panel (Vite + TypeScript + React Router + zustand + TanStack Query). Dev: `npm run dev` (proxies `/api` to :9000). Prod: `npm run build` → `frontend/dist/`, served statically by the backend. Documented at `wiki/entities/frontend.md`. - **`wiki/`** — an LLM-maintained knowledge base about the Anfu home charger OCPP integration. **Read `wiki/CLAUDE.md` before touching anything in it** — it defines the schema, conventions, and ingest/query/lint workflows. `wiki/raw/` is immutable source material; never edit it. - **`discovering/`** — throwaway-ish Python scripts used during discovery (`csms.py`, `rawlisten.py`, `station.py`). Superseded by `backend/` for production; kept as diagnostics. Documented at `wiki/entities/csms-toolkit.md`. + +Deployment: `Dockerfile` (node builds the panel, python serves it) + `compose.yaml` (Komodo stack, Traefik labels, raw :9000 for the charger) + `.gitea/workflows/build.yml` (build → smoke gate → push to `git.infra.msai.al` → Komodo redeploy). Documented at `wiki/entities/deployment.md`. Smoke test: `venv\Scripts\python -m backend.smoke_test` (65 checks, isolated temp DB — safe to run anytime). diff --git a/wiki/entities/backend.md b/wiki/entities/backend.md index 4cae0e2..9b61b7b 100644 --- a/wiki/entities/backend.md +++ b/wiki/entities/backend.md @@ -51,7 +51,8 @@ backend/ (run: venv\Scripts\python -m backend.main, from the repo root) - Relay calls are blocking tinytuya I/O, run via `asyncio.to_thread` so the OCPP socket never stalls. - Venv at repo root (`../venv/`, Python 3.13); deps pinned in `backend/requirements.txt` (fastapi, uvicorn, websockets, ocpp, tinytuya) — the auth system added none. - Sessions record the **auth method** (`card` vs `app`) for the audit trail; unknown cards NEVER charge — they queue in `pending_cards` for admin approve/reject (learn mode is gone). -- ✅ Smoke-tested 2026-07-11 (54 checks, isolated temp db via the `BACKEND_DB` env override): REST surface, allowlist CRUD incl. gun-restricted cards, login/sessions/scopes, user/relay/charger CRUD, the full consumption pipeline (start → meter sample → stop → kWh → visibility filtering), static panel serving, and a fake charge point over the real WS route. +- ✅ Smoke-tested (65 checks as of 2026-07-12, isolated temp db via the `BACKEND_DB` env override): REST surface, allowlist CRUD incl. gun-restricted cards, login/sessions/scopes, user/relay/charger CRUD, the full consumption pipeline (start → meter sample → stop → kWh → visibility filtering), static panel serving, and a fake charge point over the real WS route. Lives in the repo (`backend/smoke_test.py`) since 2026-07-12 — it's the CI gate in [[deployment]]. +- **Container-ready** (2026-07-12, [[deployment]]): `BACKEND_EVENTS` env override relocates `events.jsonl` (mirrors `BACKEND_DB`), and unauthenticated `GET /api/health` serves Docker/Traefik/Komodo probes. - ✅ **Live charger connected** (2026-07-11 evening): `eu092025` dials the backend (events.jsonl). ⚠️ Panel not yet exercised from a real phone; relays unconfigured until the [[wifi-relays|key extraction]] is done. ## Web panel diff --git a/wiki/entities/deployment.md b/wiki/entities/deployment.md new file mode 100644 index 0000000..20b5110 --- /dev/null +++ b/wiki/entities/deployment.md @@ -0,0 +1,37 @@ +--- +type: entity +updated: 2026-07-12 +tags: [deployment, ci-cd, docker, komodo, traefik] +--- + +# Deployment — Docker / Gitea CI / Komodo / Traefik + +How the [[backend]] (+ built [[frontend]]) ships to production. Added 2026-07-12; ⚠️ pipeline authored but the first run through the Gitea runner is still pending (no Docker on the dev machine — the runner is the first place the image actually builds). + +## Shape + +One image, one container, one stack: + +- **`Dockerfile`** (repo root) — two stages: `node:24-alpine` runs `npm ci && npm run build` in `frontend/`, then `python:3.13-slim` installs `backend/requirements.txt`, copies `backend/` + the built `dist/` to where `backend/main.py` expects it (`/app/frontend/dist`). Runs as UID 1000 under tini, `CMD python -m backend.main`. +- **State on a volume**: `BACKEND_DB=/data/backend.db` and `BACKEND_EVENTS=/data/events.jsonl` env overrides (the latter added 2026-07-12 to `journal.py`, mirroring the existing `store.py` override) put all mutable state on the `artiot-data` volume — the container is disposable. +- **`compose.yaml`** — the Komodo-managed stack. Env-tunable: `ARTIOT_TAG` (default `main`; set a commit SHA to pin/rollback), `ARTIOT_HOST`, `TRAEFIK_NETWORK` (default `traefik`), `ARTIOT_ENTRYPOINT` (`websecure`), `ARTIOT_CERTRESOLVER` (`letsencrypt`). +- **`GET /api/health`** — unauthenticated liveness probe (added 2026-07-12) used by the Docker healthcheck; also handy for Traefik/Komodo. + +## Two front doors, same port + +| Door | Path | Why | +|---|---|---| +| Charger | `ws://:9000/` — **published port, no proxy** | The URL is hardcoded in the charger touchscreen (change = power-cycle, [[troubleshooting]] #4) and the [[jc-6620|JC-6620]] speaks plain `ws://` — no TLS, no SNI, nothing for Traefik to route on. Docker host needs a DHCP reservation at the IP the charger dials. | +| Humans | `https://$ARTIOT_HOST` via Traefik labels | Panel with TLS; same container port 9000. | + +## CI (`.gitea/workflows/build.yml`) + +Mirrors the polymarket-bot repo's pattern. On push to `main` (paths-filtered): plain `docker build` → **smoke test gate** (`backend/smoke_test.py`, 65 checks — REST auth/scopes, per-gun cards, pending-card workflow, OCPP WS round-trips via a fake charge point, session store, SPA serving; in-process against a temp db, promoted into the repo 2026-07-12) → push `git.infra.msai.al/art/charging_station:{main,}` → HMAC-signed Komodo stack redeploy webhook. A failed smoke test means the image is never pushed. + +Repo secrets required: `REGISTRY_USERNAME`, `REGISTRY_PASSWORD`, `KOMODO_STACK_WEBHOOK_URL`, `KOMODO_WEBHOOK_SECRET`. + +## Migration & constraints + +- **Moving the existing install**: copy the current `backend/backend.db` into the volume (`docker compose cp backend/backend.db artiot:/data/backend.db`, restart) — users, cards, sessions, and the session-signing secret all ride along, so nobody re-logs-in. Fresh install instead: `docker compose exec artiot python -m backend.users add --scopes admin`. +- **Charger reachability**: today the charger dials `10.0.10.203:9000` — either the Docker host takes over that address or the touchscreen URL changes (power-cycle). ❓ ties into the always-on-host decision in [[overview]]. +- **Relay reachability**: [[wifi-relays|tinytuya]] is plain TCP to the relay IPs — the Docker host's network must reach that subnet (bridge networking is fine; device discovery by broadcast is not needed once IPs are registered). diff --git a/wiki/index.md b/wiki/index.md index afc591f..b600513 100644 --- a/wiki/index.md +++ b/wiki/index.md @@ -1,6 +1,6 @@ --- type: meta -updated: 2026-07-11 +updated: 2026-07-12 tags: [index] --- @@ -20,6 +20,7 @@ Catalog of every wiki page. Updated on every ingest. (Schema/conventions live in - [[frontend]] — the React control panel in `../frontend/`: Vite/TS, React Router, zustand, TanStack Query; served by the backend - [[csms-toolkit]] — the Python CSMS scripts in `../discovering/`; discovery/diagnostic tooling (production role superseded by [[backend]]) - [[wifi-relays]] — the Tuya/SmartLife WiFi relays; local tinytuya control path + key-extraction steps +- [[deployment]] — Docker image, Gitea CI pipeline, Komodo stack, Traefik routing; how the backend ships - [[netbird]] — the private overlay network; security boundary for the future web panel ## Concepts diff --git a/wiki/log.md b/wiki/log.md index 84ccb4c..5f8cea0 100644 --- a/wiki/log.md +++ b/wiki/log.md @@ -103,3 +103,7 @@ Owner: "why do we need this app token of X? We just need the user." Agreed — d ## [2026-07-12] lint | Session wrap-up: milestones + gaps from today filed Owner asked whether the wiki needs updating — it did. Filed: panel verified end-to-end on the phone incl. a real in-app start on the live charger (tx 1-2, 141 Wh, who=julian/method=app; the two pre-refactor session rows' who labels were repaired in the db); six household users created; "app-remote" retired (delete from Cards when convenient); Ctrl+C shutdown fix (timeout_graceful_shutdown=3 vs the never-closing charger socket); SPA cache headers + the ":9000 serves the last build" rule; telemetry columns (V/A/context) + live telemetry on /api/status; battery gauge in Control. Refreshed [[overview]] (milestones + trimmed next steps: Tuya keys, remote-stop question, deploy as service), [[backend]], [[frontend]], [[authorization]]. + +## [2026-07-12] meta | CI/CD pipeline: Docker + Gitea Actions + Komodo + Traefik + +Owner asked for a deployment pipeline matching his infra (Gitea workflows, Komodo-controlled compose stack behind Traefik). Added: multi-stage `Dockerfile` (node builds the panel, python:3.13-slim serves it), `compose.yaml` (port 9000 published raw for the charger's hardcoded ws:// dial-in, Traefik labels for the panel, env-tunable for Komodo), `.gitea/workflows/build.yml` (build -> 65-check smoke gate -> push to git.infra.msai.al -> HMAC Komodo redeploy, mirroring the polymarket-bot repo). Backend: `BACKEND_EVENTS` override, `GET /api/health`, smoke test promoted into `backend/smoke_test.py`. New page [[deployment]]; updated [[backend]], [[overview]], [[index]]. ⚠️ First runner build pending (no local Docker). diff --git a/wiki/overview.md b/wiki/overview.md index ac38c92..4e207e0 100644 --- a/wiki/overview.md +++ b/wiki/overview.md @@ -33,14 +33,14 @@ Hardware surprise: this is a **DC-capable multi-standard charger** (gun 1 EU, gu 1. **Extract the Tuya local keys** (`tinytuya wizard` — steps in [[wifi-relays]]) and register them via `PUT /api/relays/` → relays become controllable. 2. **Resolve the ❓ remote-stop restart question** — did the gun-2 session auto-restart from auth cache after RemoteStop, or was the card re-tapped? Affects the app's Stop button UX ([[authorization]]). Test: remote-stop, touch nothing for 5 min. -3. **Deploy as an always-on service** ([[architecture-plan]] phase 4) — decide the host (❓ below), run under NSSM/systemd, DHCP reservation. +3. **Deploy via the new CI/CD pipeline** ([[deployment]], built 2026-07-12): Gitea Actions builds + smoke-tests the Docker image, Komodo runs the compose stack behind Traefik. ⚠️ First runner build pending; set the 4 repo secrets, then decide the Docker host (❓ below) and give it the IP the charger dials. 4. Housekeeping: delete the retired `app-remote` allowlist entry from the Cards page; tap the remaining household cards so they pend and can be linked to their owners. ## Open decisions ❓ | Decision | Options | Status | |---|---|---| -| Always-on host for CSMS + app | LAN PC · the `10.0.10.203` machine · dedicated box (e.g. Pi on charger LAN, joined to NetBird) | open — now also needs subnet reachability to the [[wifi-relays|relays]] for local Tuya control | +| Always-on host for CSMS + app | LAN PC · the `10.0.10.203` machine · dedicated box (e.g. Pi on charger LAN, joined to NetBird) | open — must be a **Docker host** now ([[deployment]], 2026-07-12): reachable at the exact IP:9000 the charger dials, on a subnet that reaches the [[wifi-relays|relays]], joined to the Traefik network | | Web app auth | — | ✅ **resolved 2026-07-11**: username+password login with per-resource scopes (gun 1 / gun 2 / per-relay / admin) — see [[authorization]]. Bootstrap: create the first admin user via `python -m backend.users add` | | Autocharge / by vehicle | — | ❌ **closed 2026-07-09**: not supported by this firmware ([[authorization]]) | | Host IP stability | static IP · DHCP reservation | open (required either way — touchscreen URL is hardcoded) |