This commit is contained in:
anhduy-tech
2026-05-18 11:45:21 +07:00
parent 4edb2ff22b
commit 1283757903
7 changed files with 14 additions and 52 deletions

View File

@@ -1,31 +1,33 @@
# --- STAGE 1: Build (Môi trường build) ---
FROM node:20-alpine AS builder
WORKDIR /app
# Copy các file cấu hình dependency
# Tăng memory limit ngay từ đầu
ENV NODE_OPTIONS="--max-old-space-size=8192"
# Copy package files trước
COPY package*.json ./
# Cài đặt mọi thư viện (bao gồm cả devDependencies để build)
# Cài dependencies
RUN npm ci --legacy-peer-deps
# Copy toàn bộ source code và build dự án
# Copy source code
COPY . .
# Build với memory limit rõ ràng
RUN npm run build
# --- STAGE 2---
# --- STAGE 2: Production ---
FROM node:20-alpine AS runner
WORKDIR /app
# Thiết lập môi trường Production
ENV NODE_ENV=production
ENV NODE_OPTIONS="--max-old-space-size=2048"
# 1. Cài đặt PM2 toàn cục và dọn dẹp cache của npm ngay lập tức
# Cài PM2
RUN npm install pm2 -g && npm cache clean --force
# 2. Chỉ copy những file cần thiết nhất từ stage builder
# Nuxt 3/Nitro đã đóng gói mọi node_modules cần thiết vào .output
# Copy những file cần thiết từ builder
COPY --from=builder /app/.output ./.output
COPY --from=builder /app/ecosystem.config.cjs ./
COPY --from=builder /app/package*.json ./