version: '3.8'

services:
  redis:
    image: redis:7-alpine
    container_name: smart-city-redis
    networks:
      - smartcity-shared
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 10s
      timeout: 5s
      retries: 5

  cratedb:
    image: crate:5.5
    container_name: smart-city-cratedb
    restart: unless-stopped
    environment:
      - CRATE_HEAP_SIZE=1g
    volumes:
      - cratedb-data:/data
    networks:
      - smartcity-shared
    ports:
      - "4200:4200"
    healthcheck:
      test: ["CMD", "curl", "-f", "-X", "POST", "-d", "{\"stmt\": \"SELECT 1\"}", "http://localhost:4200/_sql"]
      interval: 10s
      timeout: 5s
      retries: 5

  quantumleap:
    image: fiware/quantum-leap:latest
    container_name: smart-city-quantumleap
    restart: unless-stopped
    environment:
      - CRATE_HOST=smart-city-cratedb
      - CRATE_PORT=4200
      - CRATE_DB_NAME=quantumleap
      - QL_LOG_LEVEL=DEBUG
      - RQ_MONITOR_REDIS_URL=redis://smart-city-redis:6379
      - REDIS_HOST=smart-city-redis
      - REDIS_PORT=6379
      - WQ_OFFLOAD_WORK=True
      - ORION_HOST=smart-city-orion-ld
      - ORION_PORT=1026
    depends_on:
      cratedb:
        condition: service_healthy
      redis:
        condition: service_healthy
    networks:
      - smartcity-shared
      - traefik-public
    ports:
      - "8668:8668"
    # Le worker est géré en interne par wq (pas besoin de rq worker)
    # Utilisation du command par défaut: python /src/ngsi-timeseries-api/src/app.py
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.quantumleap.rule=Host(`quantum-leap.digitribe.fr')"
      - "traefik.http.routers.quantumleap.entrypoints=websecure"
      - "traefik.http.routers.quantumleap.tls=true"
      - "traefik.http.services.quantumleap.loadbalancer.server.port=8668"

volumes:
  cratedb-data:

networks:
  smartcity-shared:
    external: true
  traefik-public:
    external: true
