FROM node:22.22.2-bookworm AS build

WORKDIR /app

COPY package.json package-lock.json ./
RUN npm ci --legacy-peer-deps

COPY . .
RUN npm run build:test-app

FROM node:22.22.2-bookworm AS runtime

WORKDIR /app

ENV NODE_ENV=production
ENV PORT=5173
ENV APP_DIST_DIR=/tmp/ai-code-test-app-dist
ENV WORK_SERVER_URL=http://host.docker.internal:3100
ENV VITE_DISABLE_APP_UPDATE=true

COPY package.json package-lock.json ./
RUN npm ci --omit=dev --legacy-peer-deps

COPY --from=build /app/scripts ./scripts
COPY --from=build /tmp/ai-code-test-app-dist /tmp/ai-code-test-app-dist

EXPOSE 5173

CMD ["npm", "run", "preview:test-app", "--", "--host", "0.0.0.0", "--port", "5173", "--strictPort"]
