# aiw-voice-app: React SPA built with Vite, served by nginx as static files.
# Multi-stage so the runtime image carries no node_modules.
#
# Build args:
#   VITE_MODE   "production" (default, prod build) or "staging" (dev-domain build)
#               Vite picks .env.<mode> automatically - see aiw-voice-app/.env.* files.

FROM node:20-alpine AS builder
WORKDIR /app

# Copy manifests first so dependency install caches independently of source.
COPY package*.json ./
RUN npm ci

COPY . .

ARG VITE_MODE=production
RUN npm run build -- --mode "$VITE_MODE"

# ---- Runtime: nginx serving the static SPA bundle ----
FROM nginx:alpine
WORKDIR /usr/share/nginx/html

# Replace nginx default site with our SPA-aware config (BrowserRouter fallback).
COPY nginx.conf /etc/nginx/conf.d/default.conf

# Copy built static assets.
COPY --from=builder /app/dist ./

EXPOSE 80
# nginx:alpine already runs `nginx -g 'daemon off;'` as CMD - no override needed.
