# Dockerfile — Python runner for the Day-3 Presidio Custom-Recognizers lab
# Base image pinned by index-digest (ADR-6).
# Re-resolve: docker buildx imagetools inspect python:3.12-slim --format '{{.Manifest.Digest}}'
FROM python:3.12-slim@sha256:423ed6ab25b1921a477529254bfeeabf5855151dc2c3141699a1bfc852199fbf

WORKDIR /workspace

# curl: for debugging convenience (e.g. testing endpoints from inside the container).
RUN apt-get update \
    && apt-get install -y --no-install-recommends curl \
    && rm -rf /var/lib/apt/lists/*

# Step 1: Install Python dependencies.
# Presidio uses spaCy as the NLP backend — NO torch/HuggingFace required.
# spaCy wheels are pre-built for linux/amd64 (no gcc needed).
COPY app/requirements.txt ./requirements.txt
RUN pip install --no-cache-dir -r requirements.txt

# Step 2: Download the spaCy en_core_web_lg NER model at BUILD time.
# `python -m spacy download en_core_web_lg` installs it as a Python package
# (pip wheel from GitHub releases, ~587 MB) into site-packages. At RUNTIME
# spacy.load() finds it there with NO network call — spaCy never re-downloads an
# installed model. Unlike HuggingFace, spaCy has no separate cache dir; the model
# IS the installed package (ADR-5) — so no TRANSFORMERS_OFFLINE flag is needed.
RUN python -m spacy download en_core_web_lg

# Step 3: Validate the spaCy model and Presidio pipeline at BUILD time.
COPY app/prebake_spacy.py /tmp/prebake_spacy.py
RUN python /tmp/prebake_spacy.py && rm /tmp/prebake_spacy.py

# Bake app + data + prompts so the image works standalone
# (compose mounts override at runtime)
COPY app/ ./app/
COPY data/ ./data/
COPY prompts/ ./prompts/

CMD ["python", "app/recognizers_demo.py"]
