name: clever_micro
services:

  rabbitmq: # copied from cleverdata backend branch feat/#190
    image: rabbitmq:3-management
    hostname: "my-rabbit"
    environment:
      RABBITMQ_DEFAULT_USER: springuser
      RABBITMQ_DEFAULT_PASS: TheCleverWho
    volumes:
      - "./container-data/rabbitmq/enabled_plugins:/etc/rabbitmq/enabled_plugins"
    #      - "./container-data/mq-data:/var/lib/rabbitmq"
    ports:
      - "5672:5672"
      - "8888:15672"
    healthcheck:
      test: ["CMD-SHELL", "rabbitmq-diagnostics -q ping"]
      interval: 30s
      timeout: 10s
      retries: 3

  traefik:
    image: "traefik:v3.2"
    container_name: "traefik"
    command:
      - "--api.insecure=true"
      - "--providers.docker=true"
      - "--providers.docker.exposedbydefault=false"
      - "--entryPoints.web.address=:8085"
    labels:
      - "traefik.enable=true"
    ports:
      - "8085:8085"
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock:ro"

  jaeger:
    image: "jaegertracing/all-in-one:latest"
    ports:
      - "16686:16686"  # Jaeger UI
      - "14268:14268"  # Jaeger collector Accepts jaeger.thrift spans directly over HTTP
      - "14250:14250"  # Jaeger gRPC Accepts model.proto spans over gRPC
      - "6831:6831/udp"  # Jaeger agent Accepts jaeger.thrift spans (Thrift compact)
      - "6832:6832/udp"  # Jaeger agent Accepts jaeger.thrift spans (Thrift binary)
      - "5778:5778"    # Jaeger agent admin + configuration
      - "4317:4317"    # OpenTelemetry Protocol (OTLP) gRPC receiver
      - "4318:4318"    # OpenTelemetry Protocol (OTLP) HTTP/protobuf receiver
      - "14269:14269"  # Jaeger health check
      - "9411:9411"    # Zipkin compatibility
    environment:
      COLLECTOR_ZIPKIN_HTTP_PORT: 9411
      COLLECTOR_OTLP_ENABLED: true

  amqp-router:
    build:
      context: .
      dockerfile: Dockerfile
    #  dockerfile: Dockerfile.amqp-adapter
    #image: "amq-python:latest"
    image: "amqp_router:latest"
    ports:
      - "${AMQ_ADAPTER_PORT:-8081}:8080"
    environment:
      cm.amq-adapter.service-name: "amq-router"
      cm.amq-adapter.is-router: "true"
      cm.amq-adapter.generator-id: 164
      cm.amq-adapter.route-mapping: "null"

      cm.dispatch.use-dlq: true
      cm.dispatch.use-confirms: false
      cm.dispatch.amq-host: rabbitmq
      cm.dispatch.amq-port: 5672
      cm.dispatch.amq-port-tls: 5671

      cm.backpressure.threshold: 20
      cm.backpressure.time-window: 3000
      cm.backpressure.management-service-url: "management-service:8080"
      quarkus.otel.exporter.otlp.endpoint: "http://jaeger:4317"
      quarkus.application.name: API-Gateway-AMQ-Adapter
      quarkus.otel.service.name: API-Gateway-AMQ-Adapter
    env_file:
      - .env_secrets
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.router-app.rule=PathPrefix(`/`)"  # default route
      - "traefik.http.routers.router-app.entrypoints=web"
    depends_on:
      rabbitmq:
        condition: service_healthy
    healthcheck:
      test: ["CMD-SHELL", "curl http://localhost:8080/amq-adapter-healthcheck"]
      interval: 30s
      timeout: 10s
      retries: 3

  #
  # DLQ is special case of AMQ adapter that will handle rejected messages
  #
  dead-letter-queue-handler:
    image: "amqp_router:latest"
    ports:
      - "${DLQ_ADAPTER_PORT:-8089}:8080"
    environment:

      cm.amq-adapter.service-name: "amq-dlq"
      cm.amq-adapter.is-router: "false"
      cm.amq-adapter.generator-id: 165
      cm.amq-adapter.route-mapping: "amq-dlq:DLX:DeadLetterQueue:#:0:0"

      cm.dispatch.use-dlq: false
      cm.dispatch.use-confirms: false
      cm.dispatch.amq-host: rabbitmq
      cm.dispatch.amq-port: 5672
      cm.dispatch.amq-port-tls: 5671

      cm.backpressure.threshold: 20
      cm.backpressure.time-window: 3000
      cm.backpressure.management-service-url: "management-service:8080"
      quarkus.application.name: AMQ-DeadLetterQueue
      quarkus.otel.exporter.otlp.endpoint: "http://jaeger:4317"
      OTEL_EXPORTER_OTLP_ENDPOINT: "http://jaeger:4317"
    env_file:
      - .env_secrets
    depends_on:
      amqp-router:
        condition: service_healthy
  #
  # test applications
  #
  amq-clever-book:
    image: "amqp_router:latest"
    ports:
      - "16000:8080"
    environment:

      cm.amq-adapter.service-name: "amq-cleverbook-adapter"
      cm.amq-adapter.generator-id: 16
      cm.amq-adapter.route-mapping: "amq-clever-book::amq-clever-book:clever.book.localhost.#:5:0"

      cm.dispatch.use-dlq: true
      cm.dispatch.use-confirms: false
      cm.dispatch.amq-host: rabbitmq
      cm.dispatch.amq-port: 5672
      cm.dispatch.amq-port-tls: 5671
      cm.dispatch.service-host: clever-book
      cm.dispatch.service-port: 8080

      cm.backpressure.threshold: 20
      cm.backpressure.time-window: 3000
      cm.backpressure.management-service-url: "management-service:8080"
      quarkus.otel.service.name: CleverBook-AMQ-Adapter
      quarkus.application.name: CleverBook-AMQ-Adapter
      quarkus.otel.exporter.otlp.endpoint: "http://jaeger:4317"
      OTEL_EXPORTER_OTLP_ENDPOINT: "http://jaeger:4317"
    env_file:
      - .env_secrets
    depends_on:
      amqp-router:
        condition: service_healthy

  #
  # Dummy app allowing POST and GET operations over REST API, emulating a real SpringBoot service
  #
  clever-book:
    build:
      context: clever-book/
      dockerfile: Dockerfile
    image: "book-management:latest"
    ports:
      - "16002:8080"
    restart: on-failure
    environment:
      SPRING_PROFILES_ACTIVE: prod
      SPRING_APPLICATION_NAME: CleverBook
      spring.application.name: CleverBook
      OTEL_EXPORTER_OTLP_ENDPOINT: "http://jaeger:4317"
      otel.exporter.otlp.endpoint: "http://jaeger:4317"
    env_file:
      - .env_secrets
    depends_on:
      amqp-router:
        condition: service_healthy

  #
  # a black box 3rd party app provisioned as-is
  #
  black-box-3rd-party:
    image: "traefik/whoami"
    container_name: "blackbox-third-party"
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.whoami.rule=Host(`whoami.localhost`)"
      - "traefik.http.routers.whoami.entrypoints=web"

  #
  # test applications for python
  #
  amq-clever-pybook:
    image: "amq-python:latest"
    # image: "amqp_router:latest"
    ports:
      - "16020:8080"
    environment:

      cm.amq-adapter.service-name: "amq-cleverpybook-adapter"
      cm.amq-adapter.generator-id: 211
      cm.amq-adapter.route-mapping: "amq-clever-pybook::amq-clever-pybook:clever.pybook.localhost.#:5:0"

      cm.dispatch.use-dlq: true
      cm.dispatch.use-confirms: false
      cm.dispatch.amq-host: rabbitmq
      cm.dispatch.amq-port: 5672
      cm.dispatch.amq-port-tls: 5671
      cm.dispatch.service-host: clever-pybook
      cm.dispatch.service-port: 5000

      cm.backpressure.threshold: 20
      cm.backpressure.time-window: 3000
      cm.backpressure.management-service-url: "management-service:8080"
      quarkus.otel.service.name: CleverPyBook-AMQ-Adapter
      quarkus.application.name: CleverPyBook-AMQ-Adapter
      quarkus.otel.exporter.otlp.endpoint: "http://jaeger:4317"
      OTEL_EXPORTER_OTLP_ENDPOINT: "http://jaeger:4317"
    env_file:
      - .env_secrets
    depends_on:
      amqp-router:
        condition: service_healthy

  #
  # Dummy app allowing POST and GET operations over REST API, emulating a real SpringBoot service
  #
  clever-pybook:
    image: "clever-pybook:latest"
    ports:
      - "16012:5000"
    restart: on-failure
    environment:
      OTEL_EXPORTER_OTLP_ENDPOINT: "http://jaeger:4317"
      OTEL_EXPORTER_OTLP_INSECURE: "true"
    depends_on:
      amqp-router:
        condition: service_healthy

