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:
1 parent
30b01d7bca
commit
fbcdcf2e2d
8 files changed
+65
-72
No files matched your search
+4
-1
@@ -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
|
- 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.
|
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).
|
- The app version is shown next to the app name (`APP_VERSION`, set at image build time).
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|||||||
+5
-2
@@ -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
|
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/.next ./.next
|
||||||
COPY --from=build --chown=app:app /app/dist ./dist
|
COPY --from=build --chown=app:app /app/dist ./dist
|
||||||
COPY --from=build --chown=app:app /app/drizzle ./drizzle
|
COPY --from=build --chown=app:app /app/drizzle ./drizzle
|
||||||
|
COPY --chmod=755 docker-entrypoint.sh docker-healthcheck.sh /usr/local/bin/
|
||||||
|
|
||||||
USER app
|
USER app
|
||||||
EXPOSE 3000
|
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"]
|
||||||
@@ -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
|
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*).
|
`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
|
```bash
|
||||||
# in a folder with deploy/compose.yaml and a filled-in .env next to it
|
|
||||||
docker compose pull && docker compose up -d
|
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
|
Pin a version with `KANAME_VERSION=0.4.0` in `.env`; the running version is shown next to the app
|
||||||
name in the header.
|
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
|
## Local development
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
|||||||
+8
-24
@@ -1,44 +1,28 @@
|
|||||||
|
# Builds the image from this checkout. For the server use deploy/compose.yaml (released image).
|
||||||
name: kaname
|
name: kaname
|
||||||
|
|
||||||
x-app: &app
|
x-app: &app
|
||||||
image: kaname:local
|
image: kaname:local
|
||||||
build: .
|
build: .
|
||||||
env_file: .env
|
env_file: .env
|
||||||
# Container paths override whatever local-dev paths are in .env.
|
# Container paths win over local-dev paths in .env.
|
||||||
environment:
|
environment:
|
||||||
DATABASE_URL: file:/data/app.db
|
DATABASE_URL: file:/data/app.db
|
||||||
MODELS_DIR: /models
|
MODELS_DIR: /models
|
||||||
HF_HOME: /data/hf-home
|
HF_HOME: /data/hf-home
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
init: true # reaps child processes (hf) and forwards signals
|
|
||||||
|
|
||||||
services:
|
services:
|
||||||
worker:
|
worker:
|
||||||
<<: *app
|
<<: *app
|
||||||
command: ["node", "dist/worker.mjs"]
|
command: worker
|
||||||
volumes:
|
volumes: [data:/data, models:/models]
|
||||||
- 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
|
|
||||||
|
|
||||||
web:
|
web:
|
||||||
<<: *app
|
<<: *app
|
||||||
command: ["node_modules/.bin/next", "start"]
|
ports: ["${WEB_PORT:-3000}:3000"]
|
||||||
ports:
|
volumes: [data:/data]
|
||||||
- "${WEB_PORT:-3000}:3000"
|
|
||||||
volumes:
|
|
||||||
- data:/data
|
|
||||||
depends_on:
|
|
||||||
worker:
|
|
||||||
condition: service_healthy # worker applies DB migrations on startup
|
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
data: # SQLite + hf home; keep on local disk (SQLite and NFS don't mix)
|
data:
|
||||||
models: # downloaded models; will become an NFS mount from TrueNAS
|
models:
|
||||||
+13
-42
@@ -1,49 +1,20 @@
|
|||||||
# Production compose for the server: runs the released image from the Gitea registry.
|
# Server setup: put this file and a filled-in .env (from .env.example) in a folder, then
|
||||||
# (The compose.yaml in the repo root builds the image locally instead.)
|
|
||||||
#
|
|
||||||
# cp ../.env.example .env # fill in, AUTH_URL = public URL
|
|
||||||
# docker compose pull && docker compose up -d
|
# 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:
|
services:
|
||||||
worker:
|
worker:
|
||||||
<<: *app
|
image: git.linxweiler.xyz/pascallinxweiler/kaname:${KANAME_VERSION:-latest}
|
||||||
command: ["node", "dist/worker.mjs"]
|
command: worker
|
||||||
volumes:
|
env_file: .env
|
||||||
- data:/data
|
volumes: [data:/data, models:/models]
|
||||||
- models:/models
|
restart: unless-stopped
|
||||||
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
|
|
||||||
|
|
||||||
web:
|
web:
|
||||||
<<: *app
|
image: git.linxweiler.xyz/pascallinxweiler/kaname:${KANAME_VERSION:-latest}
|
||||||
command: ["node_modules/.bin/next", "start"]
|
env_file: .env
|
||||||
ports:
|
ports: ["3000:3000"]
|
||||||
- "${WEB_PORT:-3000}:3000"
|
volumes: [data:/data]
|
||||||
volumes:
|
restart: unless-stopped
|
||||||
- data:/data
|
|
||||||
depends_on:
|
|
||||||
worker:
|
|
||||||
condition: service_healthy
|
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
data: # SQLite + hf home; keep on local disk (SQLite and NFS don't mix)
|
data: # SQLite + hf home: keep on local disk
|
||||||
models: # downloaded models; will become an NFS mount from TrueNAS
|
models: # downloaded models (later: NFS from TrueNAS)
|
||||||
@@ -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
|
||||||
@@ -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
@@ -14,7 +14,7 @@
|
|||||||
"db:generate": "drizzle-kit generate",
|
"db:generate": "drizzle-kit generate",
|
||||||
"db:migrate": "dotenv -e .env -- tsx src/lib/db/migrate-cli.ts",
|
"db:migrate": "dotenv -e .env -- tsx src/lib/db/migrate-cli.ts",
|
||||||
"test": "tsx --test \"src/**/*.test.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": {
|
"dependencies": {
|
||||||
"@base-ui/react": "^1.8.0",
|
"@base-ui/react": "^1.8.0",
|
||||||
|
|||||||
Reference in new issue
Block a user