build lebih ringan: cache npm + next, prioritas CPU rendah
This commit is contained in:
@@ -3,3 +3,4 @@ node_modules
|
||||
.source
|
||||
.git
|
||||
*.log
|
||||
README.md
|
||||
|
||||
23
Dockerfile
23
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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user