fix(docker): pnpm deploy for self-contained gateway runtime image #488
Reference in New Issue
Block a user
Delete Branch "fix/gateway-dockerfile-pnpm-deploy"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Bug
The gateway production Docker image failed immediately with
ERR_MODULE_NOT_FOUNDfordotenv(and every other runtime dep). Root cause: the runner stage copied/app/node_modules— pnpm's content-addressed.pnpmstore — rather thanapps/gateway/node_modules, which holds the symlinks Node.js uses to resolve packages relative to the entrypoint. In a stripped image without pnpm's virtual store topology, no package was resolvable.Additional bugs discovered during fix:
@mosaic/gateway(should be@mosaicstack/gateway)plugins/package.json files not copied beforepnpm install, so telegram/discord plugin workspace packages had nonode_modulesFix
COPY /app/node_moduleswithpnpm deploy --legacywhich produces a flat, self-contained/deploy/node_modules— no workspace symlinks or pnpm store structure needed at runtime@mosaicstack/gatewayCOPY plugins/ ./plugins/beforepnpm installso all workspace members are includedtscbuild withpnpm turbo run build --filter @mosaicstack/gateway...to build the gateway and all transitive workspace dependencies in topological order--legacyflag required by pnpm v10 for deploy in shared-lockfile workspaces withoutinject-workspace-packagesVerification
Local build: image
sha256:dd44b49b5cf49bafd91f8733792b25b08a4711d2ee1bb278460aea747c305bd0(~254 MB), all 13 packages built (13 successful, 0 failed).Runtime test:
Output:
dotenvloads cleanly. The process reaches Postgres connection — past module resolution. NoERR_MODULE_NOT_FOUND.Files changed
docker/gateway.Dockerfileonly