FROM node:22-alpine AS build
WORKDIR /src
COPY package.json package-lock.json ./
RUN npm ci
COPY . .

# Vite substitutes import.meta.env.VITE_* at build time — these must be
# build arguments, not runtime environment variables.
ARG VITE_API_URL
ARG VITE_SHOW_OPS=false
ENV VITE_API_URL=$VITE_API_URL
ENV VITE_SHOW_OPS=$VITE_SHOW_OPS
RUN npm run build

FROM nginx:1.27-alpine AS runtime
COPY --from=build /src/dist /usr/share/nginx/html
COPY nginx.conf /etc/nginx/conf.d/default.conf
EXPOSE 80

HEALTHCHECK --interval=30s --timeout=3s --retries=3 \
  CMD wget -qO- http://localhost/ >/dev/null || exit 1