From e73b019492d675f07a7afc35193b59a16c4f5ee8 Mon Sep 17 00:00:00 2001 From: Pascal Linxweiler Date: Mon, 5 Oct 2026 17:34:44 +0200 Subject: [PATCH] Deploy compose: shared DB bind mount, models on NFS - deploy/compose.yaml: KANAME_DATA_DIR bind mount (SQLite) for web and worker, NFSv4 volume for models (worker only), configured via .env - entrypoint fails fast with a chown hint if /data or /models isn't writable - .env.example and README document the server storage layout Co-Authored-By: Claude Opus 5.5 --- .env.example | 10 ++++++++++ CHANGELOG.md | 3 +++ README.md | 9 +++++++++ deploy/compose.yaml | 24 +++++++++++++++++++----- docker-entrypoint.sh | 11 ++++++++++- 5 files changed, 51 insertions(+), 6 deletions(-) diff --git a/.env.example b/.env.example index 03c692c..1ccfb5f 100644 --- a/.env.example +++ b/.env.example @@ -20,3 +20,13 @@ OIDC_CLIENT_ID= OIDC_CLIENT_SECRET= # Optional, comma-separated. If set, only members of these groups (from the `groups` claim) can log in. OIDC_ALLOWED_GROUPS= + +# --- deploy/compose.yaml only ------------------------------------------------- +# Image tag to run (default: latest) +KANAME_VERSION= +# Host folder for the SQLite DB, shared by web and worker. Local disk, not NFS. Owner uid 1000. +KANAME_DATA_DIR=./data +WEB_PORT=3000 +# NFS export for the models (NFSv4, writable by uid 1000) +NFS_SERVER=truenas.lan +NFS_EXPORT=/mnt/tank/models diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d73555..2848778 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,9 @@ step 1 (Hugging Face downloader) is released as a minor version. 20 lines: the image now has an entrypoint with roles (`web`/`worker`), runs migrations itself under a file lock (no start-order dependency between the services) and has a built-in healthcheck. +- Server storage: SQLite on a shared host folder (`KANAME_DATA_DIR`, bind mount for web and worker), + models on an NFSv4 volume (`NFS_SERVER`, `NFS_EXPORT`) mounted only by the worker. +- The container stops with a clear message if `/data` (or `/models` for the worker) isn't writable. - The app version is shown next to the app name (`APP_VERSION`, set at image build time). ### Changed diff --git a/README.md b/README.md index ca79f01..5a5f597 100644 --- a/README.md +++ b/README.md @@ -39,9 +39,18 @@ On the server you only need `deploy/compose.yaml` and a filled-in `.env` (from ` one folder; no source code, no Dockerfile: ```bash +mkdir -p data && sudo chown 1000:1000 data # SQLite DB, shared by web and worker (local disk!) docker compose pull && docker compose up -d ``` +Storage layout on the server: + +- `KANAME_DATA_DIR` (default `./data`): bind mount for the SQLite DB, mounted by both services. + Must be on local disk (SQLite breaks on NFS) and owned by uid 1000. +- `models`: NFS volume from `NFS_SERVER`/`NFS_EXPORT`, mounted only by the worker. Use NFSv4 + (hf needs file locks) and make the dataset writable for uid 1000 (owner 1000, or TrueNAS + *Mapall User/Group*). After changing NFS settings: `docker compose down && docker volume rm kaname_models`. + Pin a version with `KANAME_VERSION=0.4.0` in `.env`; the running version is shown next to the app name in the header. diff --git a/deploy/compose.yaml b/deploy/compose.yaml index 7f74bdc..eb56880 100644 --- a/deploy/compose.yaml +++ b/deploy/compose.yaml @@ -1,20 +1,34 @@ # Server setup: put this file and a filled-in .env (from .env.example) in a folder, then +# mkdir -p data && sudo chown 1000:1000 data # docker compose pull && docker compose up -d +name: kaname + services: worker: image: git.linxweiler.xyz/pascallinxweiler/kaname:${KANAME_VERSION:-latest} command: worker env_file: .env - volumes: [data:/data, models:/models] + volumes: + - ${KANAME_DATA_DIR:-./data}:/data + - models:/models restart: unless-stopped web: image: git.linxweiler.xyz/pascallinxweiler/kaname:${KANAME_VERSION:-latest} env_file: .env - ports: ["3000:3000"] - volumes: [data:/data] + ports: ["${WEB_PORT:-3000}:3000"] + volumes: + - ${KANAME_DATA_DIR:-./data}:/data restart: unless-stopped volumes: - data: # SQLite + hf home: keep on local disk - models: # downloaded models (later: NFS from TrueNAS) + # Downloaded models on the NAS (only the worker mounts it). NFSv4 because hf uses file locks; + # "hard" makes writes wait while the NAS is unreachable instead of failing half-written. + # Docker keeps these options once the volume exists: after changing them, run + # `docker compose down && docker volume rm kaname_models` (files on the NAS are not touched). + models: + driver: local + driver_opts: + type: nfs + o: "addr=${NFS_SERVER:?set NFS_SERVER in .env},nfsvers=4.1,rw,hard,noatime" + device: ":${NFS_EXPORT:?set NFS_EXPORT in .env}" diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 6c75a01..94df04d 100644 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -4,11 +4,20 @@ set -e role="${1:-web}" +require_writable() { + if ! touch "$1/.write-test" 2>/dev/null; then + echo "ERROR: $1 is not writable by uid $(id -u). On the host: chown -R $(id -u):$(id -g) " >&2 + exit 1 + fi + rm -f "$1/.write-test" +} + case "$role" in web|worker) echo "$role" > /tmp/kaname-role + require_writable /data + if [ "$role" = worker ]; then require_writable "${MODELS_DIR:-/models}"; fi # web and worker usually start together; the lock makes sure only one runs the migrations. - mkdir -p /data flock /data/.migrate.lock node dist/migrate.mjs ;; esac