# Frontend Dockerfile
FROM node:20 AS builder

WORKDIR /app

ARG VITE_BACKEND_URL
ARG VITE_STREAM_DELAY
ARG VITE_STREAM_PROXY_DELAY
ARG VITE_SYNCHRONIZATION_TOLERANCE
ARG VITE_SYNCHRONIZATION_MAX_DEVIATION
ARG VITE_SYNCHRONIZATION_ADJUSTMENT
ARG VITE_SYNCHRONIZATION_MAX_ADJUSTMENT

# Install dependencies
COPY package.json package-lock.json ./
RUN npm install

# Copy source code and build
COPY . .

ENV VITE_BACKEND_URL=$VITE_BACKEND_URL
ENV VITE_STREAM_DELAY=$VITE_STREAM_DELAY
ENV VITE_STREAM_PROXY_DELAY=$VITE_STREAM_PROXY_DELAY
ENV VITE_SYNCHRONIZATION_TOLERANCE=$VITE_SYNCHRONIZATION_TOLERANCE
ENV VITE_SYNCHRONIZATION_MAX_DEVIATION=$VITE_SYNCHRONIZATION_MAX_DEVIATION
ENV VITE_SYNCHRONIZATION_ADJUSTMENT=$VITE_SYNCHRONIZATION_ADJUSTMENT
ENV VITE_SYNCHRONIZATION_MAX_ADJUSTMENT=$VITE_SYNCHRONIZATION_MAX_ADJUSTMENT

RUN npm run build

# Serve the app using a minimal HTTP server
FROM nginx:alpine
COPY --from=builder /app/dist /usr/share/nginx/html

EXPOSE 80

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