# ─────────────────────────────────────────────────────────────────────────────
# Hugging Face Token Classification Starter — Dockerfile
# Builds a minimal image that serves the FastAPI inference endpoint.
# ─────────────────────────────────────────────────────────────────────────────
FROM python:3.11-slim

# Keeps Python from buffering stdout/stderr so logs appear immediately.
ENV PYTHONUNBUFFERED=1 \
    PYTHONDONTWRITEBYTECODE=1 \
    PIP_NO_CACHE_DIR=1

WORKDIR /app

# Install OS-level build tools needed by some tokenizer/extension builds.
RUN apt-get update && apt-get install -y --no-install-recommends \
        build-essential \
        git \
    && rm -rf /var/lib/apt/lists/*

# Install Python dependencies first (layer is cached unless requirements change).
COPY requirements.txt .
RUN pip install --upgrade pip && pip install -r requirements.txt

# Copy project source.
COPY . .

# Expose the API port (override with API_PORT env var at runtime).
EXPOSE 8000

# Default command: start the FastAPI server.
# The model is loaded from OUTPUT_DIR (mount a volume or bake weights into the image).
CMD ["uvicorn", "api.main:app", "--host", "0.0.0.0", "--port", "8000"]
