# Copyright 2015-present Lenovo
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

Bootstrap:docker
From:nvidia/cuda:12.8.0-cudnn-devel-ubuntu22.04

%files
    jupyter/start /opt

%post
    rm -f /etc/apt/sources.list.d/cuda.list /etc/apt/sources.list.d/nvidia-ml.list
    apt-get --allow-unauthenticated=true update
    DEBIAN_FRONTEND=noninteractive apt-get install -y wget \
        r-base-dev \
        automake \
        autoconf \
        libtool \
        cmake \
        gcc \
        g++
    wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O /opt/miniconda.sh
    bash /opt/miniconda.sh -b -p /opt/miniconda
    export PATH="/opt/miniconda/bin:$PATH"
    
    # Accept Anaconda Terms of Service for required channels
    conda tos accept --override-channels --channel https://repo.anaconda.com/pkgs/main
    conda tos accept --override-channels --channel https://repo.anaconda.com/pkgs/r

    conda create -v -y -n py313 python=3.13
    conda config --add channels conda-forge
    conda config --set channel_priority strict
    conda install -v -y -n py313 r=4.4=r44hd8ed1ab_1008 r-essentials=4.4=r44hd8ed1ab_2005 traitlets~=5.14.3 notebook==7.3.2 ipykernel==6.29.5
    conda run -n py313 python -m ipykernel install --name py313 --display-name "Python 3.13 (py313)" --sys-prefix
    chmod 777 /opt/start
    chmod 777 -R /opt/miniconda

%environment
    IMAGE_CONDA_ENV=py313
    export PATH="/opt/miniconda/bin:$PATH" IMAGE_CONDA_ENV
