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

#
# Dockerfile - a 'recipe' for Docker to build an image of opensuse-based
#              environment prepared for running pmemkv build and tests.
#

# Pull base image
FROM opensuse/leap:latest
MAINTAINER igor.chorazewicz@intel.com

# Set required environment variables
ENV OS opensuse-leap
ENV OS_VER latest
ENV PACKAGE_MANAGER rpm
ENV NOTTY 1

# Additional parameters to build docker without building components
ARG SKIP_VALGRIND_BUILD
ARG SKIP_PMDK_BUILD
ARG SKIP_LIBPMEMOBJCPP_BUILD

# Update the OS
RUN zypper dup -y

# Update all packages
RUN zypper update -y

# Install basic tools
RUN zypper install -y \
	autoconf \
	automake \
	bash-completion \
	clang \
	cmake \
	doxygen \
	fdupes \
	gcc \
	gcc-c++ \
	gdb \
	git \
	graphviz \
	gzip \
	keyutils-devel \
	make \
	man \
	memkind-devel \
	libjson-c-devel \
	libkmod-devel \
	libndctl-devel \
	libnuma-devel \
	libtool \
	libudev-devel \
	libunwind-devel \
	libuuid-devel \
	pandoc \
	perl-Text-Diff \
	'pkgconfig(bash-completion)' \
	rapidjson-devel \
	rpm-build \
	sudo \
	unzip \
	wget \
	which

# Enable the debuginfo repo
RUN zypper mr -e repo-debug
RUN zypper install -y \
	glibc-debuginfo

# Install a newer version of TBB from the Education repository
RUN zypper addrepo https://download.opensuse.org/repositories/Education/openSUSE_Leap_15.1/ education
RUN zypper --gpg-auto-import-keys install -y \
	tbb-devel

RUN zypper clean all

# Install libndctl
COPY install-libndctl.sh install-libndctl.sh
RUN ./install-libndctl.sh opensuse

# Install valgrind
COPY install-valgrind.sh install-valgrind.sh
RUN ./install-valgrind.sh opensuse

# Install pmdk
COPY install-pmdk.sh install-pmdk.sh
RUN ./install-pmdk.sh rpm

# Install pmdk c++ bindings
COPY install-libpmemobj-cpp.sh install-libpmemobj-cpp.sh
RUN ./install-libpmemobj-cpp.sh RPM

# Add user
ENV USER user
ENV USERPASS p1a2s3s4
ENV PFILE ./password
RUN useradd -m $USER
RUN echo $USERPASS > $PFILE
RUN echo $USERPASS >> $PFILE
RUN passwd $USER < $PFILE
RUN rm -f $PFILE
RUN sed -i 's/# %wheel ALL=(ALL) NOPASSWD: ALL/%wheel ALL=(ALL) NOPASSWD: ALL/g' /etc/sudoers
RUN groupadd wheel
RUN gpasswd wheel -a $USER
USER $USER
