Skip to content

Commit a6b6104

Browse files
tchronoedsiper
authored andcommitted
doc: simplify running the example with docker-compose
Signed-off-by: Thiago Padilha <[email protected]>
1 parent 637c57c commit a6b6104

File tree

16 files changed

+181
-94
lines changed

16 files changed

+181
-94
lines changed

examples/kafka_filter/.env

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
KAFKA_HOST=kafka-broker
2+
KAFKA_PORT=9092
3+
ZOOKEEPER_HOST=zookeeper
4+
ZOOKEEPER_PORT=2181

examples/kafka_filter/Dockerfile

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
FROM debian:bullseye-slim as builder
2+
ENV DEBIAN_FRONTEND noninteractive
3+
ENV KAFKA_URL https://dlcdn.apache.org/kafka/3.0.0/kafka_2.13-3.0.0.tgz
4+
ENV KAFKA_SHA256 a82728166bbccf406009747a25e1fe52dbcb4d575e4a7a8616429b5818cd02d1
5+
6+
# hadolint ignore=DL3008
7+
RUN apt-get update && \
8+
apt-get upgrade -y && \
9+
apt-get install -y --no-install-recommends \
10+
build-essential \
11+
curl \
12+
ca-certificates \
13+
cmake \
14+
pkg-config \
15+
libsasl2-dev \
16+
flex \
17+
openjdk-11-jre-headless \
18+
bison \
19+
netcat-openbsd \
20+
&& apt-get clean \
21+
&& rm -rf /var/lib/apt/lists/*
22+
23+
# Download kafka to access "kafka-topics" script
24+
WORKDIR /kafka
25+
RUN bash -c 'curl -L $KAFKA_URL | tee kafka.tgz | sha256sum -c <(echo "$KAFKA_SHA256 -")' \
26+
&& tar --strip-components=1 -xf kafka.tgz \
27+
&& mv /kafka/bin/kafka-topics.sh /kafka/bin/kafka-topics
28+
ENV PATH="${PATH}:/kafka/bin"
29+
30+
WORKDIR /build/
31+
COPY . /source
32+
RUN cmake -DFLB_DEV=On \
33+
-DFLB_IN_KAFKA=On \
34+
-DFLB_OUT_KAFKA=On \
35+
/source && \
36+
make -j "$(getconf _NPROCESSORS_ONLN)"
37+
38+
FROM builder as runner
39+
COPY --from=builder /build/bin/fluent-bit /usr/local/bin/fluent-bit
40+
COPY examples/kafka_filter/kafka.conf /etc/kafka.conf
41+
COPY examples/kafka_filter/kafka.lua /etc/kafka.lua
42+
CMD ["/usr/local/bin/fluent-bit", "-c", "/etc/kafka.conf"]

examples/kafka_filter/Makefile

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,11 @@
1-
CPU_COUNT := $(shell grep -c ^processor /proc/cpuinfo)
1+
build:
2+
docker-compose build
23

3-
KAFKA_TGT = kafka/done.stamp
4-
KAFKA_DIR = $(shell dirname $(KAFKA_TGT))
5-
CMAKE_TGT = build/done.stamp
6-
FLB_TGT = build/bin/fluent-bit
4+
start:
5+
docker-compose up -d
6+
docker-compose logs -f fluent-bit kafka-consumer
77

8-
run: $(KAFKA_TGT) $(FLB_TGT)
9-
./kafka-start.sh $(KAFKA_DIR) && tmux a
8+
stop:
9+
docker-compose down
1010

11-
$(FLB_TGT): $(CMAKE_TGT)
12-
make -C build -j$(CPU_COUNT)
13-
14-
$(CMAKE_TGT):
15-
rm -rf build
16-
mkdir -pv build
17-
cd build && cmake -DFLB_DEV=On -DFLB_IN_KAFKA=On -DFLB_OUT_KAFKA=On ../../..
18-
touch $@
19-
20-
$(KAFKA_TGT):
21-
rm -rf $(KAFKA_DIR)
22-
./kafka-setup.sh $(KAFKA_DIR)
23-
touch $@
24-
25-
.PHONY: run
11+
.PHONY: build start stop

examples/kafka_filter/README.md

Lines changed: 0 additions & 4 deletions
This file was deleted.

examples/kafka_filter/common.sh

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
version: '3.4'
2+
3+
x-service-common-fields: &service-common-fields
4+
volumes:
5+
- ./scripts:/scripts
6+
env_file:
7+
- ./.env
8+
9+
10+
services:
11+
fluent-bit:
12+
<<: *service-common-fields
13+
build:
14+
context: ../..
15+
target: runner
16+
dockerfile: examples/kafka_filter/Dockerfile
17+
command: /scripts/flb-start.sh
18+
depends_on:
19+
- kafka-consumer
20+
21+
22+
kafka-create-topics:
23+
<<: *service-common-fields
24+
image: confluentinc/cp-server:7.0.1
25+
command: /scripts/create-topics.sh
26+
depends_on:
27+
- kafka-broker
28+
29+
30+
kafka-producer:
31+
<<: *service-common-fields
32+
image: confluentinc/cp-server:7.0.1
33+
command: /scripts/kafka-produce.sh
34+
depends_on:
35+
- fluent-bit
36+
37+
38+
kafka-consumer:
39+
<<: *service-common-fields
40+
image: confluentinc/cp-server:7.0.1
41+
command: /scripts/kafka-consume.sh
42+
depends_on:
43+
- kafka-create-topics
44+
45+
46+
kafka-broker:
47+
image: confluentinc/cp-server:7.0.1
48+
hostname: broker
49+
container_name: kafka-broker
50+
depends_on:
51+
- zookeeper
52+
environment:
53+
KAFKA_BROKER_ID: 1
54+
KAFKA_ZOOKEEPER_CONNECT: "${ZOOKEEPER_HOST}:${ZOOKEEPER_PORT}"
55+
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: "PLAINTEXT:PLAINTEXT"
56+
KAFKA_ADVERTISED_LISTENERS: "PLAINTEXT://${KAFKA_HOST}:${KAFKA_PORT}"
57+
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
58+
KAFKA_GROUP_INITIAL_REBALANCE_DELAY_MS: 0
59+
KAFKA_CONFLUENT_LICENSE_TOPIC_REPLICATION_FACTOR: 1
60+
61+
62+
zookeeper:
63+
image: confluentinc/cp-zookeeper:7.0.1
64+
hostname: zookeeper
65+
container_name: zookeeper
66+
environment:
67+
ZOOKEEPER_CLIENT_PORT: "${ZOOKEEPER_PORT}"
68+
ZOOKEEPER_TICK_TIME: 2000

examples/kafka_filter/example-data.json

Lines changed: 0 additions & 5 deletions
This file was deleted.

examples/kafka_filter/kafka-setup.sh

Lines changed: 0 additions & 24 deletions
This file was deleted.

examples/kafka_filter/kafka-start.sh

Lines changed: 0 additions & 30 deletions
This file was deleted.

examples/kafka_filter/kafka.conf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
[INPUT]
77
Name kafka
8-
brokers localhost:9092
8+
brokers kafka-broker:9092
99
topics fb-source
1010

1111
[FILTER]
@@ -16,5 +16,5 @@
1616

1717
[OUTPUT]
1818
Name kafka
19-
brokers localhost:9092
19+
brokers kafka-broker:9092
2020
topics fb-sink

0 commit comments

Comments
 (0)