# Containerfile for Dashboard
# Multi-stage build: Node Build -> Nginx Serve

# Stage 1: Build
FROM docker.io/library/node:22-alpine as builder
WORKDIR /app
COPY package*.json ./
RUN npm config set registry https://registry.npmmirror.com && \
    npm config set maxsockets 1 && \
    npm install --network-timeout=1000000 --fetch-retries=10 --no-audit --no-fund
COPY . .
RUN npm run build

# Stage 2: Serve
FROM docker.io/library/nginx:alpine
COPY --from=builder /app/dist /usr/share/nginx/html
# Copy custom nginx config if we needed SPA routing support (try_files $uri /index.html)
# Let's create a simple config on the fly or rely on default?
# React Router needs /index.html fallbacks.
RUN echo 'server { \
    listen 80; \
    location / { \
    root /usr/share/nginx/html; \
    index index.html index.htm; \
    try_files $uri $uri/ /index.html; \
    add_header Cache-Control "no-store, no-cache, must-revalidate"; \
    } \
    }' > /etc/nginx/conf.d/default.conf

EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
