# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

version: '2.1'

services:
  oap:
    extends:
      file: ../../script/docker-compose/base-compose.yml
      service: oap
    ports:
      - "12800:12800"
    networks:
      - e2e
  banyandb:
    extends:
      file: ../../script/docker-compose/base-compose.yml
      service: banyandb
    ports:
      - 17912
  es:
    image: elastic/elasticsearch:8.3.2
    expose:
      - 9200
    networks:
      - e2e
    environment:
      - discovery.type=single-node
      - cluster.routing.allocation.disk.threshold_enabled=false
      - xpack.security.enabled=false
      - cluster.name=cluster-e2e
      - node.name=node-e2e
    healthcheck:
      test: ["CMD", "bash", "-c", "cat < /dev/null > /dev/tcp/127.0.0.1/9200"]
      interval: 10s
      timeout: 10s
      retries: 120
  es-exporter:
    image: quay.io/prometheuscommunity/elasticsearch-exporter:v1.5.0
    expose:
      - 9114
    networks:
      - e2e
    depends_on:
      es:
        condition: service_healthy
    command:
      - '--log.format=logfmt'
      - '--log.level=info'
      - '--es.uri=http://es:9200'
      - '--es.all'
      - '--es.indices'
      - '--es.indices_settings'
      - '--es.indices_mappings'
      - '--es.shards'
      - '--es.snapshots'
      - '--es.timeout=30s'
      - '--web.telemetry-path=/metrics'
    healthcheck:
      interval: 5s
      timeout: 60s
      retries: 120
      test: ["CMD", "sh", "-c", "nc -vz localhost 9114"]
  otel-collector:
    image: otel/opentelemetry-collector:${OTEL_COLLECTOR_VERSION}
    networks:
      - e2e
    command: [ "--config=/etc/otel-collector-config.yaml" ]
    volumes:
      - ./otel-collector-config.yaml:/etc/otel-collector-config.yaml
    expose:
      - 55678
    depends_on:
      oap:
        condition: service_healthy
  es-mock:
    image: curlimages/curl:latest
    networks:
      - e2e
    depends_on:
      es:
        condition: service_healthy
      es-exporter:
        condition: service_healthy
      oap:
        condition: service_healthy
    command: "sh /etc/es-e2e-data-mock.sh"
    volumes:
      - ./es-e2e-data-mock.sh:/etc/es-e2e-data-mock.sh

networks:
  e2e:
