services:
  db:
    image: postgres:16-alpine
    container_name: video_automation_db
    environment:
      POSTGRES_USER: ${POSTGRES_USER:-video_automation}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-changeme}
      POSTGRES_DB: ${POSTGRES_DB:-video_automation}
    volumes:
      - postgres_data:/var/lib/postgresql/data
    ports:
      - "5434:5432"
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-video_automation} -d ${POSTGRES_DB:-video_automation}"]
      interval: 5s
      timeout: 5s
      retries: 5
    restart: unless-stopped

  app:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: video_automation_app
    depends_on:
      db:
        condition: service_healthy
    environment:
      DATABASE_URL: postgresql://${POSTGRES_USER:-video_automation}:${POSTGRES_PASSWORD:-changeme}@db:5432/${POSTGRES_DB:-video_automation}
      PYTHONUNBUFFERED: 1
    env_file:
      - .env
    ports:
      - "8000:8000"
    restart: unless-stopped
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:8000/health"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 15s
    deploy:
      resources:
        limits:
          memory: 8G
          cpus: '4'
    command: uvicorn web.app:app --host 0.0.0.0 --port 8000

volumes:
  postgres_data:
    driver: local
