# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2016-2023, Intel Corporation

#
# Dockerfile - a 'recipe' for Docker to build an image of openSUSE-based
#              environment for building the PMDK project.
#

# Pull base image
FROM opensuse/leap:15
MAINTAINER tomasz.gromadzki@intel.com

# Set required environment variables
ENV OS opensuse/leap
ENV OS_VER 15
ENV PACKAGE_MANAGER rpm
ENV NOTTY 1
ENV LD_LIBRARY_PATH /usr/lib:$LD_LIBRARY_PATH
ENV PKG_CONFIG_PATH /usr/lib/pkgconfig:$PKG_CONFIG_PATH

# PMDK basic dependencies
ENV BASE_DEPS "\
	gcc \
	gcc-c++ \
	git \
	libndctl-devel \
	make \
	pkg-config \
	systemd"

# Valgrind dependencies
ENV VALGRIND_DEPS "\
	autoconf \
	automake \
	file \
	findutils \
	git"

# benchmarks dependencies (optional)
ENV BENCH_DEPS "\
	glib2-devel"

# examples dependencies (optional)
ENV EXAMPLES_DEPS "\
	fuse \
	fuse-devel \
	ncurses-devel \
	libuv-devel"

# documentation dependencies (optional)
ENV DOC_DEPS "\
	pandoc"

# tests dependencies
ENV TESTS_DEPS "\
	bc \
	gdb \
	libunwind-devel \
	ndctl \
	strace"

# packaging dependencies
ENV PACKAGING_DEPS "\
	fdupes \
	rpm-build \
	rpmdevtools"

# miscellaneous dependencies (mostly for CI)
ENV MISC_DEPS "\
	clang \
	hub \
	lbzip2 \
	man \
	python3-flake8 \
	python3-pip \
	rsync \
	sudo \
	tar \
	which \
	xmlto"

# python scripts dependencies
ENV PYTHON_DEPS "\
	distro \
	xmlrunner"

# Copy install valgrind script
COPY install-valgrind.sh install-valgrind.sh

# add openSUSE Leap 15.4 Oss repo
RUN zypper ar -f http://download.opensuse.org/distribution/leap/15.4/repo/oss/ oss

RUN zypper update -y && zypper install -y \
	$BASE_DEPS \
	$VALGRIND_DEPS \
	$BENCH_DEPS \
	$EXAMPLES_DEPS \
	$DOC_DEPS \
	$TESTS_DEPS \
	$PACKAGING_DEPS \
	$MISC_DEPS \
	&& ./install-valgrind.sh fedora \
	&& zypper clean all

RUN pip3 install $PYTHON_DEPS

# Add and switch user
ENV USER pmdkuser
ENV USERPASS pmdkpass
RUN useradd -m $USER
ENV PFILE ./password
RUN echo $USERPASS > $PFILE
RUN echo $USERPASS >> $PFILE
RUN passwd $USER < $PFILE
RUN rm -f $PFILE
RUN sed -i 's/# %wheel/%wheel/g' /etc/sudoers
RUN groupadd wheel
RUN gpasswd wheel -a $USER
USER $USER
