FROM fedora:31
MAINTAINER Giuliano Taffoni <giuliano.taffoni@inaf.it>
ENV CONTAINER_NAME='lofarit_base_system'

#=============================
# Switch to root for install
#=============================
USER root


#=============================
# Set enviroment
#=============================

ENV J=40
ENV INSTALLDIR=/opt/lofar
ENV PYTHON_VERSION=2.7

# Settings relevant to the installed software.
ENV ARMADILLO_VERSION=9.900.3
ENV BLAS_VERSION=3.8.0
ENV BOOST_DOT_VERSION=1.69.0
ENV BOOST_VERSION=1_69_0
ENV CFITSIO_VERSION=7.3.47
ENV FFTW_VERSION=3.5.8
ENV HDF5_VERSION=1.10.5
ENV LAPACK_VERSION=3.8.0
ENV OPENBLAS_VERSION=3.8.0
ENV SUPERLU_VERSION=5.2.1
ENV WCSLIB_VERSION=6.4
ENV DEBIAN_FRONTEND=noninteractive


#=============================
# System installs
#=============================

RUN dnf -y update

# Common packages
RUN dnf -y install dnf-plugins-core
RUN dnf -y install https://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm https://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-$(rpm -E %fedora).noarch.rpm
RUN dnf -y install patch sudo yum-utils git svn wget vim nano emacs \
                   automake autoconf cmake cmake3 make gcc gcc-c++ gcc-gfortran \
                   arpack-devel python-devel python3-devel lapack-devel libpng-devel \
                   libxml2-devel readline-devel ncurses-devel f2py bzip2-devel libicu-devel python3-scipy \
                   python-setuptools gsl gsl-devel gdal gdal-devel libpqxx libpqxx-devel \
                   bison flex ncurses tar bzip2 which gettext  \
                   python python3-devel python-pip python2-tkinter python3-tkinter \
                   libsigc++20-devel gtkmm30-devel lua lua-devel \
                   pgplot python3-numpy-f2py perf qt5 rsync openmpi openmpi-devel htop mariadb-devel python3-pybind11 pybind11-devel

# Install Boost
RUN  dnf -y install boost boost-devel boost-python2 boost-python2-devel boost-python3 boost-python3-devel

# Install FFTW
RUN dnf -y install fftw-devel fftw-libs

# Install OpenBLAS
RUN dnf -y install blas-devel

# Install SuperLU
RUN dnf -y install SuperLU SuperLU-devel

# Install Armadillo
RUN dnf -y install armadillo armadillo-devel

# Install cfitsio
RUN dnf -y install cfitsio cfitsio-devel

# Install wcslib
RUN dnf -y install wcslib wcslib-devel hostname

# Wrap up installation, remove unnecessary stuff.
RUN  dnf -y autoremove
RUN  dnf -y clean all

#=============================
# Create meta user
#=============================

# Add group. We chose GID 65527 to try avoiding conflicts.
RUN groupadd -g 65527 metagroup

# Add user. We chose UID 65527 to try avoiding conflicts.
RUN useradd metauser -d /home/metauser -u 65527 -g 65527 -m -s /bin/bash

# Add metuaser user to sudoers
RUN usermod -a -G wheel metauser

RUN sed -i 's/^%wheel/#%wheel/' /etc/sudoers 
RUN sed -i 's/^# %wheel/%wheel/'  /etc/sudoers
# Rename user home folder as a "vanilla" home folder
RUN mv /home/metauser /metauser_home_vanilla

# Give write access to anyone to the home folder so the entrypoint will be able
# to copy over the /metauser_home_vanilla into /home/metauser (for Singularity)
RUN chmod 777 /home


#=============================
# Switch to metauser
#=============================

USER metauser

