build lebih ringan: cache npm + next, prioritas CPU rendah

This commit is contained in:
Gilang Aryo
2026-11-27 18:52:59 +07:00
parent 419cd4dcb5
commit 532473ff41
2 changed files with 16 additions and 8 deletions

View File

@@ -3,3 +3,4 @@ node_modules
.source
.git
*.log
README.md

View File

@@ -1,19 +1,26 @@
# ---------- Install & build ----------
# ---------- 1. Install dependencies (di-cache selama package.json tidak berubah) ----------
FROM node:22-alpine AS deps
WORKDIR /app
COPY package.json package-lock.json ./
RUN --mount=type=cache,target=/root/.npm \
npm ci --ignore-scripts && npm install --no-save --ignore-scripts sharp
# ---------- 2. Build (hanya bagian ini yang jalan saat artikel berubah) ----------
FROM node:22-alpine AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
# postinstall menjalankan `fumadocs-mdx` (butuh source.config.ts & content/)
RUN npm ci || npm install
# sharp untuk optimasi gambar Next.js (versi Linux/Alpine)
RUN npm install --no-save sharp
ENV NEXT_TELEMETRY_DISABLED=1
ARG SITE_URL
ENV SITE_URL=${SITE_URL}
RUN npm run build
# ---------- Runtime (image kecil) ----------
RUN npx fumadocs-mdx
# nice -n 19 = prioritas CPU paling rendah, supaya POS tetap lancar saat build
RUN --mount=type=cache,target=/app/.next/cache \
nice -n 19 npm run build
# ---------- 3. Runtime (image kecil) ----------
FROM node:22-alpine AS runner
WORKDIR /app