# Ubuntu 22.04, Python 3.10, CUDA 12.3
ARG BASE_CONTAINER=tensorflow/tensorflow:2.20.0-gpu
FROM $BASE_CONTAINER

ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update && apt-get install -yq \
    build-essential \
    libsm6 \
    libxext-dev \
    libxrender1 \
    python3-dev \
    python3-pip \
    tzdata \
    unzip && \
    rm -rf /var/lib/apt/lists/* && \
    # apt's python3.10 upgrade wipes the TF-bundled pip; python3-pip above
    # provides Ubuntu's pip compatible with the upgraded interpreter
    # ipykernel 7 has asyncio rewrite affecting kernels to become idle
    # jupyter_client/server/pyzmq capped to converge with the rest of the fleet
    python3 -m pip install --upgrade \
        future pycryptodomex \
        "ipykernel<7" \
        "jupyter_client<9" \
        "jupyter_server<3" \
        "pyzmq<28"

ADD jupyter_enterprise_gateway_kernel_image_files*.tar.gz /usr/local/bin/

USER root

RUN adduser --system --uid 1000 --gid 100 jovyan && \
    chown jovyan:users /usr/local/bin/bootstrap-kernel.sh && \
    chmod 0755 /usr/local/bin/bootstrap-kernel.sh && \
    chown -R jovyan:users /usr/local/bin/kernel-launchers


USER jovyan
ENV KERNEL_LANGUAGE=python
CMD /usr/local/bin/bootstrap-kernel.sh
