batchCooking/services/tech-step-llm-worker/Dockerfile
Nicolas 1d69a61b37 fix(worker): corrige le build Docker de tech-step-llm-worker
docker compose build tech-step-llm-worker échouait sur deux problèmes
en cascade, tous deux liés à l'isolation volontaire de ce service hors
du monorepo pnpm (seul son propre package.json/tsconfig.json est copié
dans son contexte de build) :

- pnpm install --ignore-workspace --frozen-lockfile échouait
  (ERR_PNPM_IGNORED_BUILDS) : sans "packageManager" dans son
  package.json, corepack télécharge le pnpm le plus récent
  (11.22.0), qui a durci en erreur bloquante ce qui n'était qu'un
  avertissement sur les builds de dépendances ignorés
  (esbuild/node-llama-cpp). Le reste du repo est épargné parce que
  apps/api/Dockerfile copie le package.json racine, qui pinne déjà
  pnpm@10.12.4 — ce pin ne pouvait pas atteindre ce service isolé.
  Fixé en pinnant la même version ici.
- tsc échouait ensuite (TS5083 puis erreurs en cascade dans les .d.ts
  de node-llama-cpp) : tsconfig.json de ce service extends le
  tsconfig.base.json racine (skipLibCheck notamment), jamais copié
  dans le contexte de build. Fixé en le copiant avant tsconfig.json.

Vérifié : `docker compose build tech-step-llm-worker` complet en local.
2026-08-22 12:30:27 +02:00

42 lines
2.2 KiB
Docker

# Standalone image for services/tech-step-llm-worker — deliberately *not*
# built as part of apps/api's own Dockerfile/image (see this package's own
# package.json doc comment): node-llama-cpp's native binding must never be
# compiled into the API's image, and this worker shares no dependencies or
# code with it (see api-client.ts's own doc comment on why its types are
# duplicated rather than imported from @batch-cooking/shared).
FROM node:22-slim AS base
# node-llama-cpp's postinstall builds/downloads a native binding — basic
# build tooling covers the (rare) case a prebuilt binary isn't available
# for this platform; ca-certificates is needed for the HTTPS download of
# both that binary and the GGUF model weights (resolveModelFile,
# llm-verdict.ts).
RUN apt-get update && apt-get install -y --no-install-recommends python3 make g++ ca-certificates && rm -rf /var/lib/apt/lists/*
RUN corepack enable
WORKDIR /worker
FROM base AS build
# `pnpm-lock.yaml` is committed for this package (unlike
# experiments/llm-tech-step-poc, which has none) — `--frozen-lockfile`
# means a build fails loudly on any drift instead of silently resolving
# different versions than what's on disk/CI.
COPY services/tech-step-llm-worker/package.json services/tech-step-llm-worker/pnpm-lock.yaml ./
RUN pnpm install --ignore-workspace --frozen-lockfile
# tsconfig.json `extends` the repo-root base config (shared with every
# other package's own tsconfig) — must be copied in alongside it, or `tsc`
# fails outright (TS5083) before it ever reaches src.
COPY tsconfig.base.json ../tsconfig.base.json
COPY services/tech-step-llm-worker/tsconfig.json ./tsconfig.json
COPY services/tech-step-llm-worker/src ./src
RUN pnpm exec tsc -p tsconfig.json
FROM base AS runtime
ENV NODE_ENV=production
COPY --from=build /worker/node_modules ./node_modules
COPY --from=build /worker/package.json ./package.json
COPY --from=build /worker/dist ./dist
# GGUF weights download on first run into ./models (see llm-verdict.ts's
# MODELS_DIRECTORY) — mounted as a named volume in docker-compose.yml so a
# container restart doesn't re-download several hundred MB to a GB every
# time.
VOLUME ["/worker/models"]
CMD ["node", "dist/index.js"]