name: agentteam

x-agentteam-server-env: &agentteam-server-env
  AGENTTEAM_ENV: development
  AGENTTEAM_LOG_LEVEL: debug
  AGENTTEAM_PUBLIC_BASE_URL: http://localhost:8080
  AGENTTEAM_DAEMON_CONNECT_BASE_URL: http://localhost:8080
  AGENTTEAM_HTTP_ADDRESS: :3001
  AGENTTEAM_DATABASE_DSN: root@tcp(tidb:4000)/agentteam?multiStatements=true&parseTime=true&loc=UTC
  MESHX_DATABASE_DSN: root@tcp(tidb:4000)/agentteam_meshx?multiStatements=true&parseTime=true&loc=UTC
  MESHX_AGS_DATABASE_DSN: root@tcp(tidb:4000)/agentteam_ags?multiStatements=true&parseTime=true&loc=UTC
  MESHX_AGS_GIT_REPO_DIR: /data/meshx/ags-repos
  MESHX_CONTENT_STORE_ENABLED: ${MESHX_CONTENT_STORE_ENABLED:-false}
  MESHX_CONTENT_STORE_FILESYSTEM_ROOT: /data/meshx/content-store
  AGENTTEAM_ARCHIVE_DRIVER: filesystem
  AGENTTEAM_ARCHIVE_FILESYSTEM_ROOT: /data/archive
  AGENTTEAM_MEDIA_OBJECT_STORAGE_DRIVER: disabled
  AGENTTEAM_MAIL_DRIVER: noop
  AGENTTEAM_MOBILE_VERIFY_DRIVER: noop
  AGENTTEAM_PASSWORD_AUTH_ENABLED: "true"
  AGENTTEAM_AUTH_REGISTRATION_MODE: open

x-agentteam-server-image: &agentteam-server-image
  image: agentteam-server:local
  build:
    context: .
    dockerfile: Dockerfile.server
    args:
      AGENTTEAM_SERVER_GIT_COMMIT: ${AGENTTEAM_SERVER_GIT_COMMIT:-}
      AGENTTEAM_SERVER_VERSION: ${AGENTTEAM_SERVER_VERSION:?set AGENTTEAM_SERVER_VERSION from git describe before building Docker images}

services:
  tidb:
    image: pingcap/tidb:v8.5.3
    command:
      - --store=unistore
      - --path=/tmp/tidb
      - --host=0.0.0.0
      - --status=10080
    volumes:
      - tidb-data:/tmp/tidb
    healthcheck:
      test: ["CMD-SHELL", "wget -q -O- http://127.0.0.1:10080/status >/dev/null 2>&1"]
      interval: 2s
      timeout: 3s
      retries: 60
      start_period: 10s

  schema:
    <<: *agentteam-server-image
    command: ["/app/bin/agentteam-schema", "init"]
    environment: *agentteam-server-env
    depends_on:
      tidb:
        condition: service_healthy
    volumes:
      - server-data:/data
    restart: "no"

  server:
    <<: *agentteam-server-image
    environment: *agentteam-server-env
    depends_on:
      tidb:
        condition: service_healthy
      schema:
        condition: service_completed_successfully
    volumes:
      - server-data:/data
    restart: unless-stopped

  web:
    image: agentteam-web:local
    build:
      context: .
      dockerfile: Dockerfile.web
    restart: unless-stopped

  ingress:
    image: nginx:1.27-alpine
    depends_on:
      server:
        condition: service_started
      web:
        condition: service_started
    ports:
      - "8080:80"
    volumes:
      - ./docker/nginx/agentteam-compose.conf:/etc/nginx/conf.d/default.conf:ro
    restart: unless-stopped

volumes:
  server-data:
  tidb-data:
