Files
Kaname/Dockerfile
T
Pascal LinxweilerandClaude Opus 5.5 fbcdcf2e2d 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>
2026-10-05 17:30:49 +02:00

56 lines
1.9 KiB
Docker

# One image for both services; the first argument picks the role: `web` (default) or `worker`.
FROM node:24-trixie-slim AS node
# --- build -------------------------------------------------------------------
FROM node AS build
ENV NEXT_TELEMETRY_DISABLED=1
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm ci
COPY . .
RUN npm run build \
&& npm run build:worker \
&& npm prune --omit=dev
# --- runtime -----------------------------------------------------------------
# Python base (provides the official `hf` CLI) plus the Node binary. The Python image already
# has CA certificates and libstdc++, so no apt is needed.
FROM python:3.13-slim-trixie AS runtime
COPY --from=node /usr/local/bin/node /usr/local/bin/node
# Pinned: the worker relies on the CLI's on-disk layout (see src/worker/hf-layout.ts);
# re-verify that before bumping.
ARG HF_HUB_VERSION=2.1.1
RUN python -m venv /opt/hf \
&& /opt/hf/bin/pip install --no-cache-dir "huggingface_hub[hf_xet]==${HF_HUB_VERSION}" \
&& rm -rf /root/.cache \
&& useradd --uid 1000 --create-home --shell /usr/sbin/nologin app \
&& mkdir -p /data /models \
&& chown app:app /data /models
ARG APP_VERSION=dev
ENV PATH=/opt/hf/bin:$PATH \
APP_VERSION=$APP_VERSION \
NODE_ENV=production \
NEXT_TELEMETRY_DISABLED=1 \
PORT=3000 \
HOSTNAME=0.0.0.0 \
DATABASE_URL=file:/data/app.db \
MODELS_DIR=/models \
HF_HOME=/data/hf-home
WORKDIR /app
COPY --from=build --chown=app:app /app/package.json /app/next.config.ts ./
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
HEALTHCHECK --interval=15s --timeout=5s --start-period=30s --retries=3 CMD ["docker-healthcheck.sh"]
ENTRYPOINT ["docker-entrypoint.sh"]
CMD ["web"]