From 35881893f64031d8d887a4c33a7e96d8083b94e7 Mon Sep 17 00:00:00 2001 From: Akash Sivakumar Date: Thu, 14 Nov 2024 18:32:17 -0700 Subject: [PATCH] Incomplete - dockerizing kafka streaming --- preprocessing/Dockerfile.python | 20 ++++++++++++++++++++ preprocessing/pcap_processor.py | 1 + preprocessing/requirements.txt | 2 ++ 3 files changed, 23 insertions(+) create mode 100644 preprocessing/Dockerfile.python create mode 100644 preprocessing/requirements.txt diff --git a/preprocessing/Dockerfile.python b/preprocessing/Dockerfile.python new file mode 100644 index 0000000..bba0ca6 --- /dev/null +++ b/preprocessing/Dockerfile.python @@ -0,0 +1,20 @@ +# Start with a base image that includes Python +FROM python:3.9-slim + +# Set the working directory inside the container +WORKDIR /app + +# Copy only the requirements.txt file to the container +COPY requirements.txt /app + +# Install the dependencies using the requirements.txt file +RUN pip install --no-cache-dir -r requirements.txt + +# Copy only the pcap_processor.py file to the container +COPY pcap_processor.py /app + +# Expose the port Kafka uses (optional, for communication with other services) +EXPOSE 9092 + +# Command to run your Python application +CMD ["python", "pcap_processor.py"] diff --git a/preprocessing/pcap_processor.py b/preprocessing/pcap_processor.py index 21a9e6f..bcda443 100644 --- a/preprocessing/pcap_processor.py +++ b/preprocessing/pcap_processor.py @@ -14,6 +14,7 @@ dbg_print = lambda *x: DEBUG and print(f"[DEBUG] {x}") # Kafka Configuration KAFKA_TOPIC = 'pcap_stream' KAFKA_SERVER = 'localhost:9092' # Adjust to your Kafka server +#KAFKA_SERVER = 'kafka_service:9092' # Initialize Kafka Producer producer = KafkaProducer( diff --git a/preprocessing/requirements.txt b/preprocessing/requirements.txt new file mode 100644 index 0000000..b89fb74 --- /dev/null +++ b/preprocessing/requirements.txt @@ -0,0 +1,2 @@ +kafka-python +scapy \ No newline at end of file