## Umami analytics — déployer avec le compose principal
## Usage : docker compose -f docker-compose.yml -f docker-compose.umami.yml up -d
##
## Variables à définir dans .env :
##   UMAMI_DB_PASSWORD   — mot de passe PostgreSQL Umami (générer avec openssl rand -hex 32)
##   UMAMI_APP_SECRET    — secret applicatif (générer avec openssl rand -hex 32)
##   UMAMI_DOMAIN        — ex: stats.librodrome.org

name: librodrome

services:
  umami:
    image: ghcr.io/umami-software/umami:postgresql-latest
    environment:
      DATABASE_URL: postgresql://umami:${UMAMI_DB_PASSWORD}@umami-db:5432/umami
      DATABASE_TYPE: postgresql
      APP_SECRET: ${UMAMI_APP_SECRET}
    depends_on:
      umami-db:
        condition: service_healthy
    restart: always
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.umami.rule=Host(`${UMAMI_DOMAIN:-stats.librodrome.org}`)"
      - "traefik.http.routers.umami.entrypoints=websecure"
      - "traefik.http.routers.umami.tls.certresolver=letsencrypt"
      - "traefik.http.services.umami.loadbalancer.server.port=3000"
    networks:
      - default
      - traefik

  umami-db:
    image: postgres:15-alpine
    environment:
      POSTGRES_DB: umami
      POSTGRES_USER: umami
      POSTGRES_PASSWORD: ${UMAMI_DB_PASSWORD}
    volumes:
      - umami-db-data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U umami"]
      interval: 5s
      timeout: 5s
      retries: 10
    restart: always

volumes:
  umami-db-data:

networks:
  traefik:
    external: true
