# captchaforge VLM training image.
#
# CUDA + PyTorch + Transformers + PEFT + TRL — everything the
# scripts/ directory needs to run end-to-end fine-tunes against
# the captchaforge VlmDataset format.
#
# Single image covers all four scripts (auto_label, train_lora,
# distill, bench_compare). Pin every dep to a specific version so
# rebuilds are reproducible across the trainer fleet.

FROM nvidia/cuda:12.4.1-cudnn-devel-ubuntu22.04

ENV DEBIAN_FRONTEND=noninteractive \
    PYTHONUNBUFFERED=1 \
    PYTHONDONTWRITEBYTECODE=1 \
    PIP_NO_CACHE_DIR=1 \
    PIP_DISABLE_PIP_VERSION_CHECK=1 \
    HF_HUB_DISABLE_TELEMETRY=1

# System deps — Python 3.11, git for HF model pulls, build-essential
# for any per-platform wheels that aren't pre-built (rare but real).
RUN apt-get update && apt-get install -y --no-install-recommends \
    python3.11 \
    python3.11-dev \
    python3-pip \
    python3.11-venv \
    git \
    build-essential \
    libssl-dev \
    pkg-config \
    && rm -rf /var/lib/apt/lists/*

# Symlink python -> python3.11 so scripts/ shebangs work.
RUN ln -sf /usr/bin/python3.11 /usr/local/bin/python && \
    ln -sf /usr/bin/python3.11 /usr/local/bin/python3

# Working dir matches the README's docker-run mount points.
WORKDIR /work

# Python deps in requirements.txt — pinned versions so two
# `docker build` invocations with the same Dockerfile produce the
# same training environment.
COPY requirements.txt /work/requirements.txt
RUN pip install --upgrade pip && \
    pip install -r /work/requirements.txt

# Scripts directory is mounted at runtime so iterating on the
# training recipe doesn't trigger a rebuild — but we copy a
# baseline so `docker run captchaforge-trainer scripts/foo.py`
# works without a host mount.
COPY scripts/ /work/scripts/
RUN chmod +x /work/scripts/*.py /work/scripts/*.sh

# Empty default — the README documents `docker run … script.py …`.
# Falling back to bash gives the operator a shell when they
# `docker run -it captchaforge-trainer` without a command.
CMD ["bash"]
