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

version: '3.8'

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

volumes:
  metabase_data:
    name: smart-city-metabase-data

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

  metabase:
    image: metabase/metabase:latest
    container_name: metabase-app
    restart: unless-stopped
    networks:
      - smartcity-shared
      - traefik-public
    depends_on:
      metabase-db:
        condition: service_healthy
    environment:
      MB_DB_TYPE: postgres
      MB_DB_DBNAME: metabase
      MB_DB_PORT: 5432
      MB_DB_USER: metabase
      MB_DB_PASS: Digitribe972
      MB_DB_HOST: metabase-postgres
      MB_SITE_NAME: "Smart City Martinique"
      MB_SITE_URL: "https://metabase.digitribe.fr"
      MB_APPLICATION_DB: "file:/metabase-data/metabase.db"
      MB_ENABLE_PASSWORD_LOGIN: "true"
      MB_ADMIN_EMAIL: admin@digitribe.fr
      MB_ADMIN_PASSWORD: Digitribe972
      MB_JETTY_PORT: 3000
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.metabase.rule=Host(`metabase.digitribe.fr`)"
      - "traefik.http.routers.metabase.entrypoints=websecure"
      - "traefik.http.routers.metabase.tls.certresolver=letsencrypt"
      - "traefik.http.services.metabase.loadbalancer.server.port=3000"
    healthcheck:
      test: ["CMD-SHELL", "curl -f http://localhost:3000/api/health || exit 1"]
      interval: 30s
      timeout: 10s
      retries: 5
      start_period: 120s
