elearning/Backend/Dockerfile

65 lines
1.4 KiB
Text
Raw Normal View History

2026-02-09 16:56:12 +07:00
# 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++
2026-02-09 16:56:12 +07:00
# 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
2026-02-09 16:56:12 +07:00
# 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++
2026-02-09 16:56:12 +07:00
# 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
2026-02-09 16:56:12 +07:00
# 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"]