services:
  server:
    build:
      context: server
    ports:
      - 1250:1250
    volumes:
      - ./server/:/app/
      - /app/.venv
    env_file:
      - ./server/.env
    environment:
      ENTRYPOINT: server

  worker:
    build:
      context: server
    volumes:
      - ./server/:/app/
      - /app/.venv
    env_file:
      - ./server/.env
    environment:
      ENTRYPOINT: worker

  beat:
    build:
      context: server
    volumes:
      - ./server/:/app/
      - /app/.venv
    env_file:
      - ./server/.env
    environment:
      ENTRYPOINT: beat

  hatchet-worker-cpu:
    build:
      context: server
    volumes:
      - ./server/:/app/
      - /app/.venv
    env_file:
      - ./server/.env
    environment:
      ENTRYPOINT: hatchet-worker-cpu
    depends_on:
      hatchet:
        condition: service_healthy
  hatchet-worker-llm:
    build:
      context: server
    volumes:
      - ./server/:/app/
      - /app/.venv
    env_file:
      - ./server/.env
    environment:
      ENTRYPOINT: hatchet-worker-llm
    depends_on:
      hatchet:
        condition: service_healthy

  redis:
    image: redis:7.2
    ports:
      - 6379:6379
  web:
    image: node:22-alpine
    ports:
      - "3000:3000"
    command: sh -c "corepack enable && pnpm install && pnpm dev"
    restart: unless-stopped
    working_dir: /app
    volumes:
      - ./www:/app/
      - /app/node_modules
    env_file:
      - ./www/.env.local
    environment:
      - NODE_ENV=development

  postgres:
    image: postgres:17
    command: postgres -c 'max_connections=200'
    ports:
      - 5432:5432
    environment:
      POSTGRES_USER: reflector
      POSTGRES_PASSWORD: reflector
      POSTGRES_DB: reflector
    volumes:
      - ./data/postgres:/var/lib/postgresql/data
      - ./server/docker/init-hatchet-db.sql:/docker-entrypoint-initdb.d/init-hatchet-db.sql:ro
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -d reflector -U reflector"]
      interval: 10s
      timeout: 10s
      retries: 5
      start_period: 10s

  hatchet:
    image: ghcr.io/hatchet-dev/hatchet/hatchet-lite:latest
    ports:
      - "8889:8888"
      - "7078:7077"
    depends_on:
      postgres:
        condition: service_healthy
    environment:
      DATABASE_URL: "postgresql://reflector:reflector@postgres:5432/hatchet?sslmode=disable"
      SERVER_AUTH_COOKIE_DOMAIN: localhost
      SERVER_AUTH_COOKIE_INSECURE: "t"
      SERVER_GRPC_BIND_ADDRESS: "0.0.0.0"
      SERVER_GRPC_INSECURE: "t"
      SERVER_GRPC_BROADCAST_ADDRESS: hatchet:7077
      SERVER_GRPC_PORT: "7077"
      SERVER_URL: http://localhost:8889
      SERVER_AUTH_SET_EMAIL_VERIFIED: "t"
      # SERVER_DEFAULT_ENGINE_VERSION: "V1"  # default
      SERVER_INTERNAL_CLIENT_INTERNAL_GRPC_BROADCAST_ADDRESS: hatchet:7077
    volumes:
      - ./data/hatchet-config:/config
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:8888/api/live"]
      interval: 30s
      timeout: 10s
      retries: 5
      start_period: 30s

networks:
  default:
    attachable: true
