version: "3.9"

networks:
  default:
    name: roll
    driver: bridge

volumes:
  debugfs:
    driver: local
    driver_opts:
      type: debugfs
      device: debugfs
      o: uid=0,gid=0,mode=755

services:
  kafka:
    depends_on:
      - zookeeper
    image: wurstmeister/kafka:2.12-2.3.1@sha256:0b22bb436ecde11e0db1ce84170b979ce7130e5f1b292b16eace548cd78d7d9e
    restart: on-failure:3
    links:
    - zookeeper
    expose:
      - 9092
    ports:
      - 9092:9092
      - 9093:9093
    environment:
      KAFKA_VERSION: '2.3.1'
      KAFKA_BROKER_ID: '1'
      KAFKA_DELETE_TOPIC_ENABLE: 'true'
      KAFKA_ADVERTISED_HOST_NAME: 'kafka'
      KAFKA_ADVERTISED_PORT: '9092'
      KAFKA_ZOOKEEPER_CONNECT: 'zookeeper:2181'
      KAFKA_AUTO_CREATE_TOPICS_ENABLE: 'true'
      KAFKA_MESSAGE_MAX_BYTES: '200000000'
      KAFKA_LISTENERS: 'PLAINTEXT://:9092,SASL_PLAINTEXT://:9093'
      KAFKA_ADVERTISED_LISTENERS: 'PLAINTEXT://kafka:9092,SASL_PLAINTEXT://kafka:9093'
      KAFKA_SASL_ENABLED_MECHANISMS: 'PLAIN,SCRAM-SHA-256,SCRAM-SHA-512'
      KAFKA_AUTHORIZER_CLASS_NAME: 'kafka.security.auth.SimpleAclAuthorizer'
      KAFKA_ALLOW_EVERYONE_IF_NO_ACL_FOUND: 'true'
      KAFKA_OPTS: "-Djava.security.auth.login.config=/opt/kafka/config/kafka_server_jaas.conf"
      CUSTOM_INIT_SCRIPT: |-
        echo -e 'KafkaServer {\norg.apache.kafka.common.security.scram.ScramLoginModule required\n username="adminscram"\n password="admin-secret";\n org.apache.kafka.common.security.plain.PlainLoginModule required\n username="adminplain"\n password="admin-secret"\n user_adminplain="admin-secret";\n  };' > /opt/kafka/config/kafka_server_jaas.conf;
        /opt/kafka/bin/kafka-configs.sh --zookeeper zookeeper:2181 --alter --add-config 'SCRAM-SHA-256=[password=admin-secret-256],SCRAM-SHA-512=[password=admin-secret-512]' --entity-type users --entity-name adminscram
    healthcheck:
      test: ["CMD", "kafka-topics.sh", "--list", "--zookeeper", "zookeeper:2181"]
      interval: 5s
      timeout: 10s
      retries: 5
  
  zookeeper:
    image: wurstmeister/zookeeper@sha256:7a7fd44a72104bfbd24a77844bad5fabc86485b036f988ea927d1780782a6680
    expose:
      - "2181"
    ports:
      - 2181:2181

  kafkaproducer:
    depends_on:
      kafka:
        condition: service_healthy
    build:
      context: ./producer
      dockerfile: ../Dockerfile
      args:
        BINARY_NAME: producer
    pid: "host"
    ports:
      - "8080:8080"
    volumes:
      - /proc:/host/proc

  kafkaconsumer:
    depends_on:
      kafka:
        condition: service_healthy
    build:
      context: ./consumer
      dockerfile: ../Dockerfile
      args:
        BINARY_NAME: consumer
    pid: "host"
    volumes:
      - /proc:/host/proc

  go-auto-producer:
    depends_on:
      - kafkaproducer
    build:
      context: ../..
      dockerfile: Dockerfile
    privileged: true
    pid: "host"
    environment:
      - OTEL_EXPORTER_OTLP_ENDPOINT=http://jaeger:4318
      - OTEL_GO_AUTO_TARGET_EXE=/app/producer
      - OTEL_SERVICE_NAME=kafkaproducer
      - OTEL_PROPAGATORS=tracecontext,baggage
      - OTEL_GO_AUTO_SHOW_VERIFIER_LOG=true
    volumes:
      - /proc:/host/proc
      - debugfs:/sys/kernel/debug
    command: ["/otel-go-instrumentation", "-global-impl"]

  go-auto-consumer:
    depends_on:
      - kafkaconsumer
    build:
      context: ../..
      dockerfile: Dockerfile
    privileged: true
    pid: "host"
    environment:
      - OTEL_EXPORTER_OTLP_ENDPOINT=http://jaeger:4318
      - OTEL_GO_AUTO_TARGET_EXE=/app/consumer
      - OTEL_SERVICE_NAME=kkafkaconsumer
      - OTEL_PROPAGATORS=tracecontext,baggage
      - OTEL_GO_AUTO_SHOW_VERIFIER_LOG=true
    volumes:
      - /proc:/host/proc
      - debugfs:/sys/kernel/debug
    command: ["/otel-go-instrumentation", "-global-impl"]

  jaeger:
    image: jaegertracing/all-in-one:1.60@sha256:4fd2d70fa347d6a47e79fcb06b1c177e6079f92cba88b083153d56263082135e
    ports:
      - "16686:16686"
      - "14268:14268"
    environment:
      - COLLECTOR_OTLP_ENABLED=true
      - LOG_LEVEL=debug
    deploy:
      resources:
        limits:
          memory: 300M
    restart: unless-stopped
