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:
    - "${PORT_PROXY:-8000}:8000"
    - "${PORT_ADMIN:-8001}:8001"
    depends_on:
    - skywalking-oap

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

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

  # Skywalking components.
  elasticsearch:
    build:
      context: .
      dockerfile: Dockerfile-elasticsearch
    healthcheck:
      test: ["CMD-SHELL", "curl -sf http://localhost:9200/_cluster/health || exit 1"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 40s
    environment:
      discovery.type: single-node
      ingest.geoip.downloader.enabled: "false"
      # NB: This setting is for demo purposes only, you are strongly advised to configure
      #   Elasticsearch with security enabled
      xpack.security.enabled: "false"
    ulimits:
      memlock:
        soft: -1
        hard: -1

  skywalking-oap:
    build:
      context: .
      dockerfile: Dockerfile-skywalking-oap
    depends_on:
      elasticsearch:
        condition: service_healthy
    environment:
      SW_HEALTH_CHECKER: default
      SW_STORAGE: elasticsearch
      SW_STORAGE_ES_CLUSTER_NODES: elasticsearch:9200
    healthcheck:
      test: ["CMD-SHELL", "/skywalking/bin/swctl ch"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 10s
    restart: on-failure

  skywalking-ui:
    build:
      context: .
      dockerfile: Dockerfile-skywalking-ui
    healthcheck:
      test: ["CMD-SHELL", 'curl --silent --fail http://localhost:8080/graphql -X POST -H "Content-Type:application/json" -d "{ \"query\": \"query version { version }\"}" || exit 1']
      interval: 5s
      timeout: 10s
      retries: 10
      start_period: 10s
    depends_on:
      skywalking-oap:
        condition: service_healthy
    ports:
    - "${PORT_UI:-8080}:8080"
    environment:
      SW_OAP_ADDRESS: http://skywalking-oap:12800
      SW_HEALTH_CHECKER: default

  started:
    image: hello-world:latest
    depends_on:
      skywalking-ui:
        condition: service_healthy
