[KAFKA] Add docker-compose to sample project
[dmaap/kafka11aaf.git] / sampleClient / src / main / resources / docker-compose / runner.sh
1 #!/bin/bash
2
3 function start {
4   docker compose -f scram-docker-compose.yml up -d
5
6   until [ "$(docker inspect -f {{.State.Running}} broker)" == "true" ]; do
7       sleep 1;
8   done;
9
10   echo -e "\n Creating kafka users"
11   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
12   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
13
14   echo -e "\n Creating test topic"
15   docker exec broker kafka-topics --create --bootstrap-server broker:9092 --replication-factor 1 --partitions 1 --topic test-topic.1 --command-config config.properties
16
17   echo -e "\n Listing existing topics"
18   docker exec broker kafka-topics --list --bootstrap-server localhost:9092 --command-config config.properties
19
20   echo -e "\n Adding broker to /etc/hosts"
21   echo '127.0.0.1 broker' | sudo tee -a /etc/hosts
22 }
23
24
25 function stop {
26
27   docker compose -f scram-docker-compose.yml down
28
29   sudo sed -i.bak '/broker/d' /etc/hosts
30 }
31
32 function publisher {
33     docker exec -it broker kafka-console-producer --bootstrap-server localhost:9092 --topic test-topic.1 --producer.config config.properties
34 }
35
36 showHelp() {
37 cat << EOF
38 Usage: ./runner.sh [start|stop]
39
40 start
41
42 stop
43
44 EOF
45 }
46
47 while true
48 do
49 case "$1" in
50 start)
51     start
52     ;;
53 pub)
54     publisher
55     ;;
56 stop)
57     stop
58     ;;
59 *)
60     showHelp
61     shift
62     break;;
63 esac
64 shift
65 done