ARG FROM_IMAGE
FROM ${FROM_IMAGE}

MAINTAINER h2oai "h2o.ai"

ARG H2O_BRANCH='master'
RUN export JENKINS_UID=$(id -u jenkins) && export JENKINS_GID=$(id -g jenkins)

COPY xgb/centos/common/sbin xgb/common/sbin xgb/centos/omp/sbin /usr/sbin/

RUN \
    chmod +x /usr/sbin/install_packages /usr/sbin/install_omp_packages && \
    sync && \
    /usr/sbin/install_packages && \
    /usr/sbin/install_omp_packages

COPY jdk1.8.0_171.zip /usr/local/lib/
RUN \
    chmod +x /usr/sbin/install_java && \
    sync && \
    /usr/sbin/install_java

ENV JAVA_VERSION '8'
ENV JAVA_HOME /usr/lib/jvm/java-8-oracle
ENV PATH ${JAVA_HOME}/bin:${PATH}

# Install Python 3.7
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

RUN \
    chmod +x /usr/sbin/create_jenkins_user && \
    sync && \
    /usr/sbin/create_jenkins_user

RUN localedef -i en_US -f UTF-8 en_US.UTF-8
# Set GRADLE USER env var
ENV GRADLE_OPTS '-Dorg.gradle.daemon=false'
ENV LANG 'en_US.UTF-8'
ENV LC_ALL 'en_US.UTF-8'

COPY xgb/common/tmp/prepare_gradle_caches /tmp/
RUN \
    chmod +x /tmp/prepare_gradle_caches && \
    chown jenkins:jenkins /tmp/prepare_gradle_caches
USER jenkins
RUN \
    /tmp/prepare_gradle_caches

USER root
