# Build context: repo root (docker compose sets context: .)
#
# cowork-service is a lightweight Fastify bridge (no Cosmos containers of its own).
# This Dockerfile mirrors services/mcp-server/Dockerfile but copies the full
# workspace in a single step rather than enumerating every package.json, which
# keeps it resilient to additions/removals of workspace members.
FROM node:22-alpine AS builder
RUN npm config set strict-ssl false \
  && npm install -g pnpm@10
WORKDIR /app

# Copy workspace config + lockfile for dependency resolution
COPY package.json pnpm-workspace.yaml pnpm-lock.yaml tsconfig.base.json ./

# Copy full workspace sources (dev-compose; not optimised for image size)
COPY packages/ packages/
COPY services/ services/
COPY dashboards/ dashboards/
COPY scripts/ scripts/

# Install workspace deps (no frozen lockfile — mirrors the repo's dev install flow)
RUN pnpm install --no-frozen-lockfile

# Build only cowork-service and its workspace dependencies
RUN pnpm -r --filter @lysnrai/cowork-service... build

# Deploy to isolated directory (production deps only)
RUN pnpm --filter @lysnrai/cowork-service deploy --legacy /app/deploy

# ── Production ─────────────────────────────────────────────
FROM node:22-alpine
WORKDIR /app
COPY --from=builder /app/deploy ./
ENV NODE_ENV=production
EXPOSE 4009
CMD ["node", "dist/server.js"]
