services:
  e2e-agent-builder:
    build:
      context: ..
      dockerfile: e2e/Dockerfile.agent-builder
    volumes:
      - ./artifacts:/artifacts
    container_name: e2e-agent-builder

  e2e-postgres:
    image: postgres:17
    environment:
      POSTGRES_DB: testdb
      POSTGRES_USER: testuser
      POSTGRES_PASSWORD: testpassword
    container_name: e2e-agent-postgres
    command:
      - bash
      - -c
      - |
        mkdir -p /wal-queue && chown postgres:postgres /wal-queue
        exec docker-entrypoint.sh postgres \
          -c wal_level=replica \
          -c max_wal_senders=3 \
          -c archive_mode=on \
          -c "archive_command=cp %p /wal-queue/%f"
    volumes:
      - ./pgdata:/var/lib/postgresql/data
      - wal-queue:/wal-queue
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U testuser -d testdb"]
      interval: 2s
      timeout: 5s
      retries: 30

  e2e-mock-server:
    build:
      context: .
      dockerfile: Dockerfile.mock-server
    volumes:
      - ./artifacts:/artifacts:ro
      - backup-storage:/backup-storage
    container_name: e2e-mock-server
    healthcheck:
      test: ["CMD", "wget", "-q", "--spider", "http://localhost:4050/health"]
      interval: 2s
      timeout: 5s
      retries: 10

  e2e-agent-runner:
    build:
      context: .
      dockerfile: Dockerfile.agent-runner
    volumes:
      - ./artifacts:/opt/agent/artifacts:ro
      - ./scripts:/opt/agent/scripts:ro
    depends_on:
      e2e-postgres:
        condition: service_healthy
      e2e-mock-server:
        condition: service_healthy
    container_name: e2e-agent-runner
    command: ["bash", "/opt/agent/scripts/run-all.sh", "host"]

  e2e-agent-docker:
    build:
      context: .
      dockerfile: Dockerfile.agent-docker
    volumes:
      - ./artifacts:/opt/agent/artifacts:ro
      - ./scripts:/opt/agent/scripts:ro
      - /var/run/docker.sock:/var/run/docker.sock
      - wal-queue:/wal-queue
    depends_on:
      e2e-postgres:
        condition: service_healthy
      e2e-mock-server:
        condition: service_healthy
    container_name: e2e-agent-docker
    command: ["bash", "/opt/agent/scripts/run-all.sh", "docker"]

volumes:
  wal-queue:
  backup-storage:
