Optimize docker image

Change-Id: I78b060eca5d99bced3573f804490bc607df40352
diff --git a/Dockerfile b/Dockerfile
index aad4d5c..548bc69 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,32 +1,55 @@
-# Use the official Python 3.12 image
-FROM python:3.12-slim-bookworm
+# Multi-stage Docker build for size optimization
+FROM python:3.12-slim-bookworm AS builder
+
+# Install build dependencies
+RUN apt-get update && apt-get install -y \
+    gcc \
+    g++ \
+    && rm -rf /var/lib/apt/lists/*
 
 # Set environment variables
-ENV PIP_CACHE_DIR="/app/.cache/pip" \
+ENV PIP_CACHE_DIR="/tmp/.cache/pip" \
     PYTHONPATH="PYTHONPATH:."
 ENV VIRTUAL_ENV=/app/venv
 ENV PATH="$VIRTUAL_ENV/bin:$PATH"
-ENV MAKEFLAGS="-j$(nproc)"
+
+# Set the working directory and copy requirements
+WORKDIR /app
+COPY requirements.txt /app/requirements.txt
+
+# Install Python dependencies in virtual environment
+RUN python -m venv venv
+RUN venv/bin/pip install --upgrade pip
+RUN venv/bin/pip install -r requirements.txt
+RUN venv/bin/python -m spacy download de_core_news_lg
+
+# Production stage
+FROM python:3.12-slim-bookworm AS production
+
+# Install minimal runtime dependencies
+RUN apt-get update && apt-get install -y \
+    && rm -rf /var/lib/apt/lists/* \
+    && apt-get clean
+
+# Copy virtual environment from builder
+COPY --from=builder /app/venv /app/venv
+
+# Copy application code
+COPY lib /app/lib
+COPY systems /app/systems
+COPY my_utils /app/my_utils
+
+# Set environment variables
+ENV VIRTUAL_ENV=/app/venv
+ENV PATH="$VIRTUAL_ENV/bin:$PATH"
+ENV PYTHONPATH="PYTHONPATH:."
 
 # spaCy processing configuration
 ENV SPACY_USE_DEPENDENCIES="True"
 ENV SPACY_USE_GERMALEMMA="True"
 
-# Set the working directory
-COPY lib /app/lib
-COPY requirements.txt /app/requirements.txt
-COPY systems /app/systems
-COPY my_utils /app/my_utils
 WORKDIR /app
-
-# Install Python dependencies and create a virtual environment
 RUN mkdir -p "/app/logs"
-RUN python -m venv venv
-RUN venv/bin/pip install --upgrade pip
-RUN venv/bin/pip install -r requirements.txt
-RUN . venv/bin/activate && python -m spacy download de_core_news_lg
 
 # Define the entry point
-CMD ["python", "/app/systems/parse_spacy_pipe.py"]
-
-
+CMD ["python", "/app/systems/parse_spacy_pipe.py"]
\ No newline at end of file