# ── TensorFlow Distributed Training Starter — Dockerfile ─────────────────────
#
# CPU image by default. For GPU support, swap the FROM line:
#   FROM tensorflow/tensorflow:2.15.0-gpu
#
# Build:
#   docker build -t demia-tf-dist-train:latest .
#
# Run (single-machine training):
#   docker run --rm \
#       -v $(pwd)/outputs:/app/outputs \
#       demia-tf-dist-train:latest \
#       python scripts/run.py --mode train
# ─────────────────────────────────────────────────────────────────────────────

FROM tensorflow/tensorflow:2.15.0

# Set working directory
WORKDIR /app

# Suppress TF C++ info logs inside the container
ENV TF_CPP_MIN_LOG_LEVEL=2

# Copy dependency files first (leverages Docker layer cache)
COPY requirements.txt pyproject.toml ./

# Install Python dependencies
RUN pip install --no-cache-dir --upgrade pip && \
    pip install --no-cache-dir -r requirements.txt

# Copy the full project
COPY . .

# Create output directories (they will be bind-mounted in practice)
RUN mkdir -p outputs/checkpoints outputs/logs

# Default: train using the MirroredStrategy (CPU fallback when no GPU)
CMD ["python", "scripts/run.py", "--mode", "train", "--strategy", "mirrored"]
