FROM amazon/aws-lambda-python:3.12.2025.11.23.13-x86_64

ARG CACHE_BUSTER=0

# STEP 1: OS Security Patching (Addresses libxml2 CVEs)
# The CACHE_BUSTER forces this layer to run fresh, ensuring current patches are applied.
RUN echo "Running security update for build $CACHE_BUSTER" && \
    dnf update -y && \
    dnf clean all

# STEP 2: Copy Requirements Files
# Copy requirements before installing to ensure they're available
COPY requirements.txt requirements-test.txt ./

# STEP 3: Install Build Dependencies and Python Packages
# Install required system packages, then upgrade/install Python dependencies.
RUN dnf install -y gcc python3-devel zlib-devel librdkafka-devel || \
    dnf install -y gcc python3-devel zlib-devel && \
    # Fixes CVE-2025-8869 by pinning pip to a patched version
    pip install --upgrade pip==25.2 && \
    pip install --only-binary :all: confluent-kafka --no-cache-dir && \
    pip install -r requirements-test.txt --no-cache-dir && \
    dnf clean all

COPY config.py integration-tests.sh docker-compose.yaml ./
COPY src/ ./src
COPY tests/ ./tests

ENTRYPOINT [ "/var/task/integration-tests.sh" ]
