ARG BASE=centos:8

FROM ${BASE} AS yum
RUN yum install -y \
	which \
	bzip2 \
	git \
	libarchive \
	cmake \
	gcc \
	make \
	openssl-devel \
	openssh-server \
	git-daemon \
	java-1.8.0-openjdk-headless \
	sudo \
	python39 \
	krb5-workstation \
	krb5-libs

FROM yum AS libssh2
RUN cd /tmp && \
    curl --location --silent --show-error https://www.libssh2.org/download/libssh2-1.8.0.tar.gz | tar -xz && \
    cd libssh2-1.8.0 && \
    ./configure && \
    make && \
    make install && \
    cd .. && \
    rm -rf libssh2-1.8.0

FROM libssh2 AS valgrind
RUN cd /tmp && \
    curl --insecure --location --silent --show-error https://sourceware.org/pub/valgrind/valgrind-3.15.0.tar.bz2 | \
        tar -xj && \
    cd valgrind-3.15.0 && \
    ./configure && \
    make MAKEFLAGS="-j -l$(grep -c ^processor /proc/cpuinfo)" && \
    make install && \
    cd .. && \
    rm -rf valgrind-3.15.0

FROM valgrind AS adduser
RUN useradd --shell /bin/bash libgit2 --create-home

FROM adduser AS configure
ENV PKG_CONFIG_PATH /usr/local/lib/pkgconfig
RUN mkdir /var/run/sshd
RUN echo "/usr/local/lib" > /etc/ld.so.conf.d/local && \
    ldconfig
