fix(docker): use pnpm deploy for embedder runtime image

The previous Dockerfile copied apps/embedder/node_modules straight from
the deps stage, but with pnpm's default isolated layout that directory
is a farm of relative symlinks pointing into the root .pnpm store. With
the root node_modules absent in the runtime image, every dependency
resolution failed (fastify, @xenova/transformers, ...).

pnpm deploy --prod writes a portable directory with flat node_modules
that resolves cleanly from a fresh WORKDIR. The `files` field on the
embedder package opts dist/ into the deployed output (the workspace
.gitignore would otherwise exclude it).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-15 09:09:40 -07:00
co-authored by Claude Opus 4.7
parent 9a8b504f51
commit a6f944b44d
2 changed files with 12 additions and 11 deletions
+11 -11
View File
@@ -13,26 +13,27 @@ WORKDIR /app
FROM base AS deps
COPY package.json pnpm-workspace.yaml pnpm-lock.yaml .npmrc ./
COPY apps/embedder/package.json ./apps/embedder/
# Other workspace package.json files needed so pnpm install can resolve the
# workspace before --filter narrows things down.
COPY apps/web/package.json ./apps/web/
COPY packages/schemas/package.json ./packages/schemas/
RUN --mount=type=cache,id=pnpm,target=/root/.local/share/pnpm/store \
pnpm install --frozen-lockfile --filter @shared-memory/embedder...
pnpm install --frozen-lockfile
# ---------- builder ----------
FROM base AS builder
COPY --from=deps /app/node_modules ./node_modules
COPY --from=deps /app/apps/embedder/node_modules ./apps/embedder/node_modules
COPY --from=deps /app/apps/web/node_modules ./apps/web/node_modules
COPY --from=deps /app/packages/schemas/node_modules ./packages/schemas/node_modules
COPY . .
# Compile TS to JS.
# Compile TS → JS into apps/embedder/dist.
RUN cd apps/embedder \
&& pnpm exec tsc -p tsconfig.json --noEmit false --outDir dist
# Prune devDependencies so the runtime image only ships production deps.
RUN cd apps/embedder \
&& pnpm install --prod --frozen-lockfile --filter @shared-memory/embedder...
# `pnpm deploy` writes a self-contained tree to /deploy: package.json,
# dist/, and a flat node_modules with only production deps. The `files`
# field in apps/embedder/package.json is what tells deploy to include dist.
RUN pnpm --filter @shared-memory/embedder deploy --prod /deploy
# ---------- runner ----------
FROM node:20-alpine AS runner
@@ -48,15 +49,14 @@ RUN apk add --no-cache wget \
&& mkdir -p /data/models \
&& chown -R node-embedder:nodejs /data
COPY --from=builder --chown=node-embedder:nodejs /app/apps/embedder/dist ./dist
COPY --from=builder --chown=node-embedder:nodejs /app/apps/embedder/node_modules ./node_modules
COPY --from=builder --chown=node-embedder:nodejs /app/apps/embedder/package.json ./package.json
# /deploy is the self-contained output of `pnpm deploy --prod` — copy as-is.
COPY --from=builder --chown=node-embedder:nodejs /deploy ./
USER node-embedder
EXPOSE 8080
VOLUME ["/data/models"]
HEALTHCHECK --interval=15s --timeout=5s --start-period=120s --retries=5 \
HEALTHCHECK --interval=15s --timeout=5s --start-period=180s --retries=8 \
CMD wget -q -O - http://127.0.0.1:8080/health | grep -q '"ready":true' || exit 1
CMD ["node", "--enable-source-maps", "dist/index.js"]
+1
View File
@@ -3,6 +3,7 @@
"version": "0.1.0",
"private": true,
"type": "module",
"files": ["dist", "package.json"],
"scripts": {
"dev": "tsx watch src/index.ts",
"build": "tsc --noEmit",