From 24a412f793e6d31ac0656a353bc3dfcb63ea70f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorem=20Ju=C3=A1rez?= Date: Sat, 13 Jun 2026 20:13:21 -0600 Subject: [PATCH] Fix Prisma migrate deploy in standalone production image The entrypoint invoked the node_modules/.bin/prisma symlink, so Node resolved the CLI's bundled .wasm files relative to .bin/ and crashed with ENOENT on prisma_schema_build_bg.wasm. Call the real CLI entry (node_modules/prisma/build/ index.js) instead so the wasm resolves under prisma/build/. Also add the linux-musl-openssl-3.0.x binaryTarget so the runtime engine matches the alpine runner regardless of build host arch. Verified end-to-end in a built alpine image: migrate deploy applies, and the Prisma client reads/writes against Postgres at runtime. --- Dockerfile | 10 ++++++++-- docker-entrypoint.sh | 5 ++++- prisma/schema.prisma | 5 ++++- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 6f4bc72..ddea050 100644 --- a/Dockerfile +++ b/Dockerfile @@ -26,9 +26,15 @@ COPY --from=builder /app/public ./public COPY --from=builder /app/.next/standalone ./ COPY --from=builder /app/.next/static ./.next/static -# Prisma needs the schema + engine + CLI to run migrate deploy at startup. +# Prisma needs the schema + migrations + CLI + engines to run migrate deploy at +# startup. We copy the FULL packages (not the .bin symlink) so the CLI's bundled +# .wasm files resolve relative to node_modules/prisma/build/, and the entrypoint +# invokes the real entry path directly (see docker-entrypoint.sh). +# - prisma/ : schema.prisma + migrations/ +# - node_modules/prisma: CLI + prisma_schema_build_bg.wasm and friends +# - node_modules/@prisma: engines (schema-engine for migrate) + client runtime +# - node_modules/.prisma: generated client + linux-musl query engine COPY --from=builder /app/prisma ./prisma -COPY --from=builder /app/node_modules/.bin/prisma ./node_modules/.bin/prisma COPY --from=builder /app/node_modules/prisma ./node_modules/prisma COPY --from=builder /app/node_modules/@prisma ./node_modules/@prisma COPY --from=builder /app/node_modules/.prisma ./node_modules/.prisma diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 48bd329..916543b 100644 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -2,8 +2,11 @@ set -e # Apply pending migrations against the database, then start the server. +# Invoke the real CLI entry (NOT the .bin/prisma symlink): Node resolves the +# bundled .wasm files relative to the script's own directory, so calling the +# symlink would look for them under node_modules/.bin/ and fail with ENOENT. echo "Running prisma migrate deploy…" -./node_modules/.bin/prisma migrate deploy +node node_modules/prisma/build/index.js migrate deploy # Ensure the upload directory exists in the mounted volume. mkdir -p "${UPLOAD_DIR:-/data/uploads}" diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 311231e..71d1004 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -1,5 +1,8 @@ generator client { - provider = "prisma-client-js" + provider = "prisma-client-js" + // native = host platform (builder/runner are both node:20-alpine = musl). + // The explicit musl target guards the runtime engine in the final image. + binaryTargets = ["native", "linux-musl-openssl-3.0.x"] } datasource db {