# Build the frontend SPA, then serve it (and proxy /api) from Caddy.
# Build context is the repo root so we can pull the workspace lockfile and frontend/.

FROM oven/bun:1-alpine AS frontend-build

WORKDIR /app

COPY package.json bun.lock ./
COPY backend/package.json ./backend/
COPY frontend/package.json ./frontend/
RUN bun install --frozen-lockfile --filter frontend

COPY frontend/ ./frontend/

WORKDIR /app/frontend
RUN bun run build

FROM caddy:2-alpine

COPY caddy/Caddyfile /etc/caddy/Caddyfile
COPY --from=frontend-build /app/frontend/dist /srv

EXPOSE 80
