# Parameters related to building rocBLAS
ARG base_image

FROM ${base_image}
LABEL maintainer="rocblas-maintainer@amd.com"

ARG user_uid

# Install dependent packages
# Dependencies:
# * hcc-config.cmake: pkg-config
# * tensile: python2.7, python-yaml
# * rocblas-test: gfortran, googletest
# * rocblas-bench: libboost-program-options-dev
# * libhsakmt.so: libnuma1
RUN zypper refresh && zypper -n --no-gpg-checks install\
    sudo \
    ca-certificates \
    git \
    gcc-c++ \
    gcc-fortran \
    make \
    cmake \
    fftw3-devel \
    rpm-build \
    dpkg \
    python2-PyYAML \
    libboost_program_options1_66_0-devel\
    libcxxtools9 \
    libnuma1 \
    llvm7-devel \
    python3-pip

RUN pip3 install wheel && pip3 install tox pyyaml

# docker pipeline runs containers with particular uid
# create a jenkins user with this specific uid so it can use sudo priviledges
# Grant any member of sudo group password-less sudo privileges
RUN useradd --create-home -u ${user_uid} -o -G video --shell /bin/bash jenkins && \
    echo '%video ALL=(ALL) NOPASSWD:ALL' | tee /etc/sudoers.d/sudo-nopasswd && \
    chmod 400 /etc/sudoers.d/sudo-nopasswd

ARG ROCBLAS_SRC_ROOT=/usr/local/src/rocBLAS

# Clone rocblas repo
# Build client dependencies and install into /usr/local (LAPACK & GTEST)
RUN mkdir -p ${ROCBLAS_SRC_ROOT} && cd ${ROCBLAS_SRC_ROOT} && \
    git clone -b develop --depth=1 https://github.com/ROCmSoftwarePlatform/rocBLAS . && \
    mkdir -p build/deps && cd build/deps && \
    cmake -DBUILD_BOOST=OFF ${ROCBLAS_SRC_ROOT}/deps && \
    make -j $(nproc) install && \
    rm -rf ${ROCBLAS_SRC_ROOT}
