# Shared build for the API and every agent worker — they're all plain Node
# processes in the same npm-workspaces monorepo. WORKSPACE picks which one
# actually runs at container start.
FROM node:20-slim AS build
WORKDIR /app

COPY package.json ./
COPY tsconfig.base.json ./
COPY packages ./packages
COPY apps ./apps

RUN npm install
RUN npm run build --workspaces --if-present

FROM node:20-slim
WORKDIR /app
ENV NODE_ENV=production
COPY --from=build /app ./

ARG WORKSPACE
ENV WORKSPACE=${WORKSPACE}
CMD ["sh", "-c", "node ${WORKSPACE}/dist/index.js"]
