version: "3.8"
services:

  # base images
  flask_service:
    build:
      context: ../shared/flask
    image: flask_service:python-3.10-slim-bullseye
    restart: "no"
    deploy:
      replicas: 0

  tracing:
    build:
      context: ../shared/tracing
    image: envoyproxy:tracing
    restart: "no"
    deploy:
      replicas: 0

  # Front envoy.
  front-envoy:
    build:
      context: .
      dockerfile: Dockerfile-frontenvoy
    ports:
    - 8000:8000
    - 8001:8001
    depends_on:
    - skywalking-oap

  # First service.
  service1:
    image: envoyproxy:tracing
    volumes:
    - ./service1-envoy-skywalking.yaml:/etc/service-envoy.yaml
    environment:
    - SERVICE_NAME=1
    depends_on:
    - skywalking-oap

  # Second service.
  service2:
    image: envoyproxy:tracing
    volumes:
    - ./service2-envoy-skywalking.yaml:/etc/service-envoy.yaml
    environment:
    - SERVICE_NAME=2
    depends_on:
    - skywalking-oap

  # Skywalking components.
  elasticsearch:
    image: elasticsearch:7.9.2
    healthcheck:
      test: ["CMD-SHELL", "curl --silent --fail localhost:9200/_cluster/health || exit 1"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 40s
    environment:
      discovery.type: single-node
    ulimits:
      memlock:
        soft: -1
        hard: -1

  skywalking-oap:
    image: apache/skywalking-oap-server:8.6.0-es7
    depends_on:
    - elasticsearch
    environment:
      SW_STORAGE: elasticsearch7
      SW_STORAGE_ES_CLUSTER_NODES: elasticsearch:9200
    healthcheck:
      test: ["CMD-SHELL", "/skywalking/bin/swctl"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 40s
    restart: on-failure

  skywalking-ui:
    image: apache/skywalking-ui:8.6.0
    depends_on:
    - skywalking-oap
    ports:
    - 8080:8080
    environment:
      SW_OAP_ADDRESS: skywalking-oap:12800
