# 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.

services:
  banyandb:
    expose:
      - 17912
      - 2121
      - 6060
    command: standalone
    healthcheck:
      test: ["CMD", "./bydbctl", "health", "--config=-", "--addr=http://banyandb:17913"]
      interval: 5s
      timeout: 120s
      retries: 120

  liaison:
    hostname: liaison
    ports:
      - 17913:17913
    expose:
      - 17912
      - 2121
      - 6060
    command: liaison --etcd-endpoints=http://etcd:2379
    healthcheck:
      test: ["CMD", "./bydbctl", "health", "--addr=http://liaison:17913"]
      interval: 5s
      timeout: 120s
      retries: 120

  data:
    hostname: data
    expose:
      - 17912
      - 2121
      - 6060
      - 17932
    command: data --etcd-endpoints=http://etcd:2379
    healthcheck:
      test: ["CMD", "./bydbctl", "health", "--addr=http://127.0.0.1:17913"]
      interval: 5s
      timeout: 120s
      retries: 120

  agent:
    image: "ghcr.io/apache/skywalking-java/skywalking-java:${SW_AGENT_JAVA_COMMIT}-java8"
    command: cp -r /skywalking/agent/ /skywalking-java-agent/
    volumes:
      - sw_agent:/skywalking-java-agent

  oap:
    image: "ghcr.io/apache/skywalking/oap:${SW_OAP_COMMIT}"
    expose:
      - 11800
      - 12800
      - 10051
      - 5005
    environment:
      SW_STORAGE_BANYANDB_TARGETS: banyandb:17912
    healthcheck:
      test: ["CMD", "bash", "-c", "cat < /dev/null > /dev/tcp/127.0.0.1/11800"]
      interval: 5s
      timeout: 120s
      retries: 120

  ui:
    image: "ghcr.io/apache/skywalking/ui:${SW_OAP_COMMIT}"
    expose:
      - 8080
    environment:
      - SW_OAP_ADDRESS=http://oap:12800

  provider:
    image: "ghcr.io/apache/skywalking/e2e-service-provider:${SW_AGENT_E2E_SERVICE_PROVIDER_COMMIT}"
    volumes:
      - sw_agent:/sw-java-agent
    expose:
      - 9090
      - 5005
    environment:
      JAVA_TOOL_OPTIONS: -javaagent:/sw-java-agent/agent/skywalking-agent.jar
      SW_AGENT_COLLECTOR_BACKEND_SERVICES: oap:11800
      SW_LOGGING_OUTPUT: CONSOLE
      SW_AGENT_NAME: e2e-service-provider
      SW_AGENT_INSTANCE_NAME: provider1
      SW_AGENT_COLLECTOR_GET_PROFILE_TASK_INTERVAL: 1
      SW_AGENT_COLLECTOR_GET_AGENT_DYNAMIC_CONFIG_INTERVAL: 1
      SW_METER_ACTIVE: 'false'
    healthcheck:
      test: ["CMD", "bash", "-c", "cat < /dev/null > /dev/tcp/127.0.0.1/9090"]
      interval: 5s
      timeout: 60s
      retries: 120

  consumer:
    image: "ghcr.io/apache/skywalking/e2e-service-consumer:${SW_AGENT_E2E_SERVICE_PROVIDER_COMMIT}"
    volumes:
      - sw_agent:/sw-java-agent
    expose:
      - 9092
      - 5005
    environment:
      JAVA_TOOL_OPTIONS: -javaagent:/sw-java-agent/agent/skywalking-agent.jar
      SW_AGENT_COLLECTOR_BACKEND_SERVICES: oap:11800
      SW_LOGGING_OUTPUT: CONSOLE
      PROVIDER_URL: http://provider:9090
      SW_AGENT_NAME: e2e-service-consumer
      SW_AGENT_INSTANCE_NAME: consumer1
      SW_AGENT_COLLECTOR_GET_PROFILE_TASK_INTERVAL: 1
      SW_AGENT_COLLECTOR_GET_AGENT_DYNAMIC_CONFIG_INTERVAL: 1
      SW_METER_ACTIVE: 'false'
    healthcheck:
      test: ["CMD", "bash", "-c", "cat < /dev/null > /dev/tcp/127.0.0.1/9092"]
      interval: 5s
      timeout: 60s
      retries: 120

  traffic_loader:
    image: grafana/k6:latest
    ports:
      - "6565:6565"

  etcd:
    image: gcr.io/etcd-development/etcd:v3.5.9
    ports:
      - "2379:2379"
    command: etcd --listen-client-urls http://0.0.0.0:2379 --advertise-client-urls http://etcd:2379 --max-request-bytes 10485760 --backend-batch-limit 10000
    healthcheck:
      test: ["CMD", "etcdctl", "endpoint", "health"]
      interval: 1m30s
      timeout: 10s
      retries: 3
      start_period: 40s

volumes:
  sw_agent:
