services:
  metadata-db:
    image: postgres:16-alpine
    environment:
      POSTGRES_DB: datalake
      POSTGRES_USER: datalake
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-CHANGE_ME}
    volumes:
      - metadata_data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U datalake -d datalake"]
      interval: 10s
      timeout: 5s
      retries: 10
    networks: [datalake_internal]

  redis:
    image: redis:7-alpine
    command: ["redis-server", "--appendonly", "yes", "--requirepass", "${REDIS_PASSWORD:-CHANGE_ME}"]
    volumes:
      - redis_data:/data
    networks: [datalake_internal]

  minio:
    image: minio/minio:latest
    command: server /data --console-address ":9001"
    environment:
      MINIO_ROOT_USER: ${S3_ACCESS_KEY:-datalake_admin}
      MINIO_ROOT_PASSWORD: ${S3_SECRET_KEY:-CHANGE_ME}
    volumes:
      - minio_data:/data
    ports:
      - "9000:9000"
      - "9001:9001"
    networks: [datalake_internal]

  api:
    build: .
    env_file: .env
    command: uvicorn app.main:app --host 0.0.0.0 --port 8080
    ports:
      - "8080:8080"
    depends_on:
      metadata-db:
        condition: service_healthy
      minio:
        condition: service_started
      redis:
        condition: service_started
    networks: [datalake_internal]

  worker:
    build: .
    env_file: .env
    command: celery -A app.workers.celery_app worker --loglevel=INFO --concurrency=2
    depends_on: [api, redis]
    networks: [datalake_internal]

  scheduler:
    build: .
    env_file: .env
    command: celery -A app.workers.celery_app beat --loglevel=INFO
    depends_on: [api, redis]
    networks: [datalake_internal]

  prometheus:
    image: prom/prometheus:v2.54.1
    command: ["--config.file=/etc/prometheus/prometheus.yml"]
    volumes: ["./observability/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml:ro", "prometheus_data:/prometheus"]
    ports: ["9090:9090"]
    depends_on: [api]
    networks: [datalake_internal]

  grafana:
    image: grafana/grafana:11.2.0
    environment:
      GF_SECURITY_ADMIN_USER: ${GRAFANA_ADMIN_USER:-admin}
      GF_SECURITY_ADMIN_PASSWORD: ${GRAFANA_ADMIN_PASSWORD:-CHANGE_ME}
    volumes: ["grafana_data:/var/lib/grafana", "./observability/grafana/provisioning:/etc/grafana/provisioning:ro"]
    ports: ["3000:3000"]
    depends_on: [prometheus]
    networks: [datalake_internal]

networks:
  datalake_internal:
    driver: bridge

volumes:
  metadata_data:
  redis_data:
  minio_data:
  prometheus_data:
  grafana_data:
