FROM  centos:centos7

##  Following hack is required for Centos7 image as Centos7 is EOL.
## yum-config-manager --nogpgcheck  --add-repo https://archive.kernel.org/centos-vault/7.9.2009/os/x86_64/Packages/
## yum-config-manager --nogpgcheck  --add-repo http://archive.kernel.org/centos-vault/7.9.2009/updates/x86_64/
## yum-config-manager --nogpgcheck  --add-repo https://mirror.nsc.liu.se/centos-store/7.9.2009/os/x86_64/Packages/
## yum-config-manager --nogpgcheck  --add-repo https://mirror.nsc.liu.se/centos-store/7.9.2009/updates/x86_64/Packages/

ENV CFPREFIX=/software/crystfel/devel
ENV PKG_CONFIG_PATH=$CFPREFIX/lib64/pkgconfig:$CFPREFIX/lib/pkgconfig
ENV LD_LIBRARY_PATH=$CFPREFIX/lib64:$CFPREFIX/lib
ENV LD_RUN_PATH=$CFPREFIX/lib64:$CFPREFIX/lib
ENV PATH=$CFPREFIX/bin:/opt/cmake-3.18.2-Linux-x86_64/bin/:$PATH

RUN  yum-config-manager --disable \* && \
     yum-config-manager --nogpgcheck  --add-repo https://vault.centos.org/7.9.2009/os/x86_64/ && \
     yum-config-manager --nogpgcheck  --add-repo https://vault.centos.org/7.9.2009/updates/x86_64/ **\
     yum-config-manager --enable vault.centos.org_7.9.2009_os_x86_64_ && \
     yum-config-manager --save --setopt=vault.centos.org_7.9.2009_os_x86_64_.gpgkey="file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7" && \
     yum-config-manager --enable vault.centos.org_7.9.2009_updates_x86_64_ && \
     yum-config-manager --save --setopt=vault.centos.org_7.9.2009_updates_x86_64_.gpgkey="file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7"

RUN    yum -y update ; \
       yum -y group install  'Development Tools' ; \
       yum -y install  flex bison gcc-c++  gcc-gfortran gtk3-devel cairo-devel \
              pango-devel gdk-pixbuf2-devel libpng-devel diffutils \
              zeromq-devel python3-devel which wget lz4 lz4-devel \
              bzip2-libs bzip2-devel libcurl-devel openssh-clients cmake

RUN    python3 -m ensurepip --upgrade && python3 -m pip  install meson ninja

# CMake
RUN cd /opt; \
    wget -nv https://github.com/Kitware/CMake/releases/download/v3.18.2/cmake-3.18.2-Linux-x86_64.tar.gz; \
    tar -xzf cmake-3.18.2-Linux-x86_64.tar.gz; \
    rm  ./cmake-3.18.2-Linux-x86_64.tar.gz

# HDF5
RUN    wget -nv https://support.hdfgroup.org/ftp/HDF5/releases/hdf5-1.12/hdf5-1.12.1/src/hdf5-1.12.1.tar.bz2 ; \
       tar -xf hdf5-1.12.1.tar.bz2 ; \
       pushd hdf5-1.12.1; \
       ./configure --prefix=$CFPREFIX \
                --enable-shared  --disable-static \
                --with-default-plugindir=${CFPREFIX}/lib64/plugins ;\
       make -j 32; \
       make install; \
       popd; \ 
       rm -rf hdf5-1.12.1 hdf5-1.12.1.tar.bz2

# HDF5 filter plugins
RUN    git clone --depth 1 https://github.com/nexusformat/HDF5-External-Filter-Plugins.git ; \
       pushd HDF5-External-Filter-Plugins; \
       mkdir build; \
       pushd build; \
       cmake .. -DCMAKE_INSTALL_PREFIX=$CFPREFIX \
                -DENABLE_BITSHUFFLE_PLUGIN=yes \
                -DENABLE_LZ4_PLUGIN=yes \
                -DENABLE_BZIP2_PLUGIN=yes \
                -DCMAKE_BUILD_TYPE=Release ; \
       popd; \
       make -C build -j 32; \
       make -C build install; \
       popd ; \
       rm -rf HDF5-External-Filter-Plugins

# GSL
RUN    wget -nv http://ftp.fau.de/gnu/gsl/gsl-2.6.tar.gz ; \
       tar -xzf gsl-2.6.tar.gz ; \
       pushd gsl-2.6 ; \
       ./configure --prefix=$CFPREFIX ; \
       make -j 32 ; \
       make install ; \
       popd ; \
       rm -rf gsl-2.6 gsl-2.6.tar.gz
    
# FFTW
RUN    wget -nv http://fftw.org/fftw-3.3.9.tar.gz ; \
       tar -xzf fftw-3.3.9.tar.gz ; \
       pushd fftw-3.3.9 ; \
       ./configure --enable-shared --prefix=$CFPREFIX ; \
       make -j 32 ; \
       make install ; \
       popd ; \
       rm -rf fftw-3.3.9 fftw-3.3.9.tar.gz ; 

# MsgPack
RUN    wget -nv https://github.com/msgpack/msgpack-c/releases/download/cpp-3.3.0/msgpack-3.3.0.tar.gz ; \
       tar -xzf msgpack-3.3.0.tar.gz ;  \
       pushd msgpack-3.3.0; \
       mkdir build; \
       pushd build; \
       cmake .. -DCMAKE_INSTALL_PREFIX=$CFPREFIX \
                -DMSGPACK_BUILD_EXAMPLES=OFF \
                -DMSGPACK_ENABLE_CXX=OFF \
                -DCMAKE_BUILD_TYPE=Release ; \
       popd ; \
       make -C build -j 32 ; \
       make -C build install ; \
       popd ; \
       rm -rf msgpack-3.3.0 msgpack-3.3.0.tar.gz

# ASAP::O
RUN    git clone https://gitlab.desy.de/asapo/asapo.git ; \
       pushd asapo ; \
       git checkout 24.11.1 ; \
       mkdir build ; \
       pushd build ; \
       cmake .. -GNinja -DBUILD_CLIENTS_ONLY=ON -DBUILD_PYTHON=OFF \
                -DCMAKE_INSTALL_PREFIX=$CFPREFIX \
                -DCMAKE_BUILD_TYPE=RelWithDebInfo ; \
       popd ; \
       ninja -C build ; \
       ninja -C build install  ; \
       popd

# Seedee
RUN    git clone https://gitlab.desy.de/fs-sc/seedee.git ; \
       pushd seedee ; \
       mkdir build ; \
       cd build ; \
       cmake .. -GNinja -DCMAKE_INSTALL_PREFIX=$CFPREFIX -DCMAKE_BUILD_TYPE=RelWithDebInfo ; \
       cd .. ; \
       ninja -C build ; \
       ninja -C build install ; \
       popd
