# Stage 1: Build frontend
FROM node:20-alpine AS builder
WORKDIR /build
COPY frontend/package*.json ./
RUN npm ci
COPY frontend/ .
RUN npm run build

# Stage 2: Nginx with bundled frontend
FROM nginx:alpine

COPY infrastructure/nginx/nginx.conf /etc/nginx/nginx.conf

# Copy prebuilt frontend from builder stage
COPY --from=builder /build/dist/ /srv/frontend/

# Create HLS directory
RUN mkdir -p /srv/hls

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