From 9cea0e7df283c7683a342ba49a6ffb7bb2a22f13 Mon Sep 17 00:00:00 2001 From: Sachin Nigam Date: Fri, 29 May 2020 00:06:55 +0530 Subject: [PATCH] Add docker-compose support. Fixes #1 Fix exit by replacing .Fatal with .log --- README.md | 17 +++++++++++++++++ docker-compose-win.yml | 34 ++++++++++++++++++++++++++++++++++ docker-compose.yml | 34 ++++++++++++++++++++++++++++++++++ jobs/number.go | 4 ++-- 4 files changed, 87 insertions(+), 2 deletions(-) create mode 100644 docker-compose-win.yml create mode 100644 docker-compose.yml diff --git a/README.md b/README.md index 0ef55a1..3283728 100644 --- a/README.md +++ b/README.md @@ -95,6 +95,23 @@ type EventData struct { ``` Kafka topics are great for pushing NRT metrices (Near Real Time) to the dashboard. Kafka topic bound widgets can be used to display Time series graphs or volatile values. Mustard already has built-in support for [ApexCharts](https://apexcharts.com/), which can be used for displaying charts. +### Docker compose +There's a docker compose file which exposes kafka listener both internally and externally. On windows, since traffic cannot be routed to linux containers, the kafka listener is exposed as host.docker.internal on the host. The docker-compose for windows is docker-compose-win.yml. + +```shell +$ docker-compose -f ./docker-compose.yml up -d +``` +Please make sure that mustard's env file has the topic you need to listen to (KAFKA_TOPIC) + +The docker compose file uses https://github.com/wurstmeister/kafka-docker/, please refer to the documentation there to troubleshoot connectivity issues. + +On windows, this is how it would potentially work: + +1. Create the topic: +```.\kafka-topics.bat --bootstrap-server host.docker.internal:9094 --topic test --create``` +2. Set the topic name in .env +3. Produce a message: +```.\kafka-console-producer.bat --bootstrap-server host.docker.internal:9094 --topic test``` ### TODO - Create wiki - Drag and drop support diff --git a/docker-compose-win.yml b/docker-compose-win.yml new file mode 100644 index 0000000..af6237d --- /dev/null +++ b/docker-compose-win.yml @@ -0,0 +1,34 @@ +version: '3.2' +services: + zookeeper: + image: wurstmeister/zookeeper + ports: + - "2181:2181" + kafka: + image: wurstmeister/kafka:latest + ports: + - target: 9094 + published: 9094 + protocol: tcp + mode: host + environment: + KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181 + HOSTNAME_COMMAND: "docker info | grep ^Name: | cut -d' ' -f 2" + KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: INSIDE:PLAINTEXT,OUTSIDE:PLAINTEXT + KAFKA_ADVERTISED_LISTENERS: INSIDE://:9092,OUTSIDE://host.docker.internal:9094 + KAFKA_LISTENERS: INSIDE://:9092,OUTSIDE://:9094 + KAFKA_INTER_BROKER_LISTENER_NAME: INSIDE + volumes: + - /var/run/docker.sock:/var/run/docker.sock + depends_on: + - zookeeper + mustard: + build: . + ports: + - "8090:80" + environment: + KAFKA_URL: kafka:9092 + env_file: + - .env + depends_on: + - kafka diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..2a81603 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,34 @@ +version: '3.2' +services: + zookeeper: + image: wurstmeister/zookeeper + ports: + - "2181:2181" + kafka: + image: wurstmeister/kafka:latest + ports: + - target: 9094 + published: 9094 + protocol: tcp + mode: host + environment: + KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181 + HOSTNAME_COMMAND: "docker info | grep ^Name: | cut -d' ' -f 2" + KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: INSIDE:PLAINTEXT,OUTSIDE:PLAINTEXT + KAFKA_ADVERTISED_LISTENERS: INSIDE://:9092,OUTSIDE://_{HOSTNAME_COMMAND}:9094 + KAFKA_LISTENERS: INSIDE://:9092,OUTSIDE://:9094 + KAFKA_INTER_BROKER_LISTENER_NAME: INSIDE + volumes: + - /var/run/docker.sock:/var/run/docker.sock + depends_on: + - zookeeper + mustard: + build: . + ports: + - "8090:80" + environment: + KAFKA_URL: kafka:9092 + env_file: + - .env + depends_on: + - kafka diff --git a/jobs/number.go b/jobs/number.go index 378f60c..403bb19 100644 --- a/jobs/number.go +++ b/jobs/number.go @@ -21,13 +21,13 @@ func init() { now := time.Now() resp, err := http.Get(fmt.Sprintf(numberURL, now.Day())) if err != nil { - log.Fatal(err) + log.Println(err) return } defer resp.Body.Close() text, err := ioutil.ReadAll(resp.Body) if err != nil { - log.Fatal(err) + log.Println(err) return } data := mustardcore.EventData{Event: "clockWidget", Data: number{Trivia: string(text)}}