FROM python:3.12-slim

RUN apt-get update && \
    apt-get install -y --no-install-recommends \
        yara \
        libyara-dev \
        gcc

WORKDIR /app

COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt && \
    apt-get purge -y gcc && \
    apt-get autoremove -y && \
    rm -rf /var/lib/apt/lists/*

COPY api.py .

# Bundled default rules (can be overridden/extended via volume mount)
COPY rules/ /rules/bundled/

# Custom rules mount point (operators add .yar files here)
RUN mkdir -p /rules/custom

EXPOSE 8080

HEALTHCHECK --interval=15s --timeout=5s --retries=3 \
    CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:8080/health')"

CMD ["python", "api.py"]
