update dockerfile next js file only temporarily

This commit is contained in:
Syifa 2025-11-28 14:56:24 +07:00
parent e97a42a753
commit 7dbbe6dc0f
1 changed files with 24 additions and 10 deletions

View File

@ -1,27 +1,41 @@
# Build Stage
# ---------- BUILD STAGE ----------
FROM node:20 AS builder
WORKDIR /app
# Copy only package files first
COPY package*.json ./
# Install ALL deps (dev + prod)
RUN npm install
# Copy source code
COPY . .
# Build Next.js
RUN npm run build
# Production Stage - HANYA FILE BUILD STATIC
FROM node:20-alpine
# Remove devDependencies, keep only production deps
RUN npm prune --omit=dev
# ---------- PRODUCTION STAGE ----------
FROM node:20-alpine AS runner
WORKDIR /app
ENV NODE_ENV=production
# install dependencies production only
COPY package*.json ./
RUN npm install --omit=dev
# Copy production deps only
COPY --from=builder /app/node_modules ./node_modules
# copy hasil build
COPY --from=builder /app/build ./build
# atau untuk Next.js: COPY --from=builder /app/.next ./ .next
# Copy minimal runtime files
COPY --from=builder /app/package*.json ./
COPY --from=builder /app/.next ./.next
COPY --from=builder /app/next.config.ts ./next.config.ts
# Ownership fix (optional but recommended)
RUN chown -R node:node /app
# Switch to built-in non-root user
USER node
EXPOSE 3000
CMD ["npm", "start"]
CMD ["npm", "start"]