# Fully-qualified base image (docker.io/...) so Podman/Buildah never prompts for a
# short-name registry. See "Troubleshooting" in README.md.
FROM docker.io/nvidia/cuda:12.4.1-runtime-ubuntu22.04

ENV DEBIAN_FRONTEND=noninteractive
ENV TZ=UTC
SHELL ["/bin/bash", "-c"]

# ============================================================
# System dependencies
# ============================================================
RUN apt-get update && apt-get install -y --no-install-recommends \
    wget curl ca-certificates gnupg \
    python3 python3-pip python3-venv \
    git build-essential gfortran \
    zlib1g-dev libpng-dev libjpeg-dev libfreetype6-dev \
    xvfb libgl1-mesa-glx libglfw3 \
    libxrandr2 libxinerama1 libxcursor1 libxi6 \
    libssl-dev libcurl4-openssl-dev libxml2-dev \
    && rm -rf /var/lib/apt/lists/*

# ============================================================
# Julia 1.11 (matches environment/Manifest.toml julia_version = "1.11.7")
# ============================================================
RUN curl -fsSL https://julialang-s3.julialang.org/bin/linux/x64/1.11/julia-1.11.7-linux-x86_64.tar.gz \
    | tar -xz -C /usr/local --strip-components=1

# ============================================================
# Python ML packages (GPU / CUDA 12.4)
# ============================================================
RUN pip3 install --no-cache-dir \
    torch torchvision --index-url https://download.pytorch.org/whl/cu124 \
    && pip3 install --no-cache-dir \
    Pillow numpy scikit-learn matplotlib pandas scipy psutil plotly

# ============================================================
# Project code
# ============================================================
WORKDIR /app
COPY . .

# ============================================================
# Julia environment
# ============================================================
# Instantiate from the committed Manifest.toml (no resolve: the lock is complete,
# and resolving against a fresh registry is fragile). No explicit precompile:
# GLMakie is a GUI-only dependency that fails to precompile headlessly, but the
# pipeline never loads it, so it must not fail the build.
RUN julia --project=/app/environment -e 'using Pkg; Pkg.instantiate()'

# ============================================================
# Environment variables
# ============================================================
ENV PYTHONPATH="/app/scripts_python:${PYTHONPATH}"
ENV DISPLAY=:99

LABEL maintainer="MSI Julia-Python CNN"
LABEL description="Julia preprocessing + Python SimCLR - MSI CNN Pipeline (GPU)"

CMD ["/bin/bash"]