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.
This commit is contained in:
1 parent
fc12ff5f02
commit
24a412f793
3 files changed
+16
-4
No files matched your search
+8
-2
@@ -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
|
||||
|
||||
@@ -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}"
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in new issue
Block a user