# Wild Dragon MAM — Worker Node Stack
# ─────────────────────────────────────
# Deploy on any machine you want to join the cluster as a worker.
# The primary stack (mam-api, db, redis) continues running on TrueNAS.
#
# Required env vars (set in .env.worker or export before running):
#   MAM_API_URL   URL of the primary MAM API  e.g. http://10.0.0.25:47432
#   NODE_TOKEN    Bearer token from the primary's Tokens page
#
# Optional env vars (needed only if starting the worker profile):
#   REDIS_URL, DATABASE_URL, S3_ENDPOINT, S3_BUCKET, S3_ACCESS_KEY, S3_SECRET_KEY
#
# Start node-agent only (cluster visibility + health):
#   docker compose -f docker-compose.worker.yml up -d
#
# Start node-agent + job worker (full processing node):
#   docker compose -f docker-compose.worker.yml --profile worker up -d

services:

  node-agent:
    build: ./services/node-agent
    restart: unless-stopped
    environment:
      MAM_API_URL:   ${MAM_API_URL}
      NODE_TOKEN:    ${NODE_TOKEN:-}
      NODE_ROLE:     ${NODE_ROLE:-worker}
      AGENT_PORT:    3002
      HEARTBEAT_MS:  ${HEARTBEAT_MS:-30000}
    ports:
      - "${AGENT_PORT:-7436}:3002"
    networks:
      - wild-dragon-worker

  worker:
    build: ./services/worker
    profiles: [worker]
    restart: unless-stopped
    environment:
      REDIS_URL:      ${REDIS_URL}
      DATABASE_URL:   ${DATABASE_URL}
      S3_ENDPOINT:    ${S3_ENDPOINT}
      S3_BUCKET:      ${S3_BUCKET}
      S3_ACCESS_KEY:  ${S3_ACCESS_KEY}
      S3_SECRET_KEY:  ${S3_SECRET_KEY}
      S3_REGION:      ${S3_REGION:-us-east-1}
    networks:
      - wild-dragon-worker

networks:
  wild-dragon-worker:
    driver: bridge
