# The hub's website as a standalone Next.js server. Build from the repository root (the app uses the workspace's
# packages for the API's types):
#
#   docker build -f apps/web/Dockerfile --build-arg API_URL=http://api:4101 -t t5de-hub-web .
#   docker run -p 4100:4100 -e API_URL=http://api:4101 t5de-hub-web
#
# API_URL is needed at build time too: Next fixes the /api rewrite when it builds.

FROM oven/bun:1.4.4 AS bun

FROM node:26-slim AS build
COPY --from=bun /usr/local/bin/bun /usr/local/bin/bun
WORKDIR /repo
ENV NEXT_TELEMETRY_DISABLED=1
# Dependencies first, so they're cached while only source changes.
COPY package.json bun.lock ./
COPY apps/web/package.json apps/web/
COPY apps/api/package.json apps/api/
COPY packages/db/package.json packages/db/
RUN bun install --frozen-lockfile
COPY packages/db packages/db
COPY apps/api apps/api
COPY apps/web apps/web
ARG API_URL=http://api:4101
ENV API_URL=$API_URL
RUN cd apps/web && bun run build

FROM node:26-slim
WORKDIR /app
ENV NODE_ENV=production NEXT_TELEMETRY_DISABLED=1 PORT=4100 HOSTNAME=0.0.0.0
ARG API_URL=http://api:4101
ENV API_URL=$API_URL
COPY --from=build --chown=node:node /repo/apps/web/.next/standalone ./
COPY --from=build --chown=node:node /repo/apps/web/.next/static ./apps/web/.next/static
USER node
EXPOSE 4100
CMD ["node", "apps/web/server.js"]
