# Multi-stage: Vite production build runs during `docker build` / `docker compose build` —
# no `npm run build` on the host first. The final image is nginx + freshly built `dist/`.
#
# Unity still exports into Needle/<app>/assets/ on your machine; include that folder in the
# build context when it exists (it is not listed in .dockerignore). Clones without `assets/`
# need a Unity export (or committed assets) before the image can bundle a valid scene.

ARG NEEDLE_APP=MenuScene

FROM node:22 AS builder
ARG NEEDLE_APP
WORKDIR /src

COPY Needle/${NEEDLE_APP}/package.json Needle/${NEEDLE_APP}/package-lock.json ./
RUN rm package-lock.json && npm install

COPY Needle/${NEEDLE_APP}/ ./
RUN npm run build

FROM nginx:1.27-alpine

ARG NEEDLE_APP
COPY --from=builder /src/dist /usr/share/nginx/html
COPY docker/nginx-default.conf /etc/nginx/conf.d/default.conf

EXPOSE 80

HEALTHCHECK --interval=30s --timeout=5s --start-period=5s --retries=3 \
  CMD wget -q -O /dev/null http://127.0.0.1/ || exit 1
