- Add build dependencies (python3, make, g++) to both builder and production stages - Use --ignore-scripts=false flag to ensure native modules compile - Fixes MODULE_NOT_FOUND error for bcrypt_lib.node
67 lines
1.5 KiB
Docker
67 lines
1.5 KiB
Docker
# Build stage
|
|
FROM node:20-alpine AS builder
|
|
|
|
WORKDIR /app
|
|
|
|
# Install build dependencies for native modules (bcrypt, prisma)
|
|
RUN apk add --no-cache python3 make g++
|
|
|
|
# Copy package files
|
|
COPY package*.json ./
|
|
COPY pnpm-lock.yaml* ./
|
|
|
|
# Install pnpm and dependencies with build scripts enabled
|
|
RUN npm install -g pnpm && \
|
|
pnpm install --frozen-lockfile --ignore-scripts=false
|
|
|
|
# Copy source code
|
|
COPY . .
|
|
|
|
# Generate Prisma client
|
|
RUN pnpm prisma:generate
|
|
|
|
# Build application
|
|
RUN pnpm build
|
|
|
|
# Production stage
|
|
FROM node:20-alpine AS production
|
|
|
|
WORKDIR /app
|
|
|
|
# Install build dependencies for native modules (bcrypt, prisma)
|
|
RUN apk add --no-cache python3 make g++
|
|
|
|
# Install pnpm
|
|
RUN npm install -g pnpm
|
|
|
|
# Copy package files
|
|
COPY package*.json ./
|
|
COPY pnpm-lock.yaml* ./
|
|
|
|
# Install production dependencies with build scripts enabled
|
|
RUN pnpm install --frozen-lockfile --ignore-scripts=false
|
|
|
|
# Copy prisma schema and generate client
|
|
COPY --from=builder /app/prisma ./prisma
|
|
RUN pnpm prisma:generate
|
|
|
|
# Remove devDependencies (keep bcrypt and prisma client)
|
|
RUN pnpm prune --prod
|
|
|
|
# Copy built files from builder
|
|
COPY --from=builder /app/dist ./dist
|
|
COPY --from=builder /app/public ./public
|
|
|
|
# Set environment
|
|
ENV NODE_ENV=production
|
|
ENV PORT=4000
|
|
|
|
# Expose port
|
|
EXPOSE 4000
|
|
|
|
# Health check
|
|
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
|
|
CMD wget --no-verbose --tries=1 --spider http://localhost:4000/health || exit 1
|
|
|
|
# Start application
|
|
CMD ["node", "dist/server.js"]
|