# Parameters related to building hipSPARSE
ARG base_image

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

ARG user_uid

# Install dependent packages
# Dependencies: rocsparse rocprim
# * hcc-config.cmake: pkg-config
# * hipsparse-test: googletest
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
    rock-dkms \
    sudo \
    ca-certificates \
    git \
    make \
    cmake \
    pkg-config \
    libnuma1 \
    rocprim \
    && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

# 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 sudo --shell /bin/bash jenkins && \
    mkdir -p /etc/sudoers.d/ && \
    echo '%sudo   ALL=(ALL) NOPASSWD:ALL' | tee /etc/sudoers.d/sudo-nopasswd

ARG ROCSPARSE_SRC_ROOT=/usr/local/src/rocSPARSE
ARG HIPSPARSE_SRC_ROOT=/usr/local/src/hipSPARSE

# Clone rocsparse repo
# Build rocsparse and install into /usr/local
RUN mkdir -p ${ROCSPARSE_SRC_ROOT} && cd ${ROCSPARSE_SRC_ROOT} && \
    git clone -b develop --depth=1 https://github.com/ROCmSoftwarePlatform/rocSPARSE . && \
    HCC_AMDGPU_TARGET=gfx803 ./install.sh -i && \
    rm -rf ${ROCSPARSE_SRC_ROOT}

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