Skip to content

Commit 4e35685

Browse files
committed
add functional dockerfile, cfg and change docker-compose.yaml
add try catch for run in main.py
1 parent 80f8b54 commit 4e35685

File tree

6 files changed

+48
-37
lines changed

6 files changed

+48
-37
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
.vscode
1+
.vscode
2+
__pycache__/
3+
.idea/

deploy/Dockerfile

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,3 @@
1-
FROM debian:bullseye
2-
3-
RUN apt-get update -y \
4-
&& apt-get upgrade -y \
5-
&& apt-get -y install build-essential \
6-
zlib1g-dev \
7-
libncurses5-dev \
8-
libgdbm-dev \
9-
libnss3-dev \
10-
libssl-dev \
11-
libreadline-dev \
12-
libffi-dev \
13-
libsqlite3-dev \
14-
libbz2-dev \
15-
wget \
16-
&& export DEBIAN_FRONTEND=noninteractive \
17-
&& apt-get purge -y imagemagick imagemagick-6-common
18-
19-
RUN cd /usr/src \
20-
&& wget https://www.python.org/ftp/python/3.11.0/Python-3.11.0.tgz \
21-
&& tar -xzf Python-3.11.0.tgz \
22-
&& cd Python-3.11.0 \
23-
&& ./configure --enable-optimizations \
24-
&& make altinstall
25-
26-
RUN update-alternatives --install /usr/bin/python python /usr/local/bin/python3.11 1
1+
FROM python:3.11-bullseye
2+
ADD requirements.txt /app/requirements.txt
3+
RUN python3 -m pip install -r /app/requirements.txt
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[kafka]
2+
3+
url = kafka:9092

deploy/docker-compose.yaml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,20 @@ services:
2020
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:9092,PLAINTEXT_HOST://localhost:29092
2121
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
2222
KAFKA_INTER_BROKER_LISTENER_NAME: PLAINTEXT
23-
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
23+
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
24+
25+
datastrike-python:
26+
image: datastrike/python:latest
27+
build:
28+
context: .
29+
dockerfile: Dockerfile
30+
31+
command: /bin/bash -c "cd /datastrike-python/ && python3 main.py"
32+
volumes:
33+
- ../src/:/datastrike-python
34+
- ../../map/:/map
35+
- type: bind
36+
source: datastrike_python_processing.cfg
37+
target: /datastrike-python/datastrike_python_processing.cfg
38+
depends_on:
39+
- kafka
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[kafka]
2+
3+
url = localhost:29092

src/main.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,24 @@
33
import sys
44
from kafka_lib import ProducerThread, ConsumerThread
55
from log_analyser.log_analyser import LogAnalyser
6+
import configparser
67

78

89
class DatastrikePythonProcessing:
910
def __init__(self):
1011

1112
self.running = True
1213

13-
self.producer_thread = ProducerThread("localhost:29092")
14+
self.config = configparser.ConfigParser()
15+
self.config.read("datastrike_python_processing.cfg")
16+
17+
18+
self.kafka_url = self.config["kafka"]["url"]
19+
20+
print(self.kafka_url)
21+
self.producer_thread = ProducerThread(self.kafka_url)
1422

15-
self.consumer_thread = ConsumerThread("localhost:29092")
23+
self.consumer_thread = ConsumerThread(self.kafka_url)
1624
self.consumer_thread.add_topics("analyse", self.on_callback_test)
1725

1826
self.consumer_thread.start()
@@ -28,13 +36,15 @@ def on_callback_test(self, topic, data):
2836

2937
if self.check_txt_extension(fileName):
3038

31-
la = LogAnalyser(filePath, fileName, teamId)
32-
la.run()
33-
if la.map != None:
34-
self.producer_thread.send("analyse.report", la.map.export_json())
35-
else:
36-
self.producer_thread.send("analyse.report", {"error": "File txt not correct"})
37-
39+
try:
40+
la = LogAnalyser(filePath, fileName, teamId)
41+
la.run()
42+
if la.map != None:
43+
self.producer_thread.send("analyse.report", la.map.export_json())
44+
else:
45+
self.producer_thread.send("analyse.report", {"error": "File txt not correct"})
46+
except Exception as e:
47+
self.producer_thread.send("analyse.report", {"error": "{}".format(e)})
3848
else:
3949
self.producer_thread.send("analyse.report", {"error": "File extension not correct"})
4050

0 commit comments

Comments
 (0)