# Apache Superset - BI Dashboard for Smart City Digital Twin
# Usage: docker compose -f docker-compose.superset.yml up -d
# Access: https://superset.digitribe.fr

version: '3.8'

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

volumes:
  superset_data:
    name: smart-city-superset-data
  superset_redis:
    name: smart-city-superset-redis

services:
  superset-redis:
    image: redis:7-alpine
    container_name: superset-redis
    restart: unless-stopped
    networks:
      - smartcity-shared
    volumes:
      - superset_redis:/data
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 10s
      timeout: 5s
      retries: 5

  superset-db:
    image: postgres:15-alpine
    container_name: superset-postgres
    restart: unless-stopped
    networks:
      - smartcity-shared
    environment:
      POSTGRES_DB: superset
      POSTGRES_USER: superset
      POSTGRES_PASSWORD: Digitribe972
    volumes:
      - superset_data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U superset"]
      interval: 10s
      timeout: 5s
      retries: 5

  superset:
    image: apache/superset:4.0.0
    container_name: superset-app
    restart: unless-stopped
    networks:
      - smartcity-shared
      - traefik-public
    depends_on:
      superset-db:
        condition: service_healthy
      superset-redis:
        condition: service_healthy
    environment:
      SUPERSET_SECRET_KEY: superset-secret-key-change-me-2024
      DATABASE_DIALECT: postgresql
      DATABASE_HOST: superset-postgres
      DATABASE_PORT: 5432
      DATABASE_DB: superset
      DATABASE_USER: superset
      DATABASE_PASSWORD: Digitribe972
      REDIS_HOST: superset-redis
      REDIS_PORT: 6379
      SUPERSET_ENV: production
      SUPERSET_LOAD_EXAMPLES: "false"
      MAPBOX_API_KEY: ""
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.superset.rule=Host(`superset.digitribe.fr`)"
      - "traefik.http.routers.superset.entrypoints=websecure"
      - "traefik.http.routers.superset.tls.certresolver=letsencrypt"
      - "traefik.http.services.superset.loadbalancer.server.port=8088"
    healthcheck:
      test: ["CMD-SHELL", "curl -f http://localhost:8088/health || exit 1"]
      interval: 30s
      timeout: 10s
      retries: 5
      start_period: 120s
