From a056cefa76cadc7949c1c8f1aa2d24547ff4cdaa Mon Sep 17 00:00:00 2001 From: thanhnv Date: Wed, 1 Jul 2026 22:42:47 +0900 Subject: [PATCH] fix(backend-image): keep bcrypt native addon in runtime stage MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The runtime stage reinstalled deps with `npm ci --ignore-scripts`, which skips bcrypt's install script and never produces bcrypt_lib.node. The app then crash-looped at runtime ("Cannot find module .../bcrypt_lib.node") — the Prisma seed and NestJS auth both require bcrypt — so nginx returned 502 on login. Reuse the builder's node_modules (bcrypt built WITH scripts + generated Prisma client) instead of reinstalling. builder and runtime share node:20-slim, so the native binaries are ABI/platform-compatible. Co-Authored-By: Claude Opus 4.8 (1M context) --- AINative_OKR_CASAN5/Dockerfile.backend | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/AINative_OKR_CASAN5/Dockerfile.backend b/AINative_OKR_CASAN5/Dockerfile.backend index f743517..8e6c336 100644 --- a/AINative_OKR_CASAN5/Dockerfile.backend +++ b/AINative_OKR_CASAN5/Dockerfile.backend @@ -29,9 +29,13 @@ COPY backend/package.json ./backend/ COPY frontend/package.json ./frontend/ COPY backend/prisma ./backend/prisma -RUN npm ci --ignore-scripts - -RUN cd backend && npx prisma generate +# Reuse the builder's node_modules: it already contains bcrypt's compiled +# native addon (built WITH install scripts) and the generated Prisma client. +# A fresh `npm ci --ignore-scripts` here omits bcrypt's *.node binary, so the +# app crash-loops at runtime ("Cannot find module .../bcrypt_lib.node") — both +# the seed and NestJS auth require bcrypt. builder and runtime share the same +# node:20-slim base, so the native binaries are ABI/platform-compatible. +COPY --from=builder /app/node_modules ./node_modules COPY --from=builder /app/backend/dist ./backend/dist COPY backend/entrypoint.sh /entrypoint.sh