########################################################
#        Renku install section - do not edit           #

FROM renku/cond:3.10-0.18.1 as builder

# RENKU_VERSION determines the version of the renku CLI
# that will be used in this image. To find the latest version,
# visit https://pypi.org/project/renku/#history.
ARG RENKU_VERSION=2.6.1

# Install renku from pypi or from github if a dev version
RUN if [ -n "$RENKU_VERSION" ] ; then \
        source .renku/venv/bin/activate ; \
        currentversion=$(renku --version) ; \
        if [ "$RENKU_VERSION" != "$currentversion" ] ; then \
            pip uninstall renku -y ; \
            gitversion=$(echo "$RENKU_VERSION" | sed -n "s/^[[:digit:]]\+\.[[:digit:]]\+\.[[:digit:]]\+\(rc[[:digit:]]\+\)*\(\.dev[[:digit:]]\+\)*\(+g\([a-f0-9]\+\)\)*\(+dirty\)*$/\4/p") ; \
            if [ -n "$gitversion" ] ; then \
                pip install --no-cache-dir --force "git+https://github.com/SwissDataScienceCenter/renku-python.git@$gitversion" ;\
            else \
                pip install --no-cache-dir --force renku==${RENKU_VERSION} ;\
            fi \
        fi \
    fi
#             End Renku install section                #
########################################################


###### RENKU CUDA IMAGE ######
#ARG BASE_IMAGE=renku/renkulab-py:3.10-640c758
FROM renku/renkulab-cuda:12.2-956b697

USER root

# install tools
RUN apt-get update && \
   apt-get install -y  --no-install-recommends  \
    curl \
    gcc \
    git \
    htop \
    libgl1 \
    libglib2.0-0 \
    ncdu \
    psmisc \
    rsync \
    screen \
    sudo \
    tmux \
    unzip \
    vim \
    wget

# add ssh keys

COPY .ssh/authorized_keys /home/jovyan/.ssh/authorized_keys
RUN chown -R jovyan:users /home/jovyan/.ssh
RUN chmod 700 /home/jovyan/.ssh
RUN chmod 600 /home/jovyan/.ssh/*

COPY docker/renku/post-init.sh /post-init.sh
RUN chown jovyan:users /post-init.sh && chmod +x /post-init.sh

USER $NB_USER

## install the python dependencies
COPY docker/renku/requirements.txt docker/renku/environment.yml /tmp/

RUN mamba env update -f /tmp/environment.yml -n base && \
    /opt/conda/bin/pip install -r /tmp/requirements.txt --no-cache-dir && \
    mamba clean -y --all && \
    mamba env export -n "root" && \
    rm -rf ${HOME}/.renku/venv


ENV CONDA_DIR /opt/conda
ENV PATH=$CONDA_DIR/bin:$PATH
RUN /opt/conda/bin/conda init


