version: "3.8"

services:
  app:
    build:
      context: ..
      dockerfile: docker/Dockerfile
    ports:
      - "5001:5001"
    environment:
      - DATABASE_URL=postgresql://todouser:todopass@postgres:5432/todos
      - UPLOAD_FOLDER=/tmp/todo_uploads
      - PORT=5001
    depends_on:
      postgres:
        condition: service_healthy
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:5001/health"]
      interval: 10s
      timeout: 5s
      retries: 5

  postgres:
    image: postgres:15-alpine
    environment:
      - POSTGRES_USER=todouser
      - POSTGRES_PASSWORD=todopass
      - POSTGRES_DB=todos
    volumes:
      - postgres_qa_data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U todouser -d todos"]
      interval: 5s
      timeout: 5s
      retries: 5

  venomqa:
    build:
      context: ../../..
      dockerfile: Dockerfile
    environment:
      - PYTHONUNBUFFERED=1
    volumes:
      - ./journeys:/app/journeys:ro
      - ./actions:/app/actions:ro
      - ./venomqa.yaml:/app/venomqa.yaml:ro
      - ./reports:/reports
    working_dir: /app
    depends_on:
      app:
        condition: service_healthy
    command: >
      sh -c "pip install -e /venomqa && python -c 'from venomqa import Client; from venomqa.runner import JourneyRunner; print(\"VenomQA ready\")'"

volumes:
  postgres_qa_data:
