From cca866505f0a2bba24ec68028e652ae950243194 Mon Sep 17 00:00:00 2001 From: Jarvis Date: Tue, 21 Apr 2026 20:53:28 -0500 Subject: [PATCH] fix(docker): use pnpm deploy for self-contained gateway image MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Root cause: the runner stage copied /app/node_modules (the pnpm content-addressed .pnpm store) instead of apps/gateway/node_modules (which holds the symlinks Node.js uses to resolve packages relative to the gateway entrypoint). In a stripped image without pnpm's virtual store topology, dotenv and every other dep were unresolvable, causing ERR_MODULE_NOT_FOUND on startup. Fix: replace the broken node_modules copy with `pnpm deploy --legacy` which produces a flat, self-contained node_modules at /deploy — no workspace symlinks required. Also corrected the filter name (@mosaic/gateway → @mosaicstack/gateway), added COPY plugins/ to the pre-install step so turbo's dependency graph can resolve the telegram/discord plugins that are workspace deps of the gateway, and switched the build step to `pnpm turbo run build --filter @mosaicstack/gateway...` so all transitive workspace packages are compiled in topological order before the gateway. Verification: local build succeeded (image sha256:dd44b49b5cf49bafd91f8733792b25b08a4711d2ee1bb278460aea747c305bd0, ~254 MB). Running the image with stub env reaches Postgres connection error (TierDetectionError: postgres unreachable at nope:5432) — dotenv loads cleanly, past module resolution. No ERR_MODULE_NOT_FOUND. Co-Authored-By: Claude Sonnet 4.6 --- docker/gateway.Dockerfile | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/docker/gateway.Dockerfile b/docker/gateway.Dockerfile index 39b7a5b..dc67899 100644 --- a/docker/gateway.Dockerfile +++ b/docker/gateway.Dockerfile @@ -5,18 +5,27 @@ RUN corepack enable FROM base AS builder WORKDIR /app +# Copy workspace manifests first for layer-cached install COPY pnpm-workspace.yaml pnpm-lock.yaml package.json ./ COPY apps/gateway/package.json ./apps/gateway/ COPY packages/ ./packages/ +COPY plugins/ ./plugins/ RUN pnpm install --frozen-lockfile COPY . . -RUN pnpm --filter @mosaic/gateway build +# Build gateway and all of its workspace dependencies via turbo dependency graph +RUN pnpm turbo run build --filter @mosaicstack/gateway... +# Produce a self-contained deploy artifact: flat node_modules, no pnpm symlinks +# --legacy is required for pnpm v10 when inject-workspace-packages is not set +RUN pnpm --filter @mosaicstack/gateway --prod deploy --legacy /deploy FROM base AS runner WORKDIR /app ENV NODE_ENV=production +# Use the pnpm deploy output — resolves all deps into a flat, self-contained node_modules +COPY --from=builder /deploy/node_modules ./node_modules +COPY --from=builder /deploy/package.json ./package.json +# dist is declared in package.json "files" so pnpm deploy copies it into /deploy; +# copy from builder explicitly as belt-and-suspenders COPY --from=builder /app/apps/gateway/dist ./dist -COPY --from=builder /app/apps/gateway/package.json ./package.json -COPY --from=builder /app/node_modules ./node_modules EXPOSE 4000 CMD ["node", "dist/main.js"]