build with tag docker

This commit is contained in:
GitLab Deploy Bot
2025-11-09 14:44:58 +07:00
parent 8a11c176aa
commit 52e8fb4a3b
2 changed files with 77 additions and 52 deletions
+40 -8
View File
@@ -1,24 +1,56 @@
FROM node:20-alpine
# ============================================================
# 🏗️ Stage 1 — Builder
# ============================================================
FROM node:20-alpine AS builder
# Install hanya yang diperlukan untuk build
RUN apk add --no-cache git bash build-base curl
WORKDIR /app
# Copy dependency list terlebih dahulu agar cache efektif
COPY package*.json ./
RUN npm ci
# Gunakan npm ci (lebih cepat, konsisten)
RUN npm ci --omit=dev
# Copy source code terakhir
COPY . .
# Buat config agar Next tahu output: export
# Buat config agar Next tahu mode static export
RUN echo "const config = { output: 'export', images: { unoptimized: true } }; export default config;" > next.config.mjs
# Build project (Next.js 15 otomatis static export)
RUN NEXT_DISABLE_TURBOPACK=1 npx next build
# Build Next.js tanpa Turbopack, lalu hapus cache npm
ENV NEXT_DISABLE_TURBOPACK=1
RUN npx next build && npm cache clean --force
# Pastikan folder static tersedia untuk URL _next/static
# Tambahkan cache folder _next agar bisa dilayani oleh server
RUN mkdir -p .next/server/app/_next && \
cp -r .next/static .next/server/app/_next/static && \
cp -r public/assets .next/server/app/
cp -r public/assets .next/server/app/ || true
# ============================================================
# 🧱 Stage 2 — Runtime (super ringan)
# ============================================================
FROM node:20-alpine AS runtime
# Install hanya 1 dependency ringan untuk serving static file
RUN npm install -g serve && apk add --no-cache tini
WORKDIR /app
# Copy hasil build dari stage sebelumnya
COPY --from=builder /app/.next/server/app ./server
COPY --from=builder /app/.next/server/app/_next ./server/_next
COPY --from=builder /app/public ./public
# Set environment minimal
ENV NODE_ENV=production
ENV PORT=3000
EXPOSE 3000
CMD ["npx", "serve", ".next/server/app", "-l", "3000"]
# Jalankan lewat tini untuk handle signal & memory leak
ENTRYPOINT ["/sbin/tini", "--"]
CMD ["serve", "-s", "server", "-l", "3000"]