Skip to content

Commit 891c095

Browse files
committed
Fixes the docker-compse.yaml of ksql and adds a dockerfile in the ksqldb-cli directory to run the cli on an arm machine
1 parent b844687 commit 891c095

File tree

3 files changed

+96
-5
lines changed

3 files changed

+96
-5
lines changed

ksql/docker-compose.yaml

+11-5
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
---
2-
version: '2'
2+
version: '3'
33

44
services:
55
zookeeper:
66
image: confluentinc/cp-zookeeper:7.3.0
77
hostname: zookeeper
88
container_name: zookeeper
9+
restart: on-failure
910
ports:
1011
- "2181:2181"
1112
environment:
1213
ZOOKEEPER_CLIENT_PORT: 2181
1314
ZOOKEEPER_TICK_TIME: 2000
14-
1515
broker:
1616
image: confluentinc/cp-kafka:7.3.0
1717
hostname: broker
1818
container_name: broker
19+
restart: on-failure
1920
depends_on:
2021
- zookeeper
2122
ports:
@@ -29,11 +30,11 @@ services:
2930
KAFKA_GROUP_INITIAL_REBALANCE_DELAY_MS: 0
3031
KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: 1
3132
KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: 1
32-
3333
ksqldb-server:
3434
image: confluentinc/cp-ksqldb-server:latest
3535
hostname: ksqldb-server
3636
container_name: ksqldb-server
37+
restart: on-failure
3738
depends_on:
3839
- broker
3940
ports:
@@ -43,11 +44,16 @@ services:
4344
KSQL_BOOTSTRAP_SERVERS: broker:9092
4445
KSQL_KSQL_LOGGING_PROCESSING_STREAM_AUTO_CREATE: "true"
4546
KSQL_KSQL_LOGGING_PROCESSING_TOPIC_AUTO_CREATE: "true"
46-
4747
ksqldb-cli:
48-
image: confluentinc/cp-ksqldb-cli:latest
48+
# ksqldb-cli does not provide an arm image, and cp-ksqldb-cli does not work as expected
49+
# image: confluentinc/ksqldb-cli:latest
50+
build:
51+
context: ksqldb-cli
52+
dockerfile: Dockerfile
4953
container_name: ksqldb-cli
54+
restart: on-failure
5055
depends_on:
5156
- broker
5257
- ksqldb-server
5358
entrypoint: /bin/sh
59+
tty: true

ksql/ksqldb-cli/Dockerfile

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM debian
2+
3+
RUN apt update
4+
5+
RUN apt install -y default-jre
6+
RUN apt install -y software-properties-common curl gnupg
7+
8+
RUN curl -sq http://ksqldb-packages.s3.amazonaws.com/deb/0.28/archive.key | apt-key add -
9+
10+
RUN add-apt-repository "deb http://ksqldb-packages.s3.amazonaws.com/deb/0.28 stable main"
11+
RUN apt update
12+
13+
RUN apt install confluent-ksqldb

ksql/readme.md

+72
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,85 @@
11
# KSQL
22

3+
Spaws a kafka cluster including zookeeper and a ksqldb server. The traditional ksqldb-cli images is replaced with an own image as the traditional ksqldb-cli does not provide an arm image.
4+
35
```
46
docker-compose up
57
```
68

9+
After the containers of the docker-compose file are started, the following command can be used run the ksqldb client of the ksqldb-client container.
10+
711
```
812
docker exec -it ksqldb-cli ksql http://ksqldb-server:8088
913
```
1014

15+
## Setup Instructions
16+
1117
https://github.com/confluentinc/ksql
1218

1319
https://ksqldb.io/quickstart.html
20+
21+
## KSQL-CLI Image
22+
23+
https://hub.docker.com/_/debian
24+
25+
https://stackoverflow.com/questions/46032392/docker-compose-does-not-allow-to-use-local-images
26+
27+
https://docs.ksqldb.io/en/latest/operate-and-deploy/installation/install-ksqldb-with-docker/#connect-ksqldb-cli-to-a-dockerized-ksqldb-server
28+
29+
## KSQL Demo
30+
31+
```
32+
CREATE STREAM riderLocations (profileId VARCHAR, latitude DOUBLE, longitude DOUBLE) WITH (kafka_topic='locations', value_format='json', partitions=1);
33+
```
34+
35+
```
36+
CREATE TABLE currentLocation AS
37+
SELECT profileId,
38+
LATEST_BY_OFFSET(latitude) AS la,
39+
LATEST_BY_OFFSET(longitude) AS lo
40+
FROM riderlocations
41+
GROUP BY profileId
42+
EMIT CHANGES;
43+
```
44+
45+
```
46+
CREATE TABLE ridersNearMountainView AS
47+
SELECT ROUND(GEO_DISTANCE(la, lo, 37.4133, -122.1162), -1) AS distanceInMiles,
48+
COLLECT_LIST(profileId) AS riders,
49+
COUNT(*) AS count
50+
FROM currentLocation
51+
GROUP BY ROUND(GEO_DISTANCE(la, lo, 37.4133, -122.1162), -1);
52+
```
53+
54+
```
55+
-- Mountain View lat, long: 37.4133, -122.1162
56+
SELECT * FROM riderLocations
57+
WHERE GEO_DISTANCE(latitude, longitude, 37.4133, -122.1162) <= 5 EMIT CHANGES;
58+
```
59+
60+
```
61+
INSERT INTO riderLocations (profileId, latitude, longitude) VALUES ('c2309eec', 37.7877, -122.4205);
62+
INSERT INTO riderLocations (profileId, latitude, longitude) VALUES ('18f4ea86', 37.3903, -122.0643);
63+
INSERT INTO riderLocations (profileId, latitude, longitude) VALUES ('4ab5cbad', 37.3952, -122.0813);
64+
INSERT INTO riderLocations (profileId, latitude, longitude) VALUES ('8b6eae59', 37.3944, -122.0813);
65+
INSERT INTO riderLocations (profileId, latitude, longitude) VALUES ('4a7c7b41', 37.4049, -122.0822);
66+
INSERT INTO riderLocations (profileId, latitude, longitude) VALUES ('4ddad000', 37.7857, -122.4011);
67+
```
68+
69+
```
70+
SELECT * from ridersNearMountainView WHERE distanceInMiles <= 10;
71+
```
72+
73+
## KSQL Follow Up
74+
75+
https://docs.ksqldb.io/en/latest/concepts/streams/
76+
77+
https://docs.ksqldb.io/en/latest/concepts/?_ga=2.59521449.545340244.1677833658-274482105.1677001988
78+
79+
## Q&A
80+
81+
https://stackoverflow.com/questions/36249744/interactive-shell-using-docker-compose
82+
83+
https://stackoverflow.com/questions/30233105/docker-compose-up-for-only-certain-containers
84+
85+
https://stackoverflow.com/questions/31746182/docker-compose-wait-for-container-x-before-starting-y

0 commit comments

Comments
 (0)