version: "3.7"
services:
  pg:
    image: postgres:14.4
    command: "-c wal_level=logical"
    ports:
      - "127.0.0.1:6432:5432"
    environment:
      POSTGRES_PASSWORD: password
  
  dbz:
    image: debezium/server:2.4.2.Final
    # image: debezium/server:2.5.0.Final
    environment:
      - DEBEZIUM_SOURCE_CONNECTOR_CLASS=io.debezium.connector.postgresql.PostgresConnector
      - DEBEZIUM_SOURCE_DATABASE_HOSTNAME=pg
      - DEBEZIUM_SOURCE_DATABASE_PORT=5432
      - DEBEZIUM_SOURCE_DATABASE_USER=postgres
      - DEBEZIUM_SOURCE_DATABASE_PASSWORD=password
      - DEBEZIUM_SOURCE_DATABASE_DBNAME=postgres
      - DEBEZIUM_SOURCE_PLUGIN_NAME=pgoutput
      - DEBEZIUM_SOURCE_TOPIC_PREFIX=local
      - DEBEZIUM_SOURCE_OFFSET_STORAGE_FILE_FILENAME=offset
      - DEBEZIUM_SINK_TYPE=kafka
      - DEBEZIUM_SINK_KAFKA_PRODUCER_BOOTSTRAP_SERVERS=kafka:29092
      - DEBEZIUM_SINK_KAFKA_PRODUCER_KEY_SERIALIZER=org.apache.kafka.common.serialization.StringSerializer
      - DEBEZIUM_SINK_KAFKA_PRODUCER_VALUE_SERIALIZER=org.apache.kafka.common.serialization.StringSerializer
    depends_on:
      - pg
      - kafka

  zookeeper:
    image: confluentinc/cp-zookeeper:7.3.2
    environment:
      ZOOKEEPER_CLIENT_PORT: 2181
      ZOOKEEPER_TICK_TIME: 2000
    ports:
      - 2181:2181

  kafka:
    image: confluentinc/cp-kafka:7.3.2
    hostname: kafka
    depends_on:
      - zookeeper
    ports:
      - 9092:9092
      - 29092:29092
    environment:
      KAFKA_BROKER_ID: 1
      KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
      KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
      KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:29092,PLAINTEXT_HOST://localhost:9092
      KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
      KAFKA_GROUP_INITIAL_REBALANCE_DELAY_MS: 0
      KAFKA_CONFLUENT_LICENSE_TOPIC_REPLICATION_FACTOR: 1
