summaryrefslogtreecommitdiffstats
path: root/sampleClient/src/main/resources/docker-compose/runner.sh
blob: 2a188b12c6a768a5d9f893506785a387d98735a8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/bin/bash

function start {
  docker compose -f scram-docker-compose.yml up -d

  until [ "$(docker inspect -f {{.State.Running}} broker)" == "true" ]; do
      sleep 1;
  done;

  echo -e "\n Creating kafka users"
  docker exec broker kafka-configs --zookeeper zookeeper:2181 --alter --add-config 'SCRAM-SHA-256=[password=broker],SCRAM-SHA-512=[password=broker]' --entity-type users --entity-name broker
  docker exec broker kafka-configs --zookeeper zookeeper:2181 --alter --add-config 'SCRAM-SHA-256=[password=client-secret],SCRAM-SHA-512=[password=client-secret]' --entity-type users --entity-name client

  echo -e "\n Creating test topic"
  docker exec broker kafka-topics --create --bootstrap-server broker:9092 --replication-factor 1 --partitions 1 --topic test-topic.1 --command-config config.properties

  echo -e "\n Listing existing topics"
  docker exec broker kafka-topics --list --bootstrap-server localhost:9092 --command-config config.properties

  echo -e "\n Adding broker to /etc/hosts"
  echo '127.0.0.1 broker' | sudo tee -a /etc/hosts
}


function stop {

  docker compose -f scram-docker-compose.yml down

  sudo sed -i.bak '/broker/d' /etc/hosts
}

function publisher {
    docker exec -it broker kafka-console-producer --bootstrap-server localhost:9092 --topic test-topic.1 --producer.config config.properties
}

showHelp() {
cat << EOF
Usage: ./runner.sh [start|stop]

start

stop

EOF
}

while true
do
case "$1" in
start)
    start
    ;;
pub)
    publisher
    ;;
stop)
    stop
    ;;
*)
    showHelp
    shift
    break;;
esac
shift
done