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

services:
  opensearch:
    <<: *defaults
    image: ${GLOBAL_REGISTRY:-}opensearchproject/opensearch:${OPENSEARCH_VERSION:-2.19.0}
    environment:
      TZ: ${TZ:-UTC}
      cluster.name: ${CLUSTER_NAME:-opensearch-cluster}
      node.name: opensearch
      discovery.type: single-node
      bootstrap.memory_lock: true
      OPENSEARCH_JAVA_OPTS: '-Xms${OPENSEARCH_HEAP_SIZE:-512m} -Xmx${OPENSEARCH_HEAP_SIZE:-512m}'
      OPENSEARCH_INITIAL_ADMIN_PASSWORD: ${OPENSEARCH_ADMIN_PASSWORD:-Admin@123}
      DISABLE_SECURITY_PLUGIN: ${DISABLE_SECURITY_PLUGIN:-false}
    ulimits:
      memlock:
        soft: -1
        hard: -1
      nofile:
        soft: 65536
        hard: 65536
    ports:
      - '${OPENSEARCH_PORT_OVERRIDE:-9200}:9200'
      - '${OPENSEARCH_PERF_ANALYZER_PORT_OVERRIDE:-9600}:9600'
    volumes:
      - opensearch_data:/usr/share/opensearch/data
    deploy:
      resources:
        limits:
          cpus: ${OPENSEARCH_CPU_LIMIT:-2.0}
          memory: ${OPENSEARCH_MEMORY_LIMIT:-2G}
        reservations:
          cpus: ${OPENSEARCH_CPU_RESERVATION:-0.1}
          memory: ${OPENSEARCH_MEMORY_RESERVATION:-1G}
    healthcheck:
      test:
        [CMD-SHELL, 'curl -f http://localhost:9200/_cluster/health || exit 1']
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 60s

  opensearch-dashboards:
    <<: *defaults
    image: ${GLOBAL_REGISTRY:-}opensearchproject/opensearch-dashboards:${OPENSEARCH_DASHBOARDS_VERSION:-2.19.0}
    ports:
      - '${OPENSEARCH_DASHBOARDS_PORT_OVERRIDE:-5601}:5601'
    environment:
      TZ: ${TZ:-UTC}
      OPENSEARCH_HOSTS: '["https://opensearch:9200"]'
      DISABLE_SECURITY_DASHBOARDS_PLUGIN: ${DISABLE_SECURITY_PLUGIN:-false}
    depends_on:
      opensearch:
        condition: service_healthy
    deploy:
      resources:
        limits:
          cpus: ${OPENSEARCH_DASHBOARDS_CPU_LIMIT:-1.0}
          memory: ${OPENSEARCH_DASHBOARDS_MEMORY_LIMIT:-1G}
        reservations:
          cpus: ${OPENSEARCH_DASHBOARDS_CPU_RESERVATION:-0.1}
          memory: ${OPENSEARCH_DASHBOARDS_MEMORY_RESERVATION:-512M}
    healthcheck:
      test:
        - CMD
        - wget
        - --no-verbose
        - --tries=1
        - --spider
        - 'http://localhost:5601/api/status'

      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 30s

volumes:
  opensearch_data:
