# syntax=docker/dockerfile:1
# Generator worker (BullMQ). Renders generated MCP servers, builds their Docker
# images and runs them as sibling containers on the host daemon.
# Build context must be the repo root: docker build -f apps/generator/Dockerfile .

FROM node:20-alpine AS base
RUN corepack enable && corepack prepare pnpm@9.12.0 --activate
WORKDIR /app

# ---- deps ----
FROM base AS deps
COPY pnpm-lock.yaml pnpm-workspace.yaml package.json ./
COPY apps/api/package.json apps/api/
COPY apps/web/package.json apps/web/
COPY apps/generator/package.json apps/generator/
COPY apps/runner-template/package.json apps/runner-template/
COPY packages/auth/package.json packages/auth/
COPY packages/db/package.json packages/db/
COPY packages/llm/package.json packages/llm/
COPY packages/types/package.json packages/types/
RUN pnpm install --frozen-lockfile

# ---- runtime ----
FROM deps AS runtime
# docker CLI: the worker shells out to `docker build` / `docker run` against the
# host daemon (socket mounted in compose). apps/runner-template is copied below
# and used as the build context template for every generated server.
RUN apk add --no-cache docker-cli
ENV NODE_ENV=production
COPY . .
# build-context is a mounted volume at runtime; create the dir so the path exists.
RUN mkdir -p /app/build-context
WORKDIR /app/apps/generator
CMD ["pnpm", "start"]
