x-defaults: &defaults
  restart: unless-stopped
  logging:
    driver: json-file
    options:
      max-size: 100m
      max-file: '3'

services:
  kibana:
    <<: *defaults
    image: ${GLOBAL_REGISTRY:-}docker.elastic.co/kibana/kibana:${KIBANA_VERSION:-9.2.0}
    ports:
      - '${KIBANA_PORT_OVERRIDE:-5601}:5601'
    volumes:
      - kibana_data:/usr/share/kibana/data

      # Custom configuration
      # - ./kibana.yml:/usr/share/kibana/config/kibana.yml:ro
    environment:
      - TZ=${TZ:-UTC}
      - SERVERNAME=${KIBANA_SERVERNAME:-kibana}
      - ELASTICSEARCH_HOSTS=${ELASTICSEARCH_HOSTS:-http://elasticsearch:9200}
      - ELASTICSEARCH_USERNAME=${ELASTICSEARCH_USERNAME:-}
      - ELASTICSEARCH_PASSWORD=${ELASTICSEARCH_PASSWORD:-}
      - XPACK_SECURITY_ENABLED=${KIBANA_SECURITY_ENABLED:-false}
      - XPACK_ENCRYPTEDSAVEDOBJECTS_ENCRYPTIONKEY=${KIBANA_ENCRYPTION_KEY:-}
      - LOGGING_ROOT_LEVEL=${KIBANA_LOG_LEVEL:-info}
    deploy:
      resources:
        limits:
          cpus: ${KIBANA_CPU_LIMIT:-1.00}
          memory: ${KIBANA_MEMORY_LIMIT:-1G}
        reservations:
          cpus: ${KIBANA_CPU_RESERVATION:-0.25}
          memory: ${KIBANA_MEMORY_RESERVATION:-512M}
    healthcheck:
      test: [CMD-SHELL, 'curl -f http://localhost:5601/api/status || exit 1']
      interval: 30s
      timeout: 10s
      retries: 5
      start_period: 60s

volumes:
  kibana_data:
