# ─── Stage 1: Build ────────────────────────────────────────────────────────── FROM node:20-slim AS builder WORKDIR /app RUN apt-get update -qq && apt-get install -y -qq openssl python3 && rm -rf /var/lib/apt/lists/* COPY package.json package-lock.json ./ COPY apps/okr/backend/package.json ./apps/okr/backend/ COPY apps/okr/frontend/package.json ./apps/okr/frontend/ COPY apps/okr/backend/prisma ./apps/okr/backend/prisma RUN npm ci COPY apps/okr/backend/src ./apps/okr/backend/src COPY apps/okr/backend/tsconfig*.json ./apps/okr/backend/ RUN cd apps/okr/backend && npx prisma generate && npx tsc -p tsconfig.build.json # ─── Stage 2: Runtime ──────────────────────────────────────────────────────── FROM node:20-slim AS runtime WORKDIR /app RUN apt-get update -qq && apt-get install -y -qq openssl && rm -rf /var/lib/apt/lists/* COPY package.json package-lock.json ./ COPY apps/okr/backend/package.json ./apps/okr/backend/ COPY apps/okr/frontend/package.json ./apps/okr/frontend/ COPY apps/okr/backend/prisma ./apps/okr/backend/prisma # 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/apps/okr/backend/dist ./apps/okr/backend/dist COPY apps/okr/backend/entrypoint.sh /entrypoint.sh RUN chmod +x /entrypoint.sh WORKDIR /app/apps/okr/backend EXPOSE 3001 ENV PORT=3001 ENV NODE_ENV=production ENTRYPOINT ["/entrypoint.sh"]