# Builder stage: install dependencies and build the monorepo using Bun
FROM node:lts-bookworm AS builder
WORKDIR /workspace
# Install system dependencies
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update -y \
&& apt-get install -y curl ca-certificates git build-essential python3 \
&& rm -rf /var/lib/apt/lists/*
# Copy repository (best effort for caching; the CI-like environment will have the full repo)
COPY . .
# Install Bun and dependencies
RUN curl -fsSL https://bun.sh/install | bash
ENV PATH="/root/.bun/bin:${PATH}"
# Install workspace dependencies
RUN bun install
# Typecheck the entire monorepo and build the app package
RUN bun turbo typecheck
RUN bun --cwd packages/app build
# Runtime stage: serve the built static site
FROM node:lts-bookworm
WORKDIR /app
# Copy the built assets from the builder stage
COPY --from=builder /workspace/packages/app/dist ./dist
# Install a tiny static file server to serve the built assets
RUN npm i -g serve
EXPOSE 8080
# Serve the prebuilt app on port 8080
CMD ["serve", "-s", "dist", "-l", "8080"]