mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-20 13:32:00 +00:00
56 lines
1.7 KiB
Docker
56 lines
1.7 KiB
Docker
# ============================================================
|
|
# 🏗️ 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 ./
|
|
|
|
# Gunakan npm ci (lebih cepat, konsisten)
|
|
RUN npm ci --omit=dev
|
|
|
|
# Copy source code terakhir
|
|
COPY . .
|
|
|
|
# Buat config agar Next tahu mode static export
|
|
RUN echo "const config = { output: 'export', images: { unoptimized: true } }; export default config;" > next.config.mjs
|
|
|
|
# Build Next.js tanpa Turbopack, lalu hapus cache npm
|
|
ENV NEXT_DISABLE_TURBOPACK=1
|
|
RUN npx next build && npm cache clean --force
|
|
|
|
# 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/ || 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
|
|
|
|
# Jalankan lewat tini untuk handle signal & memory leak
|
|
ENTRYPOINT ["/sbin/tini", "--"]
|
|
|
|
CMD ["serve", "-s", "server", "-l", "3000"] |