# Generates a Docker container with an installed GenTen built with clang
# compilers and OpenMP thread parallelism.
#
# This is intended to be run from the top-level genten source tree

# Base image -- Need to using testing for newer CMake
#FROM debian:testing
#FROM debian:stable
FROM ubuntu:20.04
MAINTAINER Eric Phipps <etphipp@sandia.gov>

# Change to bash so we have, e.g., -o pipefail
SHELL ["/bin/bash", "-c"]

# Install GenTen dependencies
RUN \
  apt-get update --yes && \
  apt-get install --yes \
    cmake \
    libblas-dev \
    liblapack-dev \
    libboost-iostreams-dev \
    libomp-dev \
    clang \
    gfortran \
    && \
  rm -rf /var/lib/apt/lists/*

#apt-get dist-upgrade --yes && \

# Install useful utilities
RUN \
  apt-get update --yes && \
  apt-get install --yes \
    vim \
    libgpm2 \
    libcanberra0 \
    && \
    rm -rf /var/lib/apt/lists/*

# Add genten src
RUN mkdir -p /src
COPY . /src/genten

ARG ARCH=BDW

# Setup environment
ENV \
  OMP_PROC_BIND=spread \
  OMP_PLACES=threads \
  GENTEN_ARCH=${ARCH} \
  GENTEN_SRC_PATH=/src/genten \
  GENTEN_INSTALL_PATH=/usr

# Build and install genten
RUN \
  set -o pipefail && \
  mkdir -p /build/genten  && \
  cd /build/genten && \
  /src/genten/scripts/gitlab_clang/do_configure.sh 2>&1 | tee cmake_output.txt && \
  make -j4 install 2>&1 | tee make_output.txt
