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

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

# Pull base image
FROM rockylinux/rockylinux:9
MAINTAINER tomasz.gromadzki@intel.com

# Set required environment variables
ENV OS rockylinux/rockylinux
ENV OS_VER 9
ENV PACKAGE_MANAGER rpm
ENV NOTTY 1

# PMDK basic dependencies
ENV BASE_DEPS "\
	git \
	daxctl-devel \
	make \
	ndctl-devel \
	passwd \
	pkgconfig"

# 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 \
	openssh-server \
	strace"

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

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

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

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

RUN dnf update -y && dnf install -y epel-release \
&& dnf --enablerepo devel install -y \
	$BASE_DEPS \
	$VALGRIND_DEPS \
	$BENCH_DEPS \
	$EXAMPLES_DEPS \
	$DOC_DEPS \
	$TESTS_DEPS \
	$PACKAGING_DEPS \
	$MISC_DEPS \
	&& ./install-valgrind.sh rockylinux \
	&& dnf clean all

RUN pip3 install $PYTHON_DEPS

# Add ans switch user
ENV USER pmdkuser
ENV USERPASS pmdkpass
RUN useradd -m $USER
RUN echo $USERPASS | passwd $USER --stdin
RUN gpasswd wheel -a $USER
RUN echo "%wheel ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
USER $USER
