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

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

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

# Set required environment variables
ENV OS archlinux-base
ENV OS_VER latest
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 pacman cache and install basic tools
RUN pacman -Syu --noconfirm
RUN pacman -S --noconfirm \
	asciidoc \
	autoconf \
	automake \
	bash-completion \
	clang \
	cmake \
	doxygen \
	file \
	gcc \
	gdb \
	git \
	graphviz \
	gzip \
	intel-tbb \
	libunwind \
	llvm \
	make \
	numactl \
	pandoc \
	perl-text-diff \
	pkg-config \
	sfml \
	sudo \
	wget \
	which \
	whois \
	xmlto

# Install rapidjson from sources
COPY install-rapidjson.sh install-rapidjson.sh
RUN ./install-rapidjson.sh

# Install libndctl
COPY install-libndctl.sh install-libndctl.sh
RUN ./install-libndctl.sh archlinux-base

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

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

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

# Install memkind
COPY install-memkind.sh install-memkind.sh
RUN ./install-memkind.sh

# 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 gpasswd wheel -a $USER
USER $USER

# Clean the cache of packages
RUN rm -rf /var/cache/pacman/pkg/*
