- 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 <noreply@anthropic.com>
95 lines
4.4 KiB
Markdown
95 lines
4.4 KiB
Markdown
# Model Manager
|
|
|
|
Self-hosted web UI for downloading and managing local LLMs from Hugging Face.
|
|
Downloads are done by the official `hf` CLI; the Hub API is used for metadata.
|
|
|
|
## Architecture
|
|
|
|
- **web** (`next start`): Next.js App Router UI + API routes, OIDC login via Auth.js.
|
|
- **worker** (`src/worker`): owns the job queue, spawns `hf download`, tracks progress from bytes on
|
|
disk, applies DB migrations at startup. Only one worker runs at a time (DB lease).
|
|
- They talk only through the SQLite database (`DATABASE_URL`); the UI gets live updates via SSE
|
|
(`/api/stream`).
|
|
|
|
## Run with Docker (recommended)
|
|
|
|
```bash
|
|
cp .env.example .env # fill in HF_TOKEN, AUTH_SECRET, OIDC_*; AUTH_URL = URL you open in the browser
|
|
docker compose up --build
|
|
```
|
|
|
|
Open `AUTH_URL` (e.g. http://localhost:3000). `WEB_PORT=3100 docker compose up` changes the host port.
|
|
Volumes: `data` (SQLite + hf home, keep on local disk) and `models` (downloaded models).
|
|
|
|
OIDC redirect URI for the client in Pocket ID: `<AUTH_URL>/api/auth/callback/pocket-id`.
|
|
|
|
## Releases and deployment
|
|
|
|
Pushing a tag `vX.Y.Z` (must equal `version` in `package.json` and have a `## [X.Y.Z]` section in
|
|
`CHANGELOG.md`) runs `.gitea/workflows/release.yaml` on Gitea Actions:
|
|
|
|
1. lint, typecheck, unit tests
|
|
2. builds the image and pushes `git.linxweiler.xyz/pascallinxweiler/kaname:X.Y.Z`, `:X.Y` and `:latest`
|
|
3. creates a Gitea release with the CHANGELOG section as notes
|
|
|
|
Requirements: an `act_runner` registered for the repo/user with Docker access, and a repo secret
|
|
`REGISTRY_TOKEN` (personal access token with *package: read and write*).
|
|
|
|
On the server you only need `deploy/compose.yaml` and a filled-in `.env` (from `.env.example`) in
|
|
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.
|
|
|
|
The image picks its role from the first argument: `web` (default) or `worker`. Both run pending
|
|
DB migrations at startup (serialized with a file lock on `/data`), and the image has a built-in
|
|
healthcheck for both roles.
|
|
|
|
## Local development
|
|
|
|
```bash
|
|
npm install
|
|
npm run dev # web (http://localhost:3000) + worker
|
|
```
|
|
|
|
Use local paths in `.env` (`DATABASE_URL=file:./data/app.db`, `MODELS_DIR=./data/models`).
|
|
The worker needs the `hf` CLI on `PATH` (`pip install "huggingface_hub[hf_xet]==2.1.1"`); without it
|
|
everything but downloading works. Don't point a Windows-native web app and a containerized worker at
|
|
the same SQLite file: SQLite locking doesn't work across that boundary.
|
|
|
|
| Script | What it does |
|
|
| --- | --- |
|
|
| `npm run dev:web` / `npm run dev:worker` | run one side only |
|
|
| `npm run db:generate` | create a migration after changing `src/lib/db/schema.ts` |
|
|
| `npm run db:migrate` | apply migrations without starting the worker |
|
|
| `npm run build:worker` | bundle the worker to `dist/worker.mjs` (used in the image) |
|
|
| `npm test` | unit tests (Node test runner via tsx) |
|
|
| `npm run typecheck`, `npm run lint` | checks |
|
|
|
|
## How `hf download` behaves (huggingface_hub 2.1.1)
|
|
|
|
Verified in a container; the image pins this version. Re-check before bumping it.
|
|
|
|
- With `--local-dir`, partial files live in `<dir>/.cache/huggingface/download/` as
|
|
`<hash>.<etag>.<random>.incomplete` and are moved into place when complete.
|
|
- **Partial files are not resumed.** A re-run skips completed files but restarts unfinished ones
|
|
from zero (new random name). The worker deletes leftover partials.
|
|
- With Xet enabled the partial file only grows in large bursts, so the worker sets
|
|
`HF_HUB_DISABLE_XET=1` by default for accurate progress (configurable in `.env`).
|
|
- SIGTERM stops a download (exit 143); SIGINT does not stop a Xet download.
|
|
- Exit code 0 doesn't guarantee the files are there (e.g. a pattern that matched nothing), so the
|
|
worker checks every expected file's size and metadata afterwards.
|