volumes:
  prometheus_data: {}
  grafana_data: {}
  shard1-data: {}
  shard2-data: {}

services:
  # cart:
  #   build:
  #     context: .
  #     dockerfile: cart/Dockerfile
  #   ports:
  #     - "8080:8080"
  #   depends_on:
  #     - product-service

  # product-service:
  #   image: gitlab-registry.ozon.dev/go/classroom-18/students/homework-draft/products:latest
  #   ports:
  #     - "8082:8082"

  # loms:
  #   build: 
  #     context: .
  #     dockerfile: loms/Dockerfile
  #   depends_on:
  #     postgres-master:
  #       condition: service_started
  #     init-kafka:
  #       condition: service_completed_successfully
  #   ports:
  #     - "8083:8083"
  #     - "8084:8084"
  #     - "8085:8085"

  # notifier:
  #   build:
  #     context: .
  #     dockerfile: notifier/Dockerfile
  #   depends_on:
  #     init-kafka:
  #       condition: service_completed_successfully
  #   deploy:
  #     replicas: 3

  # comments:
  #   build: 
  #     context: .
  #     dockerfile: comments/Dockerfile
  #   depends_on:
  #     postgres-comments-shard-1:
  #       condition: service_started
  #     postgres-comments-shard-2:  
  #       condition: service_started
  #   ports:
  #     - "8083:8083"
  #     - "8084:8084"
  #     - "8085:8085"

  postgres-master:
    image: gitlab-registry.ozon.dev/go/classroom-18/students/base/postgres:16
    container_name: postgres-master
    environment:
      - POSTGRESQL_USERNAME=user
      - POSTGRESQL_PASSWORD=password
      - POSTGRESQL_DATABASE=route256
      - POSTGRESQL_REPLICATION_MODE=master
      - POSTGRESQL_REPLICATION_USER=repl_user
      - POSTGRESQL_REPLICATION_PASSWORD=repl_password
      - POSTGRESQL_SYNCHRONOUS_COMMIT_MODE=on
      - POSTGRESQL_NUM_SYNCHRONOUS_REPLICAS=1
    ports:
      - "5433:5432"

  postgres-replica:
    image: gitlab-registry.ozon.dev/go/classroom-18/students/base/postgres:16
    container_name: postgres-replica
    depends_on:
      - postgres-master
    environment:
      - POSTGRESQL_DATABASE=route256
      - POSTGRESQL_USERNAME=user
      - POSTGRESQL_PASSWORD=password
      - POSTGRESQL_REPLICATION_MODE=slave
      - POSTGRESQL_REPLICATION_USER=repl_user
      - POSTGRESQL_REPLICATION_PASSWORD=repl_password
      - POSTGRESQL_MASTER_HOST=postgres-master
      - POSTGRESQL_MASTER_PORT_NUMBER=5432
      - POSTGRESQL_SYNCHRONOUS_COMMIT_MODE=on
      - POSTGRESQL_NUM_SYNCHRONOUS_REPLICAS=1
    ports:
      - "5434:5432"

  postgres-comments-shard-1:
    image: gitlab-registry.ozon.dev/go/classroom-18/students/base/postgres:16
    environment:
      POSTGRES_DB: comments_db
      POSTGRES_USER: comments-user-1
      POSTGRES_PASSWORD: comments-password-1
    ports:
      - "5438:5432"
    volumes:
      - shard1-data:/var/lib/postgresql/data

  postgres-comments-shard-2:
    image: gitlab-registry.ozon.dev/go/classroom-18/students/base/postgres:16
    environment:
      POSTGRES_DB: comments_db
      POSTGRES_USER: comments-user-2
      POSTGRES_PASSWORD: comments-password-2
    ports:
      - "5439:5432"
    volumes:
      - shard2-data:/var/lib/postgresql/data

  kafka-ui:
    container_name: kafka-ui
    image: provectuslabs/kafka-ui:latest
    ports:
      - 8095:8080
    environment:
      KAFKA_CLUSTERS_0_NAME: local
      KAFKA_CLUSTERS_0_BOOTSTRAPSERVERS: kafka0:29092
      DYNAMIC_CONFIG_ENABLED: "true"

  kafka0:
    container_name: kafka
    image: confluentinc/cp-kafka:7.7.1.arm64
    ports:
      - 9092:9092
    expose:
      - '29092'
    environment:
      KAFKA_NODE_ID: 1
      KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,CONTROLLER:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
      KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka0:29092,PLAINTEXT_HOST://localhost:9092
      KAFKA_LISTENERS: PLAINTEXT://kafka0:29092,CONTROLLER://kafka0:29093,PLAINTEXT_HOST://:9092
      KAFKA_CONTROLLER_LISTENER_NAMES: "CONTROLLER"
      KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
      KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: 1
      KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: 1
      KAFKA_CONTROLLER_QUORUM_VOTERS: "1@kafka0:29093"
      KAFKA_PROCESS_ROLES: "broker,controller"
      KAFKA_LOG_DIRS: "/tmp/kraft-combined-logs"
      CLUSTER_ID: 'MkU3OEVBNTcwNTJENDM2Qk'

  init-kafka:
    image: confluentinc/cp-kafka:7.7.1.arm64
    depends_on:
      - kafka0
    entrypoint: [ '/bin/sh', '-c' ]
    command: |
      "
      # blocks until kafka is reachable
      kafka-topics --bootstrap-server kafka:29092 --list

      echo -e 'Creating kafka topics'
      kafka-topics --create --topic loms.order-events --bootstrap-server kafka:29092 --partitions 2 --replication-factor 1

      echo -e 'Successfully created the following topics:'
      kafka-topics --bootstrap-server kafka:29092 --list
      "

  prometheus:
    image: prom/prometheus:latest
    volumes:
      - ./prometheus/:/etc/prometheus/
      - prometheus_data:/prometheus
    command:
      - '--config.file=/etc/prometheus/prometheus.yml'
      - '--storage.tsdb.path=/prometheus'
      - '--web.console.libraries=/usr/share/prometheus/console_libraries'
      - '--web.console.templates=/usr/share/prometheus/consoles'
    ports:
      - "9090:9090"

  grafana:
    image: grafana/grafana:latest
    volumes:
      - grafana_data:/var/lib/grafana
    ports:
      - "3000:3000"

  jaeger:
    image: jaegertracing/all-in-one:latest
    ports:
      - "16686:16686"
      - "4318:4318"
