# ============================================================================
#  CentralLogging — docker-compose (Loki + Grafana + Log Gateway)
#  Verze:  1.0
#  Datum:  2026-06-08
#  Popis:  Stack pro centrální logování na Unraidu.
#            - loki     : úložiště logů (HTTP push API), retence 90 dní
#            - grafana  : prohlížení a dashboardy nad Loki
#            - gateway  : FastAPI brána, kam posílají logy klientské skripty
#
#  Spuštění na Unraidu:
#     docker compose -f docker-compose.yml up -d
#
#  Porty (uprav dle potřeby):
#     3100  Loki HTTP        (interní, klienti na něj nesahají přímo)
#     3000  Grafana web UI
#     8770  Log Gateway      (sem posílají skripty)
# ============================================================================
services:

  loki:
    image: grafana/loki:3.1.1
    container_name: central-loki
    restart: unless-stopped
    command: -config.file=/etc/loki/loki-config.yml
    ports:
      - "3100:3100"
    volumes:
      - ./loki-config.yml:/etc/loki/loki-config.yml:ro
      # Persistentní data na Unraid share (desítky TB) — uprav cestu:
      - /mnt/user/appdata/central-logging/loki:/loki
    networks:
      - logging

  grafana:
    image: grafana/grafana:11.2.0
    container_name: central-grafana
    restart: unless-stopped
    ports:
      - "3001:3000"   # 3000 na Unraidu drží Gitea -> Grafana na 3001
    environment:
      - GF_SECURITY_ADMIN_USER=admin
      - GF_SECURITY_ADMIN_PASSWORD=${GRAFANA_PASSWORD:-changeme}
      - GF_USERS_ALLOW_SIGN_UP=false
    volumes:
      - /mnt/user/appdata/central-logging/grafana:/var/lib/grafana
      - ./grafana-datasource.yml:/etc/grafana/provisioning/datasources/loki.yml:ro
      - ./grafana-dashboards.yml:/etc/grafana/provisioning/dashboards/central.yml:ro
      - ./dashboards:/etc/grafana/provisioning/dashboards/json:ro
    depends_on:
      - loki
    networks:
      - logging

  gateway:
    build:
      context: ../gateway
    image: central-log-gateway:1.0
    container_name: central-log-gateway
    restart: unless-stopped
    ports:
      - "8770:8770"
    environment:
      - LOKI_URL=http://loki:3100
      - LOG_TOKEN=${LOG_TOKEN:-change-this-shared-secret}
      - GATEWAY_ENV=prod
    depends_on:
      - loki
    networks:
      - logging

networks:
  logging:
    driver: bridge
