# Temporary Test Environment - Isolated from Production
# Ports: API 4001, Frontend 8001, Prometheus 9092, Grafana 3005
# Database: /tmp/llmhosts-test.db (ephemeral)
# Network: llmhosts-test-network

services:
  llmhosts-test:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: llmhosts-test
    ports:
      - "4001:4000"  # API on different port
    environment:
      - DATABASE_URL=sqlite:////tmp/llmhosts-test.db
      - ENVIRONMENT=test
      - LOG_LEVEL=DEBUG
      - METRICS_ENABLED=true
      - CORS_ORIGINS=http://localhost:8001
      - AUTH_SECRET=${AUTH_SECRET:-test-secret-change-in-production}
    volumes:
      - /tmp/llmhosts-test-data:/data
      - ./llmhosts:/app/llmhosts:ro
    networks:
      - llmhosts-test-network
    healthcheck:
      test: ["CMD", "python3", "-c", "import urllib.request; urllib.request.urlopen('http://127.0.0.1:4000/health').read()"]
      interval: 10s
      timeout: 5s
      retries: 3
      start_period: 30s
    restart: unless-stopped

  llmhosts-frontend-test:
    build:
      context: ./frontend
      dockerfile: Dockerfile
      args:
        - NEXT_PUBLIC_API_URL=http://localhost:4001
    container_name: llmhosts-frontend-test
    ports:
      - "8001:3000"  # Frontend on high port to avoid conflicts
    environment:
      - NODE_ENV=production
      - DATABASE_URL=file:/tmp/llmhosts-test.db
      - NEXTAUTH_URL=http://localhost:3001
      - NEXTAUTH_SECRET=${AUTH_SECRET:-test-secret-change-in-production}
      - AUTH_TRUST_HOST=true
      - NEXT_PUBLIC_API_URL=http://localhost:4001
      - STRIPE_SECRET_KEY=${STRIPE_TEST_SECRET_KEY:-sk_test_placeholder} # gitleaks:allow
      - STRIPE_WEBHOOK_SECRET=${STRIPE_TEST_WEBHOOK_SECRET:-whsec_placeholder} # gitleaks:allow
    volumes:
      - /tmp/llmhosts-test-data:/data
    networks:
      - llmhosts-test-network
    depends_on:
      llmhosts-test:
        condition: service_healthy
    healthcheck:
      test: ["CMD", "node", "-e", "require('http').get('http://127.0.0.1:3000/api/health',r=>{process.exit(r.statusCode===200?0:1)}).on('error',()=>process.exit(1))"]
      interval: 10s
      timeout: 5s
      retries: 3
      start_period: 30s
    restart: unless-stopped

  # Monitoring stack for test environment
  prometheus-test:
    image: prom/prometheus:latest
    container_name: prometheus-test
    ports:
      - "9092:9090"  # Different port
    volumes:
      - ./infrastructure/monitoring/prometheus/prometheus.test.yml:/etc/prometheus/prometheus.yml:ro
      - prometheus-test-data:/prometheus
    command:
      - '--config.file=/etc/prometheus/prometheus.yml'
      - '--storage.tsdb.retention.time=7d'
      - '--web.enable-lifecycle'
    networks:
      - llmhosts-test-network
    restart: unless-stopped

  grafana-test:
    image: grafana/grafana:latest
    container_name: grafana-test
    ports:
      - "3005:3000"  # Different port (avoid conflict with 3004)
    volumes:
      - grafana-test-data:/var/lib/grafana
      - ./infrastructure/monitoring/grafana/provisioning:/etc/grafana/provisioning:ro
      - ./infrastructure/monitoring/grafana/dashboards:/var/lib/grafana/dashboards:ro
    environment:
      - GF_SECURITY_ADMIN_PASSWORD=test123
      - GF_SERVER_ROOT_URL=http://localhost:3005
      - GF_AUTH_ANONYMOUS_ENABLED=false
    networks:
      - llmhosts-test-network
    depends_on:
      - prometheus-test
    restart: unless-stopped

networks:
  llmhosts-test-network:
    name: llmhosts-test-network
    driver: bridge

volumes:
  prometheus-test-data:
    name: prometheus-test-data
  grafana-test-data:
    name: grafana-test-data
