From a7af74e7db8833365ee1e7a9d0898c1497621b4e Mon Sep 17 00:00:00 2001 From: blazSmehov Date: Tue, 25 Nov 2025 15:01:46 +0100 Subject: [PATCH] chore: update docker compose with kafdrop and automatic topic creation --- build/docker-compose.yaml | 50 ++++++++++++++++++ build/docker-compose.yml | 82 ------------------------------ build/init-scripts/create_topic.sh | 16 ++++++ 3 files changed, 66 insertions(+), 82 deletions(-) create mode 100644 build/docker-compose.yaml delete mode 100644 build/docker-compose.yml create mode 100755 build/init-scripts/create_topic.sh diff --git a/build/docker-compose.yaml b/build/docker-compose.yaml new file mode 100644 index 0000000..8b81a93 --- /dev/null +++ b/build/docker-compose.yaml @@ -0,0 +1,50 @@ +version: "2" +services: + kafdrop: + image: obsidiandynamics/kafdrop + restart: "no" + ports: + - "127.0.0.1:9000:9000" + environment: + KAFKA_BROKERCONNECT: "kafka:29092" + depends_on: + - "kafka" + kafka: + image: apache/kafka:3.9.0 + restart: "no" + ports: + # - "127.0.0.1:2181:2181" + - "127.0.0.1:9092:9092" + - "127.0.0.1:9093:9093" + healthcheck: # <-- ADD THIS BLOCK + test: ["CMD-SHELL", "/opt/kafka/bin/kafka-topics.sh --bootstrap-server 127.0.0.1:9092 --list"] + interval: 10s + timeout: 5s + retries: 10 + start_period: 20s + environment: + KAFKA_NODE_ID: 1 + KAFKA_PROCESS_ROLES: broker,controller + KAFKA_LISTENERS: INTERNAL://:29092,EXTERNAL://:9092,CONTROLLER://127.0.0.1:9093 + KAFKA_ADVERTISED_LISTENERS: INTERNAL://kafka:29092,EXTERNAL://localhost:9092 + KAFKA_CONTROLLER_LISTENER_NAMES: CONTROLLER + KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: CONTROLLER:PLAINTEXT,INTERNAL:PLAINTEXT,EXTERNAL:PLAINTEXT + KAFKA_CONTROLLER_QUORUM_VOTERS: 1@127.0.0.1:9093 + KAFKA_INTER_BROKER_LISTENER_NAME: INTERNAL + 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 + KAFKA_NUM_PARTITIONS: 3 + + kafka-init: + image: apache/kafka:3.9.0 + command: [ "/bin/bash", "-c", "chmod +x /tmp/create_topic.sh && /tmp/create_topic.sh"] + depends_on: + kafka: + condition: service_healthy + volumes: + - ./init-scripts/create_topic.sh:/tmp/create_topic.sh + environment: + - TOPIC_NAMES=topic1,topic2,topic3 + diff --git a/build/docker-compose.yml b/build/docker-compose.yml deleted file mode 100644 index 7f27c11..0000000 --- a/build/docker-compose.yml +++ /dev/null @@ -1,82 +0,0 @@ -services: - kafka: - image: apache/kafka:3.9.0 - container_name: kafka - command: - - sh - - -c - - | - CLUSTER_ID=$$(/opt/kafka/bin/kafka-storage.sh random-uuid) - /opt/kafka/bin/kafka-storage.sh format --config /opt/kafka/config/kraft/server.properties --cluster-id $$CLUSTER_ID - /opt/kafka/bin/kafka-server-start.sh /opt/kafka/config/kraft/server.properties & - pid=$! - - # wait until Kafka is actually alive - until /opt/kafka/bin/kafka-topics.sh --bootstrap-server localhost:9092 --list >/dev/null 2>&1; do - sleep 1 - done - - # create topic - /opt/kafka/bin/kafka-topics.sh --bootstrap-server localhost:9092 \ - --create --if-not-exists --topic rawbeacons \ - --partitions 1 --replication-factor 1 - - # mark ready - touch /tmp/ready - - wait $pid - healthcheck: - test: ["CMD-SHELL", "[ -f /tmp/ready ]"] - interval: 3s - timeout: 2s - retries: 20 - ports: - - "127.0.0.1:9092:9092" - - - # presense-decoder: - # build: - # context: ../ - # dockerfile: build/package/Dockerfile.decoder - # image: presense-decoder - # container_name: presense-decoder - # environment: - # - REDIS_URL=valkey:6379 - # - KAFKA_URL=kafka:9092 - # depends_on: - # kafka: - # condition: service_healthy - # restart: always - - # presense-server: - # build: - # context: ../ - # dockerfile: build/package/Dockerfile.server - # image: presense-server - # container_name: presense-server - # environment: - # - REDIS_URL=valkey:6379 - # - KAFKA_URL=kafka:9092 - # depends_on: - # kafka: - # condition: service_healthy - - # ports: - # - "127.0.0.1:1902:1902" - # restart: always - - # presense-bridge: - # build: - # context: ../ - # dockerfile: build/package/Dockerfile.bridge - # image: presense-bridge - # container_name: presense-bridge - # environment: - # - KAFKA_URL=kafka:9092 - # - MQTT_HOST=192.168.1.101:1883 - # - MQTT_USERNAME=user - # - MQTT_PASSWORD=pass - # depends_on: - # kafka: - # condition: service_healthy - # restart: always diff --git a/build/init-scripts/create_topic.sh b/build/init-scripts/create_topic.sh new file mode 100755 index 0000000..e5d57ca --- /dev/null +++ b/build/init-scripts/create_topic.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +# create topic rawbeacons +/opt/kafka/bin/kafka-topics.sh --bootstrap-server kafka:29092 \ +--create --if-not-exists --topic rawbeacons \ +--partitions 1 --replication-factor 1 + +# create topic apibeacons +/opt/kafka/bin/kafka-topics.sh --bootstrap-server kafka:29092 \ +--create --if-not-exists --topic apibeacons \ +--partitions 1 --replication-factor 1 + +# create topic alertBeacons +/opt/kafka/bin/kafka-topics.sh --bootstrap-server kafka:29092 \ +--create --if-not-exists --topic alertbeacons \ +--partitions 1 --replication-factor 1 \ No newline at end of file