update dockerfile frontend for gitops
This commit is contained in:
parent
7860305448
commit
d63f7b6b1c
|
|
@ -1,35 +1,33 @@
|
||||||
# Gunakan base image yang lebih ringan
|
# Gunakan base image yang lebih ringan
|
||||||
FROM node:18-alpine AS builder
|
FROM node:18-alpine AS builder
|
||||||
|
|
||||||
# Set working directory
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# Copy package.json dan package-lock.json
|
# Copy package.json dan package-lock.json (kalau ada)
|
||||||
COPY package*.json ./
|
COPY package*.json ./
|
||||||
|
|
||||||
# Install dependencies (termasuk dev) di stage build
|
# Install dependencies (termasuk dev)
|
||||||
RUN npm ci
|
# 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 . .
|
COPY . .
|
||||||
|
|
||||||
# Build React app (kalau ini frontend)
|
# Build React app
|
||||||
RUN npm run build
|
RUN npm run build
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------
|
# ---------------------------
|
||||||
# Stage 2: image produksi
|
# Stage 2: production image
|
||||||
# ---------------------------
|
# ---------------------------
|
||||||
FROM node:18-alpine
|
FROM node:18-alpine
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# Hanya copy file hasil build dari stage sebelumnya
|
# Copy hasil build dari stage sebelumnya
|
||||||
COPY --from=builder /app/build ./build
|
COPY --from=builder /app/build ./build
|
||||||
COPY package*.json ./
|
|
||||||
|
|
||||||
# Install hanya dependency production
|
# Install serve untuk menyajikan React app
|
||||||
RUN npm ci --only=production && npm cache clean --force
|
RUN npm install -g serve && npm cache clean --force
|
||||||
|
|
||||||
# Ubah kepemilikan agar aman di Kubernetes
|
# Ubah kepemilikan agar aman di Kubernetes
|
||||||
RUN chown -R node:node /app
|
RUN chown -R node:node /app
|
||||||
|
|
@ -38,5 +36,5 @@ USER node
|
||||||
# Expose port
|
# Expose port
|
||||||
EXPOSE 3000
|
EXPOSE 3000
|
||||||
|
|
||||||
# Jalankan app (gunakan serve untuk app React, atau npm start kalau Node server)
|
# Jalankan app React statis
|
||||||
CMD ["npx", "serve", "-s", "build"]
|
CMD ["serve", "-s", "build"]
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue