FROM node:22-alpine AS builder
RUN corepack enable
WORKDIR /app
COPY . .
RUN pnpm install --frozen-lockfile
RUN pnpm --filter frontend build
RUN pnpm --filter proxy build

FROM node:22-alpine
RUN corepack enable && apk add --no-cache nginx
WORKDIR /app
COPY --from=builder /app/frontend/build ./frontend/build
COPY --from=builder /app/proxy/dist ./proxy/dist
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/pnpm-lock.yaml ./
COPY docker/nginx.conf /etc/nginx/http.d/default.conf
COPY docker/entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
ENV FRONTEND_PORT=2080
ENV PROXY_PORT=3456
EXPOSE 3001
CMD ["/entrypoint.sh"]
