fixing dockerfile

This commit is contained in:
rheiga19 2025-03-26 22:49:54 +07:00
parent 193bb427d2
commit a8d825c573
1 changed files with 12 additions and 25 deletions

View File

@ -1,41 +1,28 @@
# Build stage FROM node:18-alpine AS builder
FROM node:20-alpine as build
# Set working directory
WORKDIR /app WORKDIR /app
# Tambahkan dependensi yang mungkin dibutuhkan # Copy package.json and package-lock.json
RUN apk add --no-cache python3 make g++ git COPY package.json package-lock.json ./
# Copy package files dan install dependencies # Install dependencies
COPY package.json package-lock.json* ./ RUN npm install
# Gunakan --legacy-peer-deps untuk mengatasi masalah kompatibilitas
RUN npm ci --legacy-peer-deps || npm install --legacy-peer-deps
# Copy kode aplikasi # Copy project files
COPY . . COPY . .
# Build aplikasi # Build the project
RUN npm run build RUN npm run build
# Production stage # Use Nginx for serving static files
FROM nginx:alpine FROM nginx:alpine
# Copy file hasil build ke nginx # Copy build files to Nginx html directory
COPY --from=build /app/dist /usr/share/nginx/html COPY --from=builder /app/dist /usr/share/nginx/html
# Buat konfigurasi nginx untuk SPA routing
RUN echo 'server { \
listen 80; \
server_name _; \
root /usr/share/nginx/html; \
index index.html; \
location / { \
try_files $uri $uri/ /index.html; \
} \
}' > /etc/nginx/conf.d/default.conf
# Expose port 80 # Expose port 80
EXPOSE 80 EXPOSE 80
# Start nginx # Start Nginx
CMD ["nginx", "-g", "daemon off;"] CMD ["nginx", "-g", "daemon off;"]