update dockerfile frontend for gitops

This commit is contained in:
Syifa 2025-10-22 14:04:02 +07:00
parent 7860305448
commit d63f7b6b1c
1 changed files with 12 additions and 14 deletions

View File

@ -1,35 +1,33 @@
# Gunakan base image yang lebih ringan
FROM node:18-alpine AS builder
# Set working directory
WORKDIR /app
# Copy package.json dan package-lock.json
# Copy package.json dan package-lock.json (kalau ada)
COPY package*.json ./
# Install dependencies (termasuk dev) di stage build
RUN npm ci
# Install dependencies (termasuk dev)
# Ganti npm ci -> npm install biar gak error kalau belum ada lock file
RUN npm install
# Copy semua source code
# Copy seluruh source code
COPY . .
# Build React app (kalau ini frontend)
# Build React app
RUN npm run build
# ---------------------------
# Stage 2: image produksi
# Stage 2: production image
# ---------------------------
FROM node:18-alpine
WORKDIR /app
# Hanya copy file hasil build dari stage sebelumnya
# Copy hasil build dari stage sebelumnya
COPY --from=builder /app/build ./build
COPY package*.json ./
# Install hanya dependency production
RUN npm ci --only=production && npm cache clean --force
# Install serve untuk menyajikan React app
RUN npm install -g serve && npm cache clean --force
# Ubah kepemilikan agar aman di Kubernetes
RUN chown -R node:node /app
@ -38,5 +36,5 @@ USER node
# Expose port
EXPOSE 3000
# Jalankan app (gunakan serve untuk app React, atau npm start kalau Node server)
CMD ["npx", "serve", "-s", "build"]
# Jalankan app React statis
CMD ["serve", "-s", "build"]