services:
  surface-smoke:
    build:
      context: .
      dockerfile: Dockerfile
      target: production
      args:
        LAMBDA_AGENT_API_REF: ${LAMBDA_AGENT_API_REF:-master}
    environment:
      PYTHONUNBUFFERED: "1"
      SMOKE_TIMEOUT: ${SMOKE_TIMEOUT:-5}
    volumes:
      - agents:/agents
      - ./config:/app/config:ro
    depends_on:
      agent-proxy:
        condition: service_healthy
    command: >
      sh -lc "
        python -m tools.check_matrix_agents --config /app/config/matrix-agents.smoke.yaml --timeout ${SMOKE_TIMEOUT:-5}
      "

  agent-proxy:
    image: nginx:1.27-alpine
    volumes:
      - ./docker/nginx/smoke-agents.conf:/etc/nginx/nginx.conf:ro
    healthcheck:
      test:
        - CMD-SHELL
        - nc -z 127.0.0.1 7000
      interval: 2s
      timeout: 2s
      retries: 15
      start_period: 2s
    depends_on:
      agent-0:
        condition: service_healthy
      agent-1:
        condition: service_healthy
    ports:
      - "${SMOKE_PROXY_PORT:-7000}:7000"

  agent-0:
    build:
      context: ./external/platform-agent
      target: development
      additional_contexts:
        agent_api: ./external/platform-agent_api
    environment:
      PYTHONUNBUFFERED: "1"
      AGENT_ID: ${AGENT_0_ID:-agent-0}
      PROVIDER_MODEL: ${PROVIDER_MODEL:-debug-model}
      PROVIDER_URL: ${PROVIDER_URL:-http://provider.invalid/v1}
      PROVIDER_API_KEY: ${PROVIDER_API_KEY:-debug-key}
    volumes:
      - ./external/platform-agent/src:/app/src
      - ./external/platform-agent_api:/agent_api
      - agents:/shared-agents
    healthcheck:
      test:
        - CMD-SHELL
        - python -c "import urllib.request; urllib.request.urlopen('http://127.0.0.1:8000/openapi.json', timeout=2).read()"
      interval: 5s
      timeout: 3s
      retries: 12
      start_period: 5s
    command: >
      sh -lc "
        mkdir -p /shared-agents/0 &&
        rm -rf /workspace &&
        ln -s /shared-agents/0 /workspace &&
        exec /app/.venv/bin/uvicorn src.main:app --host 0.0.0.0 --port 8000 --no-access-log
      "

  agent-1:
    build:
      context: ./external/platform-agent
      target: development
      additional_contexts:
        agent_api: ./external/platform-agent_api
    environment:
      PYTHONUNBUFFERED: "1"
      AGENT_ID: ${AGENT_1_ID:-agent-1}
      PROVIDER_MODEL: ${PROVIDER_MODEL:-debug-model}
      PROVIDER_URL: ${PROVIDER_URL:-http://provider.invalid/v1}
      PROVIDER_API_KEY: ${PROVIDER_API_KEY:-debug-key}
    volumes:
      - ./external/platform-agent/src:/app/src
      - ./external/platform-agent_api:/agent_api
      - agents:/shared-agents
    healthcheck:
      test:
        - CMD-SHELL
        - python -c "import urllib.request; urllib.request.urlopen('http://127.0.0.1:8000/openapi.json', timeout=2).read()"
      interval: 5s
      timeout: 3s
      retries: 12
      start_period: 5s
    command: >
      sh -lc "
        mkdir -p /shared-agents/1 &&
        rm -rf /workspace &&
        ln -s /shared-agents/1 /workspace &&
        exec /app/.venv/bin/uvicorn src.main:app --host 0.0.0.0 --port 8000 --no-access-log
      "

volumes:
  agents:
    name: ${SURFACES_SMOKE_VOLUME:-surfaces-smoke-agents}
