elearning/Backend/Dockerfile
JakkrapartXD d2e78dcfbb
All checks were successful
Build and Deploy Backend / Build Backend Docker Image (push) Successful in 32s
Build and Deploy Frontend Learner / Build Frontend Learner Docker Image (push) Successful in 34s
Build and Deploy Backend / Deploy E-learning Backend to Dev Server (push) Successful in 3s
Build and Deploy Frontend Learner / Deploy E-learning Frontend Learner to Dev Server (push) Successful in 2s
Build and Deploy Backend / Notify Deployment Status (push) Successful in 2s
Build and Deploy Frontend Learner / Notify Deployment Status (push) Successful in 2s
feat: Implement local backend development setup with Docker Compose, introduce .dockerignore, and remove dev dependency pruning from the Dockerfile.
2026-02-10 14:26:09 +07:00

64 lines
1.4 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
# 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"]