# docker-compose-dev.yml: Enables port forwarding for local development in `make up`.
#
# To run directly from command-line:
#     docker compose -f docker-compose.yml -f docker-compose-dev.yml up -d
services:
  ai-eval-runner-dev:
    ports:
      - 8888:5000
    env_file:
      - .env
    environment:
      - HOST=0.0.0.0
      - AWS_ACCESS_KEY_ID
      - AWS_SECRET_ACCESS_KEY
      - AWS_SESSION_TOKEN
      - AWS_REGION
    depends_on:
      jobs-table-init:
        condition: service_completed_successfully

  ai-eval-runner-deploy:
    ports:
      - 8889:8080

  dynamodb-local:
    image: amazon/dynamodb-local:latest
    command: ["-jar", "DynamoDBLocal.jar", "-inMemory", "-sharedDb"]
    ports:
      - 8000:8000
    healthcheck:
      # No -f: DynamoDB Local correctly returns 400 for an unsigned/unauthenticated request —
      # any HTTP response (even 400) means the server is up; only a connection error should fail this.
      test: ["CMD", "curl", "-s", "-o", "/dev/null", "http://localhost:8000/"]
      interval: 2s
      timeout: 2s
      retries: 15

  # One-shot: creates the local jobs table before ai-eval-runner-dev starts, so `make up` fails
  # loudly on setup problems instead of the first real request failing instead.
  jobs-table-init:
    build:
      context: .
      target: dev
    env_file:
      - .env
    environment:
      - AWS_ACCESS_KEY_ID
      - AWS_SECRET_ACCESS_KEY
      - AWS_SESSION_TOKEN
      - AWS_REGION
      - PYTHONPATH=/var/app
    depends_on:
      dynamodb-local:
        condition: service_healthy
    volumes:
      - .:/var/app
    command: ["python", "scripts/create-local-jobs-table.py"]
