41 lines
828 B
Docker
41 lines
828 B
Docker
# Gunakan base image yang lebih ringan
|
|
FROM node:18-alpine AS builder
|
|
|
|
WORKDIR /app
|
|
|
|
# Copy package.json dan package-lock.json (kalau ada)
|
|
COPY package*.json ./
|
|
|
|
# Install dependencies (termasuk dev)
|
|
# Ganti npm ci -> npm install biar gak error kalau belum ada lock file
|
|
RUN npm install
|
|
|
|
# Copy seluruh source code
|
|
COPY . .
|
|
|
|
# Build React app
|
|
RUN npm run build
|
|
|
|
# ---------------------------
|
|
# Stage 2: production image
|
|
# ---------------------------
|
|
FROM node:18-alpine
|
|
|
|
WORKDIR /app
|
|
|
|
# Copy hasil build dari stage sebelumnya
|
|
COPY --from=builder /app/build ./build
|
|
|
|
# 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
|
|
USER node
|
|
|
|
# Expose port
|
|
EXPOSE 3000
|
|
|
|
# Jalankan app React statis
|
|
CMD ["serve", "-s", "build"]
|