Files
waggle-os/Dockerfile
shumeiko.it c25efe6c44 refactor(server): move the team runtime into a postponed package (P1.1)
Team mode stays in the repository but is not built or shipped (ADR-0003).

- The team server (index.ts, config, db, daemons, plugins, proactive,
  routes, scheduler, services, ws, drizzle migrations) and its tests move
  from @waggle/server to packages/team-server (@waggle/team-server,
  private). It keeps its own copies of the logger and the agent-group
  executor, so it does not import @waggle/server. @clerk/fastify, bullmq,
  ioredis, postgres, drizzle-orm, drizzle-kit, cron-parser and
  @waggle/waggle-dance leave @waggle/server; the launcher drops the same
  team-only dependencies.
- build:packages no longer builds waggle-dance or the worker: nothing in
  the community edition imports them, and the worker's project reference
  would otherwise build the team server. The worker now imports from
  team-server; the team Dockerfile builds both explicitly.
- The sidecar no longer starts the team server when DATABASE_URL is set,
  and loses the team routes (/api/team/*, /api/teams), the WaggleDance
  routes and bridge (/api/waggle-dance/*), the Team server binding and
  egress guard, the WebSocket team client, the TeamSync cache and pushes,
  team audit forwarding, team workspace registration and the team
  capability-policy lookup in chat. The in-process room signal bus stays:
  agent groups, fleet runs and external tool runs use it.
  middleware/audit.ts was dead and is deleted.
- @waggle/core loses TeamSync and the teamServer part of WaggleConfig. A
  teamServer key in config.json is ignored and kept on save, as P0.1 does
  for the tier keys. Workspaces lose teamServerUrl and teamUserId; teamId
  and teamRole stay because workspaces from a shared data directory still
  carry them and the viewer write guards read them. POST /api/workspaces
  ignores team fields.
- The sidecar bundle no longer marks the team packages as external.

The agent still references the TeamSync type in orchestrator.ts and
pattern-write-back.ts; those files are being rewritten in P1.5 and drop
it there.

Logs UF-030 and UF-031 (team sync and team policy defects found while
removing the code).
2026-10-24 12:17:41 +02:00

101 lines
4.0 KiB
Docker

# Waggle Teams Server — Production Docker Image
# Multi-stage build: install deps + build packages & frontend, then run the
# team server (packages/team-server/src/index.ts → Postgres/Redis/MinIO/Clerk).
#
# Consumed by docker-compose.production.yml. NOTE: render.yaml deploys the
# SQLite *sidecar* (local/start.ts) instead — a different hosting mode.
FROM node:20-alpine AS builder
WORKDIR /app
# Copy the full workspace before install. The monorepo has 27 workspaces
# (packages/* + apps/*); a hand-maintained COPY list drifts (it had referenced
# the nonexistent packages/ui and omitted every hive-mind-* package), so copy
# wholesale for correctness. Trades some layer-cache granularity for not
# silently breaking when a workspace is added.
COPY package.json package-lock.json* ./
COPY packages packages
COPY apps apps
COPY tsconfig*.json ./
COPY vitest*.ts ./
# Install all dependencies (incl. dev — needed to build). --ignore-scripts
# skips native rebuilds here (the build only typechecks + bundles); native
# modules are rebuilt in the native-builder stage below.
RUN npm install --ignore-scripts 2>/dev/null || npm install
# Build workspace packages THEN the web UI.
# build:all → build:packages (hive-mind-core → shared → core → agent → server)
# then the apps/web Vite build to root /dist. @waggle/hive-mind-core emits its
# dist/ here; @waggle/core imports it as dist/ at runtime, so this is required.
RUN npm run build:all
# Team mode is left out of build:packages (ADR-0003); build what this image runs.
RUN cd packages/waggle-dance && npx tsc --build --force && cd ../worker && npm run build
# ── Native module build stage ───────────────────────────────────
FROM node:20-alpine AS native-builder
WORKDIR /app
# Install native build dependencies (only needed here)
RUN apk add --no-cache python3 make g++
# Workspace manifests for production install + native rebuild
COPY package.json package-lock.json* ./
COPY packages packages
COPY apps apps
# Production-only dependencies, then rebuild native modules (better-sqlite3)
RUN npm install --omit=dev --ignore-scripts 2>/dev/null || npm install --omit=dev
RUN npm rebuild better-sqlite3 2>/dev/null || true
# ── Production image (no build tools) ──────────────────────────
FROM node:20-alpine
WORKDIR /app
# Production node_modules (native rebuilt) + root manifest. The @waggle/*
# entries here are workspace symlinks into ./packages, satisfied below.
COPY --from=native-builder /app/node_modules node_modules
COPY --from=native-builder /app/package.json package.json
# Built workspace packages from the builder — carries emitted dist/ alongside
# src, so @waggle/hive-mind-core/dist (a runtime dep of @waggle/core) is present.
# (The old Dockerfile copied source packages from the build context here, which
# dropped every freshly-built dist/ and broke runtime module resolution.)
COPY --from=builder /app/packages packages
# Built web UI → /app/dist (root dist is canonical since the Apr-12 migration)
COPY --from=builder /app/dist dist
# Create data directory and non-root user
RUN mkdir -p /data \
&& addgroup -S waggle && adduser -S waggle -G waggle \
&& chown -R waggle:waggle /app /data
# Set environment
ENV NODE_ENV=production
ENV WAGGLE_FRONTEND_DIR=/app/dist
ENV WAGGLE_DATA_DIR=/data
# The sidecar defaults to loopback (desktop-safe). A container must accept
# traffic from outside, so opt into binding all interfaces here.
ENV WAGGLE_HOST=0.0.0.0
# Expose server port
EXPOSE 3333
# Health check
HEALTHCHECK --interval=30s --timeout=5s --retries=3 \
CMD wget -q --spider http://localhost:3333/health || exit 1
# Data volume for persistence
VOLUME ["/data"]
# Run as non-root user
USER waggle
# Run drizzle migrations (cwd packages/team-server so migrate.ts's './drizzle'
# resolves), then start the team server. docker-compose can override this.
CMD ["sh", "-c", "(cd packages/team-server && npx tsx src/db/migrate.ts) && npx tsx packages/team-server/src/index.ts"]