volumes:
  postgres_data:
  rustfs_data:
  redis_data:

services:
  db:
    image: postgres:18.1-trixie
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgres
      POSTGRES_DB: intentkit
    volumes:
      - postgres_data:/var/lib/postgresql
    ports:
      - "15432:5432"
    restart: unless-stopped
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U postgres"]
      interval: 5s
      timeout: 5s
      retries: 5

  rustfs:
    image: rustfs/rustfs:latest
    ports:
      - "9000:9000"
      - "9001:9001"
    environment:
      - RUSTFS_ACCESS_KEY=minioadmin
      - RUSTFS_SECRET_KEY=minioadmin
      - RUSTFS_CONSOLE_ENABLE=true
    volumes:
      - rustfs_data:/data
    restart: unless-stopped
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:9000/health"]
      interval: 30s
      timeout: 20s
      retries: 3

  redis:
    image: redis:8.4-bookworm
    volumes:
      - redis_data:/data
    restart: unless-stopped
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 5s
      timeout: 5s
      retries: 5

  team-api:
    build:
      context: ../../../
      args:
        - RELEASE=${RELEASE:-latest}
    volumes:
      - ../../../.env:/app/.env
      - ../../../intentkit:/app/intentkit
      - ../../../app:/app/app
      - ../../../public_agents:/app/public_agents
    depends_on:
      db:
        condition: service_healthy
      redis:
        condition: service_healthy
    environment:
      - DB_USERNAME=postgres
      - DB_PASSWORD=postgres
      - DB_HOST=db
      - DB_PORT=5432
      - DB_NAME=intentkit
      - REDIS_HOST=redis
      - REDIS_PORT=6379
      - REDIS_DB=0
      - AWS_S3_CDN_URL=http://localhost:9000/static
      - AWS_S3_ENDPOINT_URL=http://rustfs:9000
      - AWS_S3_ACCESS_KEY_ID=minioadmin
      - AWS_S3_SECRET_ACCESS_KEY=minioadmin
      - AWS_S3_BUCKET=static
      - AWS_S3_REGION_NAME=us-east-1
    ports:
      - "8000:8000"
    healthcheck:
      test:
        [
          "CMD",
          "python",
          "-c",
          "import requests; requests.get('http://localhost:8000/health').raise_for_status()",
        ]
      interval: 5s
      timeout: 5s
      retries: 5
    restart: unless-stopped
    command: uvicorn app.team.api:app --host 0.0.0.0 --port 8000 --reload
