From 532473ff41975abedd3ff5a3c37266fb7fe9f532 Mon Sep 17 00:00:00 2001 From: Gilang Aryo Date: Fri, 27 Nov 2026 18:52:59 +0700 Subject: [PATCH] build lebih ringan: cache npm + next, prioritas CPU rendah --- .dockerignore | 1 + Dockerfile | 23 +++++++++++++++-------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/.dockerignore b/.dockerignore index e301876..f8c9bb8 100644 --- a/.dockerignore +++ b/.dockerignore @@ -3,3 +3,4 @@ node_modules .source .git *.log +README.md diff --git a/Dockerfile b/Dockerfile index 663dd4b..255cac2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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