Slim down server compose: entrypoint roles, self-migrating image

- docker-entrypoint.sh: `web` (default) or `worker`; both apply pending
  migrations under a flock on /data, so no start-order dependency
- docker-healthcheck.sh baked into the image for both roles
- deploy/compose.yaml reduced to image, role, env file, volumes, port
- dist/migrate.mjs bundled alongside the worker

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Pascal LinxweilerandClaude Opus 5.5 committed 2026-10-05 17:30:49 +02:00
1 parent 30b01d7bca
commit fbcdcf2e2d
8 files changed
+65 -72

No files matched your search

+4 -1
View File
@@ -10,7 +10,10 @@ step 1 (Hugging Face downloader) is released as a minor version.
- Release pipeline (`.gitea/workflows/release.yaml`): a `vX.Y.Z` tag runs checks, pushes the Docker
image to the Gitea registry (`X.Y.Z`, `X.Y`, `latest`) and creates a release from this changelog.
- `deploy/compose.yaml` for the server, using the released image (`KANAME_VERSION` to pin).
- `deploy/compose.yaml` for the server, using the released image (`KANAME_VERSION` to pin). About
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.
- The app version is shown next to the app name (`APP_VERSION`, set at image build time).
### Changed
+5 -2
View File
@@ -1,4 +1,4 @@
# One image for both services: `web` (next start) and `worker` (node dist/worker.mjs).
# One image for both services; the first argument picks the role: `web` (default) or `worker`.
FROM node:24-trixie-slim AS node
@@ -46,7 +46,10 @@ COPY --from=build --chown=app:app /app/node_modules ./node_modules
COPY --from=build --chown=app:app /app/.next ./.next
COPY --from=build --chown=app:app /app/dist ./dist
COPY --from=build --chown=app:app /app/drizzle ./drizzle
COPY --chmod=755 docker-entrypoint.sh docker-healthcheck.sh /usr/local/bin/
USER app
EXPOSE 3000
CMD ["node_modules/.bin/next", "start"]
HEALTHCHECK --interval=15s --timeout=5s --start-period=30s --retries=3 CMD ["docker-healthcheck.sh"]
ENTRYPOINT ["docker-entrypoint.sh"]
CMD ["web"]
+6 -2
View File
@@ -35,16 +35,20 @@ Pushing a tag `vX.Y.Z` (must equal `version` in `package.json` and have a `## [X
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, use `deploy/compose.yaml` (pulls the released image instead of building):
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
# in a folder with deploy/compose.yaml and a filled-in .env next to it
docker compose pull && docker compose up -d
```
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
+8 -24
View File
@@ -1,44 +1,28 @@
# Builds the image from this checkout. For the server use deploy/compose.yaml (released image).
name: kaname
x-app: &app
image: kaname:local
build: .
env_file: .env
# Container paths override whatever local-dev paths are in .env.
# Container paths win over local-dev paths in .env.
environment:
DATABASE_URL: file:/data/app.db
MODELS_DIR: /models
HF_HOME: /data/hf-home
restart: unless-stopped
init: true # reaps child processes (hf) and forwards signals
services:
worker:
<<: *app
command: ["node", "dist/worker.mjs"]
volumes:
- data:/data
- models:/models
# Give running downloads time to stop cleanly (they are marked "interrupted").
stop_grace_period: 20s
healthcheck:
test: ["CMD-SHELL", "find /tmp/kaname-worker-alive -mmin -1 | grep -q ."]
interval: 10s
timeout: 5s
start_period: 30s
retries: 3
command: worker
volumes: [data:/data, models:/models]
web:
<<: *app
command: ["node_modules/.bin/next", "start"]
ports:
- "${WEB_PORT:-3000}:3000"
volumes:
- data:/data
depends_on:
worker:
condition: service_healthy # worker applies DB migrations on startup
ports: ["${WEB_PORT:-3000}:3000"]
volumes: [data:/data]
volumes:
data: # SQLite + hf home; keep on local disk (SQLite and NFS don't mix)
models: # downloaded models; will become an NFS mount from TrueNAS
data:
models:
+13 -42
View File
@@ -1,49 +1,20 @@
# Production compose for the server: runs the released image from the Gitea registry.
# (The compose.yaml in the repo root builds the image locally instead.)
#
# cp ../.env.example .env # fill in, AUTH_URL = public URL
# Server setup: put this file and a filled-in .env (from .env.example) in a folder, then
# docker compose pull && docker compose up -d
#
# Pin a version with KANAME_VERSION=0.4.0 in .env (default: latest).
name: kaname
x-app: &app
image: git.linxweiler.xyz/pascallinxweiler/kaname:${KANAME_VERSION:-latest}
env_file: .env
environment:
DATABASE_URL: file:/data/app.db
MODELS_DIR: /models
HF_HOME: /data/hf-home
restart: unless-stopped
init: true
services:
worker:
<<: *app
command: ["node", "dist/worker.mjs"]
volumes:
- data:/data
- models:/models
stop_grace_period: 20s
healthcheck:
test: ["CMD-SHELL", "find /tmp/kaname-worker-alive -mmin -1 | grep -q ."]
interval: 10s
timeout: 5s
start_period: 30s
retries: 3
image: git.linxweiler.xyz/pascallinxweiler/kaname:${KANAME_VERSION:-latest}
command: worker
env_file: .env
volumes: [data:/data, models:/models]
restart: unless-stopped
web:
<<: *app
command: ["node_modules/.bin/next", "start"]
ports:
- "${WEB_PORT:-3000}:3000"
volumes:
- data:/data
depends_on:
worker:
condition: service_healthy
image: git.linxweiler.xyz/pascallinxweiler/kaname:${KANAME_VERSION:-latest}
env_file: .env
ports: ["3000:3000"]
volumes: [data:/data]
restart: unless-stopped
volumes:
data: # SQLite + hf home; keep on local disk (SQLite and NFS don't mix)
models: # downloaded models; will become an NFS mount from TrueNAS
data: # SQLite + hf home: keep on local disk
models: # downloaded models (later: NFS from TrueNAS)
+20
View File
@@ -0,0 +1,20 @@
#!/bin/sh
# Usage: docker run <image> [web|worker|<any command>] (default: web)
set -e
role="${1:-web}"
case "$role" in
web|worker)
echo "$role" > /tmp/kaname-role
# 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
case "$role" in
web) exec node_modules/.bin/next start ;;
worker) exec node dist/worker.mjs ;;
*) exec "$@" ;;
esac
+8
View File
@@ -0,0 +1,8 @@
#!/bin/sh
# Healthcheck for both roles (see docker-entrypoint.sh).
case "$(cat /tmp/kaname-role 2>/dev/null)" in
# The worker touches this file on every heartbeat (every 5s).
worker) find /tmp/kaname-worker-alive -mmin -1 | grep -q . ;;
web) node -e 'fetch("http://127.0.0.1:" + (process.env.PORT || 3000) + "/login").then((r) => process.exit(r.ok ? 0 : 1), () => process.exit(1))' ;;
*) exit 0 ;;
esac
+1 -1
View File
@@ -14,7 +14,7 @@
"db:generate": "drizzle-kit generate",
"db:migrate": "dotenv -e .env -- tsx src/lib/db/migrate-cli.ts",
"test": "tsx --test \"src/**/*.test.ts\"",
"build:worker": "esbuild src/worker/index.ts --bundle --platform=node --target=node24 --format=esm --packages=external --outfile=dist/worker.mjs"
"build:worker": "esbuild src/worker/index.ts --bundle --platform=node --target=node24 --format=esm --packages=external --outfile=dist/worker.mjs && esbuild src/lib/db/migrate-cli.ts --bundle --platform=node --target=node24 --format=esm --packages=external --outfile=dist/migrate.mjs"
},
"dependencies": {
"@base-ui/react": "^1.8.0",