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

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

# Pull base image
FROM ubuntu:22.04
MAINTAINER tomasz.gromadzki@intel.com

# Set required environment variables
ENV OS ubuntu
ENV OS_VER 22.04
ENV PACKAGE_MANAGER dpkg
ENV NOTTY 1
ENV DEBIAN_FRONTEND noninteractive

# Additional parameters to build docker without building components
ARG SKIP_SCRIPTS_DOWNLOAD

# PMDK basic dependencies
ENV BASE_DEPS "build-essential \
	git \
	libdaxctl-dev \
	libndctl-dev \
	pkg-config"

# Valgrind dependencies
ENV VALGRIND_DEPS "autoconf \
	automake \
	build-essential \
	git"

# benchmarks dependencies (optional)
ENV BENCH_DEPS libglib2.0-dev

# examples dependencies (optional)
ENV EXAMPLES_DEPS "libfuse-dev \
	libncurses5-dev \
	libuv1-dev"

# documentation dependencies (optional)
ENV DOC_DEPS pandoc

# tests dependencies
ENV TESTS_DEPS "bc \
	gdb \
	libc6-dbg \
	libunwind-dev \
	ndctl \
	python3 \
	ssh \
	strace"

# packaging dependencies
ENV PACKAGING_DEPS "debhelper \
	devscripts \
	fakeroot"

# Codecov (coverage measurement) dependencies (optional)
ENV CODECOV_DEPS curl perl

# Coverity (static analysis) dependencies (optional)
ENV COVERITY_DEPS ruby gcc g++ wget

# miscellaneous dependencies (mostly for CI)
ENV MISC_DEPS "clang \
	hub \
	rsync \
	clang-format \
	flake8 \
	python3-pip \
	sudo \
	whois"

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

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

# Update the Apt cache and install basic tools
RUN apt-get update && apt-get dist-upgrade -y \
	&& apt-get install -y --no-install-recommends \
	$BASE_DEPS \
	$VALGRIND_DEPS \
	$BENCH_DEPS \
	$EXAMPLES_DEPS \
	$DOC_DEPS \
	$TESTS_DEPS \
	$PACKAGING_DEPS \
	$CODECOV_DEPS \
	$COVERITY_DEPS \
	$MISC_DEPS \
	&& ./install-valgrind.sh ubuntu \
	&& rm -rf /var/lib/apt/lists/*

RUN pip3 install $PYTHON_DEPS

# Add and switch user
ENV USER pmdkuser
ENV USERPASS pmdkpass
RUN useradd -m $USER -g sudo -p `mkpasswd $USERPASS`
RUN echo "%sudo ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
USER $USER
