name: rtgs

# 로컬 경량 스택 (1센터 DC1). acs와 포트/프로젝트명(-p rtgs 자동: name=rtgs) 분리.
# 서비스(Sequencer/Chanel/Dior/Hermes/Prada)는 호스트에서 gradlew bootRun으로 구동하며
# 아래 인프라(localhost:9092/5433/27017)에 접속한다.

services:
  postgres:
    image: postgres:16
    container_name: rtgs-postgres
    environment:
      POSTGRES_DB: rtgs
      POSTGRES_USER: rtgs
      POSTGRES_PASSWORD: rtgs
    ports:
      - "5433:5432"          # acs=5432 회피
    volumes:
      - pgdata:/var/lib/postgresql/data
      - ./init/postgres-init.sql:/docker-entrypoint-initdb.d/01-init.sql:ro
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U rtgs -d rtgs"]
      interval: 5s
      timeout: 3s
      retries: 20

  mongo:
    image: mongo:7
    container_name: rtgs-mongo
    ports:
      - "27017:27017"
    volumes:
      - mongodata:/data/db

  kafka:
    image: apache/kafka:3.8.1
    container_name: rtgs-kafka
    ports:
      - "9092:9092"
    environment:
      # --- KRaft 단일 노드(broker+controller) ---
      KAFKA_NODE_ID: "1"
      KAFKA_PROCESS_ROLES: "broker,controller"
      KAFKA_CONTROLLER_QUORUM_VOTERS: "1@localhost:9093"
      # HOST(호스트의 gradle bootRun) / DOCKER(컨테이너 내 kafka-ui) 이중 리스너
      KAFKA_LISTENERS: "HOST://:9092,DOCKER://:29092,CONTROLLER://:9093"
      KAFKA_ADVERTISED_LISTENERS: "HOST://localhost:9092,DOCKER://kafka:29092"
      KAFKA_CONTROLLER_LISTENER_NAMES: "CONTROLLER"
      KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: "CONTROLLER:PLAINTEXT,HOST:PLAINTEXT,DOCKER:PLAINTEXT"
      KAFKA_INTER_BROKER_LISTENER_NAME: "DOCKER"
      # --- 단일 노드 복제/ISR ---
      KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: "1"
      KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: "1"
      KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: "1"
      KAFKA_GROUP_INITIAL_REBALANCE_DELAY_MS: "0"
      # --- 저널 전역 순서 보장: 기본 파티션 1개(단일 파티션이라야 전역 순서 성립) ---
      KAFKA_NUM_PARTITIONS: "1"
      KAFKA_AUTO_CREATE_TOPICS_ENABLE: "true"

  # 선택: Kafka 관리 UI (docker compose --profile ui up)
  kafka-ui:
    image: provectuslabs/kafka-ui:latest
    container_name: rtgs-kafka-ui
    profiles: ["ui"]
    ports:
      - "8095:8080"
    environment:
      KAFKA_CLUSTERS_0_NAME: rtgs
      KAFKA_CLUSTERS_0_BOOTSTRAPSERVERS: kafka:29092
    depends_on:
      - kafka

volumes:
  pgdata:
  mongodata:
