update docker frontend for gitops

This commit is contained in:
Syifa 2025-10-22 13:58:36 +07:00
parent 69d55ddc6a
commit 7860305448
2 changed files with 31 additions and 9 deletions

View File

@ -1,4 +1,7 @@
node_modules node_modules
npm-debug.log
Dockerfile
.dockerignore
.git .git
.gitignore .gitignore
Dockerfile README.md

View File

@ -1,23 +1,42 @@
FROM node:18-alpine # Gunakan base image yang lebih ringan
FROM node:18-alpine AS builder
# Set working directory # Set working directory
WORKDIR /app WORKDIR /app
# Copy package.json & package-lock.json (kalau ada) # Copy package.json dan package-lock.json
COPY package*.json ./ COPY package*.json ./
# Install dependencies production-only # Install dependencies (termasuk dev) di stage build
RUN npm install --only=production RUN npm ci
# Copy source code # Copy semua source code
COPY . . COPY . .
# Build React app (kalau ini frontend)
RUN npm run build
# ---------------------------
# Stage 2: image produksi
# ---------------------------
FROM node:18-alpine
WORKDIR /app
# Hanya copy file 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
# Ubah kepemilikan agar aman di Kubernetes # Ubah kepemilikan agar aman di Kubernetes
RUN chown -R node:node /app RUN chown -R node:node /app
USER node USER node
# Expose port 3000 # Expose port
EXPOSE 3000 EXPOSE 3000
# Jalankan app # Jalankan app (gunakan serve untuk app React, atau npm start kalau Node server)
CMD ["npm", "start"] CMD ["npx", "serve", "-s", "build"]