Skip to content

Commit 493e8c5

Browse files
authored
Merge pull request #15 from farbodahm/feature/dockerize-project
Feature/dockerize project
2 parents 832517d + 591b1e2 commit 493e8c5

10 files changed

+130
-0
lines changed

README.md

+36
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,38 @@
11
# stateful-stream-processing
22
My university proposal on Stateful Stream Processing
3+
4+
- [stateful-stream-processing](#stateful-stream-processing)
5+
- [Problem Description](#problem-description)
6+
- [Development Environment](#development-environment)
7+
8+
## Problem Description
9+
TODO
10+
11+
## Development Environment
12+
To run the project in dev env, make sure you have [Docker]([dasd](https://docs.docker.com/get-docker/))
13+
and [Docker-Compose](https://docs.docker.com/compose/install/) installed.
14+
Then, to run the infrastructure for Kafka and Database, run:
15+
16+
```bash
17+
docker-compose -f infra.docker-compose.yml up
18+
```
19+
20+
Wait for few minutes and after you see logs related to Kafka working normally, then run the producer and consumer applications:
21+
22+
```bash
23+
docker-compose -f app.docker-compose.yml up
24+
```
25+
26+
This will run the applications.
27+
If you changed any part of the applications, including `producer`, `consumer` or `processor` you need to re-build the Docker images.
28+
29+
```bash
30+
docker-compose -f app.docker-compose.yml up --build
31+
```
32+
33+
If you wanted to tear down everything, then simply run:
34+
```bash
35+
docker-compose down
36+
```
37+
38+
**NOTE:** This will also deletes all of the Kafka topics and database, Be careful if you want keep the data produced in it.

app.docker-compose.yml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
services:
2+
producer:
3+
build:
4+
context: .
5+
args:
6+
KAFKA_BROKER: "localhost:9092"
7+
SCHEMA_REGISTRY_URL: "http://localhost:8081"
8+
dockerfile: producer.Dockerfile
9+
network_mode: "host"
10+
11+
consumer:
12+
build:
13+
context: .
14+
args:
15+
KAFKA_BROKER: "localhost:9092"
16+
SCHEMA_REGISTRY_URL: "http://localhost:8081"
17+
CONSUMER_GROUP: "Consumer1"
18+
DB_HOST: "127.0.0.1"
19+
DB_PORT: "5432"
20+
DB_USERNAME: "postgres"
21+
DB_PASSWORD: "postgres"
22+
DB_NAME: twitter
23+
dockerfile: consumer.Dockerfile
24+
network_mode: "host"

consumer.Dockerfile

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
FROM python:3.11-slim-bullseye
2+
ARG KAFKA_BROKER
3+
ARG SCHEMA_REGISTRY_URL
4+
ARG CONSUMER_GROUP
5+
ARG DB_HOST
6+
ARG DB_PORT
7+
ARG DB_USERNAME
8+
ARG DB_PASSWORD
9+
ARG DB_NAME
10+
11+
WORKDIR /consumer
12+
13+
COPY requirements.txt requirements.txt
14+
15+
RUN apt-get update \
16+
&& apt-get -y install libpq-dev gcc
17+
18+
RUN pip3 install -r requirements.txt
19+
20+
COPY . .
21+
22+
ENV PYTHONPATH "${PYTHONPATH}:/consumer"
23+
# Convert build time arguments to runtime env variables
24+
ENV KAFKA_BROKER ${KAFKA_BROKER}
25+
ENV SCHEMA_REGISTRY_URL ${SCHEMA_REGISTRY_URL}
26+
ENV CONSUMER_GROUP ${CONSUMER_GROUP}
27+
ENV DB_HOST ${DB_HOST}
28+
ENV DB_PORT ${DB_PORT}
29+
ENV DB_USERNAME ${DB_USERNAME}
30+
ENV DB_PASSWORD ${DB_PASSWORD}
31+
ENV DB_NAME ${DB_NAME}
32+
33+
CMD exec python3 consumer/main.py \
34+
-b ${KAFKA_BROKER} \
35+
-s ${SCHEMA_REGISTRY_URL} \
36+
-g ${CONSUMER_GROUP} \
37+
--db-ip ${DB_HOST} \
38+
--db-port ${DB_PORT} \
39+
--db-user ${DB_USERNAME} \
40+
--db-password ${DB_PASSWORD} \
41+
--db-name ${DB_NAME}
File renamed without changes.
File renamed without changes.
File renamed without changes.

cosumer/main.py consumer/main.py

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from time import sleep
2+
13
from sqlalchemy.orm import Session
24

35
from model.twitter_database_model import Base
@@ -9,6 +11,9 @@
911

1012
def main() -> None:
1113
"""Starting point of the producer system"""
14+
# TODO: Find a good way to wait for the producer to be ready
15+
sleep(5)
16+
1217
cli_args_parser = CliArgsParser()
1318
cli_args = cli_args_parser.parser.parse_args()
1419

File renamed without changes.
File renamed without changes.

producer.Dockerfile

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
FROM python:3.11-slim-bullseye
2+
ARG KAFKA_BROKER
3+
ARG SCHEMA_REGISTRY_URL
4+
5+
WORKDIR /producer
6+
7+
COPY requirements.txt requirements.txt
8+
9+
RUN apt-get update \
10+
&& apt-get -y install libpq-dev gcc
11+
12+
RUN pip3 install -r requirements.txt
13+
14+
COPY . .
15+
16+
ENV PYTHONPATH "${PYTHONPATH}:/producer"
17+
# Convert build time arguments to runtime env variables
18+
ENV KAFKA_BROKER ${KAFKA_BROKER}
19+
ENV SCHEMA_REGISTRY_URL ${SCHEMA_REGISTRY_URL}
20+
21+
22+
CMD exec python3 producer/main.py \
23+
-b ${KAFKA_BROKER} \
24+
-s ${SCHEMA_REGISTRY_URL}

0 commit comments

Comments
 (0)