FROM nvidia/cuda:11.0.3-devel-centos7
MAINTAINER h2oai "h2o.ai"

ARG JENKINS_UID=$(id -u jenkins)
ARG JENKINS_GID=$(id -u jenkins)
ARG H2O_BRANCH='h2o3'

RUN \
    curl -s https://repos.fedorapeople.org/repos/dchen/apache-maven/epel-apache-maven.repo | sed 's/\$releasever/7/g' > /etc/yum.repos.d/epel-apache-maven.repo && \
    yum install -y centos-release-scl && \
    yum install -y devtoolset-8-toolchain python3 zip java-1.8.0-openjdk-devel apache-maven wget git unzip make

# Install virtualenv
RUN \
    pip3 install virtualenv

# Install deps for pythons and cmake
RUN \
    yum install -y xz libffi-devel bzip2-devel ncurses-devel gdbm-devel xz-devel sqlite-devel readline-devel zlib-devel libuuid-devel && \
    yum groupinstall -y 'Development Tools' && \
    cd /usr/src && \
    curl -LO 'https://www.openssl.org/source/openssl-1.1.0h.tar.gz' && \
    tar -xf openssl-1.1.0h.tar.gz && \
    cd openssl-1.1.0h && \
    ./config shared --prefix=/usr/local/openssl11 --openssldir=/usr/local/openssl11 && \
    make && \
    make install && \
    cd .. && \
    rm -rf openssl-1.1.0h*

ENV CMAKE_VERSION '3.18'
ENV CMAKE_PATCH '2'
RUN \
    # Check that gcc is of correct version
    source scl_source enable devtoolset-8 && \
    # if [ "$(gcc --version | head -1)" != 'gcc (GCC) 7.3.1 20180303 (Red Hat 7.3.1-5)' ]; then exit 1; fi && \
    # Install CMake
    cd /usr/src && \
    wget http://www.cmake.org/files/v${CMAKE_VERSION}/cmake-${CMAKE_VERSION}.${CMAKE_PATCH}.tar.gz && \
    tar -xvzf cmake-${CMAKE_VERSION}.${CMAKE_PATCH}.tar.gz && \
    cd cmake-${CMAKE_VERSION}.${CMAKE_PATCH}/ && \
    OPENSSL_ROOT_DIR=/usr/local/openssl11 ./configure && \
    make && \
    make install && \
    cd .. && \
    rm -rf cmake-${CMAKE_VERSION}.${CMAKE_PATCH}* && \
    if [ "$(cmake --version | head -1)" != "cmake version ${CMAKE_VERSION}.${CMAKE_PATCH}" ]; then exit 1; fi

# Install Python 3.7 and 3.8
COPY xgb_build/scripts/Setup.dist.patched /usr/src/
COPY xgb_build/scripts/install_python_source_centos /usr/sbin/
RUN \
    chmod a+x /usr/sbin/install_python_source_centos && \
    sync && \
    /usr/sbin/install_python_source_centos 3.7.0 /usr/src/Setup.dist.patched && \
    /usr/sbin/install_python_source_centos 3.8.0

# Install the NCCL library
RUN \
    yum install -y libnccl libnccl-devel libnccl-static


# Add the Jenkins user
RUN \
    groupadd -g ${JENKINS_GID} jenkins && \
    useradd jenkins -m -u ${JENKINS_UID} -g jenkins
