# Multi-stage Dockerfile for backend-api # Build stage: install deps and compile FROM node:20-bullseye AS builder WORKDIR /app # Install build dependencies COPY package.json package-lock.json* ./ # Try npm ci (fast & reproducible). If package-lock.json is missing, fallback to npm install RUN apt-get update && apt-get install -y --no-install-recommends python3 build-essential ca-certificates && rm -rf /var/lib/apt/lists/* \ && (npm ci --no-audit --no-fund || npm install --no-audit --no-fund) # Copy source and generate Prisma client, then build COPY . . # Generate Prisma client so that node_modules/@prisma/client contains the generated client RUN npx prisma generate --schema=./prisma/schema.prisma || true # Build the TypeScript project RUN npm run build # Remove dev dependencies to leave only production deps (smaller final copy) # We run npm prune --production which keeps installed production deps in node_modules RUN npm prune --production || true # Production stage: copy built files and production deps FROM node:20-bullseye WORKDIR /app # Copy built output COPY --from=builder /app/dist ./dist # Copy production node_modules (including generated Prisma client) COPY --from=builder /app/node_modules ./node_modules # Copy package.json (useful for runtime metadata) COPY --from=builder /app/package.json ./package.json # Copy entrypoint script COPY docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh RUN chmod +x /usr/local/bin/docker-entrypoint.sh ENV NODE_ENV=production ENV HOST=0.0.0.0 ENV PORT=4000 EXPOSE 4000 ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"] CMD ["node", "dist/index.js"]