version: "3.8"

services:
  api:
    build:
      context: .
      dockerfile: Dockerfile
      args:
        - PYTHON_VERSION=3.12
    ports:
      - "8000:8000"
    environment:
      - DEBUG=true
      - LOG_LEVEL=debug
      - RELOAD=true
      - DATABASE_URL=postgresql://devuser:devpass@postgres:5432/venomqa_dev
      - REDIS_URL=redis://redis:6379/0
      - SECRET_KEY=dev-secret-key-change-in-production
    volumes:
      - ./api:/app/api:ro
      - ./tests:/app/tests:ro
      - ./reports:/app/reports
    depends_on:
      postgres:
        condition: service_healthy
      redis:
        condition: service_healthy
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:8000/health"]
      interval: 10s
      timeout: 5s
      retries: 3

  postgres:
    image: postgres:15-alpine
    ports:
      - "5432:5432"
    environment:
      - POSTGRES_USER=devuser
      - POSTGRES_PASSWORD=devpass
      - POSTGRES_DB=venomqa_dev
    volumes:
      - dev_postgres_data:/var/lib/postgresql/data
      - ./scripts/init.sql:/docker-entrypoint-initdb.d/init.sql:ro
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U devuser -d venomqa_dev"]
      interval: 5s
      timeout: 5s
      retries: 5

  redis:
    image: redis:7-alpine
    ports:
      - "6379:6379"
    command: redis-server --appendonly yes
    volumes:
      - dev_redis_data:/data
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 5s
      timeout: 5s
      retries: 5

  venomqa-runner:
    build:
      context: .
      dockerfile: Dockerfile.qa
    environment:
      - API_BASE_URL=http://api:8000
      - DATABASE_URL=postgresql://devuser:devpass@postgres:5432/venomqa_dev
      - REDIS_URL=redis://redis:6379/0
      - REPORT_OUTPUT=/reports
      - WATCH=true
    volumes:
      - ./reports:/reports
      - ./journeys:/app/journeys:ro
      - ./actions:/app/actions:ro
      - ./venomqa.yaml:/app/venomqa.yaml:ro
    depends_on:
      api:
        condition: service_healthy

  adminer:
    image: adminer:latest
    ports:
      - "8080:8080"
    environment:
      - ADMINER_DEFAULT_SERVER=postgres
    depends_on:
      - postgres

  redis-commander:
    image: rediscommander/redis-commander:latest
    ports:
      - "8081:8081"
    environment:
      - REDIS_HOSTS=local:redis:6379
    depends_on:
      - redis

  mailhog:
    image: mailhog/mailhog:latest
    ports:
      - "1025:1025"
      - "8025:8025"

  mock-server:
    image: mockserver/mockserver:latest
    ports:
      - "1080:1080"
    environment:
      - MOCKSERVER_INITIALIZATION_JSON_PATH=/config/initializer.json
    volumes:
      - ./tests/fixtures/mock-server:/config:ro

volumes:
  dev_postgres_data:
  dev_redis_data:
