# 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
    environment:
      - TZ=Asia/Shanghai
    ports:
      - "12800:12800"
  zookeeper:
    image: zookeeper:3.7.2
    environment:
      - ZOO_MY_ID=1
    ports:
      - "2181:2181"
    networks:
      - e2e
  clickhouse1:
    image: clickhouse/clickhouse-server:24.1.5.6
    volumes:
      - ./clickhouse1/config.xml:/etc/clickhouse-server/config.xml
      - ./clickhouse1/metrika.xml:/etc/clickhouse-server/metrika.xml
    depends_on:
      - zookeeper
    ports:
      - "9000:9000"
      - "8123:8123"
      - "9009:9009"
      - "9363:9363"
    networks:
      - e2e
    healthcheck:
      test: [ "CMD", "bash", "-c", "cat < /dev/null > /dev/tcp/127.0.0.1/8123" ]
      interval: 5s
      timeout: 60s
      retries: 120
  clickhouse2:
    image: clickhouse/clickhouse-server:24.1.5.6
    volumes:
      - ./clickhouse2/config.xml:/etc/clickhouse-server/config.xml
      - ./clickhouse2/metrika.xml:/etc/clickhouse-server/metrika.xml
    depends_on:
      - zookeeper
    ports:
      - "9001:9000"
      - "8124:8123"
      - "9010:9009"
      - "9364:9363"
    networks:
      - e2e
    healthcheck:
      test: ["CMD", "bash", "-c", "cat < /dev/null > /dev/tcp/127.0.0.1/8123"]
      interval: 5s
      timeout: 60s
      retries: 120
  clickhouse_mock:
    image: clickhouse/clickhouse-client:21.3.20.1
    depends_on:
      - otel-collector
      - zookeeper
      - clickhouse1
      - clickhouse2
      - oap
    networks:
      - e2e
    entrypoint: bash
    volumes:
      - ./clickhouse1/mock1.sql:/data/clickhouse1/mock1.sql
      - ./clickhouse2/mock2.sql:/data/clickhouse2/mock2.sql
    command:
      - -c
      - "sleep 5 && clickhouse-client --host clickhouse1 --port 9000 -d default --multiquery <  /data/clickhouse1/mock1.sql && sleep 5 && clickhouse-client --host clickhouse2 --port 9000 -d default --multiquery <  /data/clickhouse2/mock2.sql"
  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:
      - zookeeper
      - clickhouse1
      - clickhouse2
      - oap

networks:
  e2e:
