Skip to content
This repository was archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
Began process to develop a more robust set of build scripts for all o…
Browse files Browse the repository at this point in the history
…f my test platforms
  • Loading branch information
daminton committed Aug 11, 2023
1 parent 1f62eaf commit c052e4c
Show file tree
Hide file tree
Showing 10 changed files with 462 additions and 173 deletions.
20 changes: 20 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Ignore everything
*
# Whitelist what is necessary
!setup.py
!version.txt
!environment.yml
!pyproject.toml
!requirements.txt
!distclean.cmake
!cmake/Modules/*.cmake
!CMakeLists.txt
!src/CMakeLists.txt
!swiftest/CMakeLists.txt
!swiftest/tests/CMakeLists.txt
!swiftest/*.py
!swiftest/*.pyx
!swiftest/*.h
!swiftest/tests/*.py
!src/*/*.f90
!buildscripts/*.sh
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,13 @@ dump*
!singularity/
!Dockerfile
!environment.yml
!.dockerignore

bin/
build/*
hdf5-*
netcdf-c-*
netcdf-fortran-*
zlib-*


348 changes: 180 additions & 168 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,172 +13,184 @@
# dynamically.

# This build target compiles all dependencies and the swiftest driver itself
FROM intel/oneapi-hpckit:2023.1.0-devel-ubuntu20.04 as build_deps

ENV INSTALL_DIR="/usr/local"
ENV FC="${ONEAPI_ROOT}/mpi/latest/bin/mpiifort"
ENV CC="${ONEAPI_ROOT}/mpi/latest/bin/mpicc -cc=icx"
ENV CXX="${ONEAPI_ROOT}/mpi/latest/bin/mpicc -cc=icpx"
ENV F77="${FC}"
ENV CFLAGS="-fPIC"

# Get the HDF5, NetCDF-C, and NetCDF-Fortran libraries
RUN wget -qO- https://support.hdfgroup.org/ftp/HDF5/releases/hdf5-1.14/hdf5-1.14.1/src/hdf5-1.14.1-2.tar.gz | tar xvz && \
wget -qO- https://github.com/Unidata/netcdf-c/archive/refs/tags/v4.9.2.tar.gz | tar xvz && \
wget -qO- https://github.com/Unidata/netcdf-fortran/archive/refs/tags/v4.6.1.tar.gz | tar xvz && \
wget -qO- https://www.zlib.net/zlib-1.2.13.tar.gz | tar xvz

RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
m4 && \
rm -rf /var/lib/apt/lists/*

RUN cd zlib-1.2.13 && \
./configure --prefix=${INSTALL_DIR} --static && \
make && \
make install

RUN cd hdf5-1.14.1-2 && \
./configure --disable-shared \
--enable-build-mode=production \
--disable-fortran \
--disable-java \
--disable-cxx \
--prefix=${INSTALL_DIR} \
--with-zlib=${INSTALL_DIR} && \
make && \
make install

RUN cd netcdf-c-4.9.2 && \
./configure --disable-shared \
--disable-dap \
--disable-libxml2 \
--disable-byterange \
--prefix=${INSTALL_DIR} && \
make && \
make install

ENV NCDIR="${INSTALL_DIR}"
ENV NFDIR="${INSTALL_DIR}"
ENV HDF5_ROOT="${INSTALL_DIR}"
ENV HDF5_LIBDIR="${HDF5_ROOT}/lib"
ENV HDF5_INCLUDE_DIR="${HDF5_ROOT}/include"
ENV HDF5_PLUGIN_PATH="${HDF5_LIBDIR}/plugin"

# NetCDF-Fortran library
ENV FCFLAGS="${CFLAGS} -standard-semantics"
ENV FFLAGS=${CFLAGS}
ENV CPPFLAGS="-I${INSTALL_DIR}/include"
ENV LIBS="-L/usr/local/lib -L/usr/lib/x86_64-linux-gnu -lnetcdf -lhdf5_hl -lhdf5 -lm -lz"
RUN cd netcdf-fortran-4.6.1 && \
./configure --disable-shared --prefix=${NFDIR} && \
make && \
make install

FROM intel/oneapi-hpckit:2023.1.0-devel-ubuntu20.04 as build_driver
SHELL ["/bin/bash", "-c"]

# The MACHINE_CODE_VALUE argument is a string that is used when compiling the swiftest_driver. It is appended to the "-x" compiler
# option: (-x${MACHINE_CODE_VALUE}). The default value is set to "sse2" which allows for certain SIMD instructions to be used while
# remaining # compatible with a wide range of CPUs. To get the highest performance, you can pass "host" as an argument, but the
# compiled binary # would only run on a CPU with an architecture compatible with the one that the build was performed on.
# For more details and other options, see:
# https://www.intel.com/content/www/us/en/docs/fortran-compiler/developer-guide-reference/2023-1/x-qx.html
ARG MACHINE_CODE_VALUE="sse2"

ARG BUILD_TYPE="RELEASE"

# Additional CMAKE options:
ARG EXTRA_CMAKE_OPTIONS=""

ENV INSTALL_DIR="/usr/local"
ENV NETCDF_HOME=${INSTALL_DIR}
ENV NETCDF_FORTRAN_HOME=${NETCDF_HOME}
ENV NETCDF_LIBRARY=${NETCDF_HOME}
ENV FOR_COARRAY_NUM_IMAGES=1
ENV OMP_NUM_THREADS=1
ENV FC="${ONEAPI_ROOT}/mpi/latest/bin/mpiifort"
ENV CC="${ONEAPI_ROOT}/mpi/latest/bin/mpicc"
ENV CXX="${ONEAPI_ROOT}/mpi/latest/bin/mpicxx"
ENV FFLAGS="-fPIC -standard-semantics"
ENV LDFLAGS="-L${INSTALL_DIR}/lib"
ENV LIBS="-lhdf5_hl -lhdf5 -lz"
ENV PATH /root/miniconda3/bin:$PATH

COPY --from=build_deps ${INSTALL_DIR}/. ${INSTALL_DIR}/

COPY ./environment.yml /swiftest/

RUN wget https://repo.anaconda.com/miniconda/Miniconda3-py311_23.5.2-0-Linux-x86_64.sh && \
/bin/bash Miniconda3-py311_23.5.2-0-Linux-x86_64.sh -b && \
/root/miniconda3/bin/conda init bash && \
source /root/.bashrc && conda update --all -y && \
conda install conda-libmamba-solver -y && \
conda config --set solver libmamba && \
cd swiftest && \
conda env create -f environment.yml && \
conda init bash && \
echo "conda activate swiftest-env" >> ~/.bashrc && \
source ~/.bashrc && \
conda install -c conda-forge scikit-build -y&& \
conda install -c anaconda cython -y

COPY ./cmake/ /swiftest/cmake/
COPY ./src/ /swiftest/src/
COPY ./CMakeLists.txt /swiftest/
COPY ./swiftest/ /swiftest/swiftest/
COPY ./version.txt /swiftest/
COPY ./setup.py /swiftest/
COPY ./requirements.txt /swiftest/
COPY ./pyproject.toml /swiftest/
RUN cd swiftest && \
pip install . -v

# This build target creates a container that executes just the driver program
FROM ubuntu:20.04 as driver
COPY --from=build_driver /usr/local/bin/swiftest_driver /usr/local/bin/
ENTRYPOINT ["/usr/local/bin/swiftest_driver"]

# This build target exports the binary to the host
FROM scratch AS export_driver
COPY --from=build_driver /usr/local/bin/swiftest_driver /

# This build target exports the static library to the host
FROM scratch as export_library
COPY --from=build_driver /usr/local/lib/libswiftest.a /

# This build target exports the module file to the host
FROM scratch as export_module
COPY --from=build_driver /swiftest/include/ /swiftest/

# This build target creates a container with a conda environment with all dependencies needed to run the Python front end and
# analysis tools
FROM continuumio/miniconda3 as python
ARG BUILDIMAGE="intel/oneapi-hpckit:2023.1.0-devel-ubuntu20.04"
FROM ${BUILDIMAGE} as build-deps
SHELL ["/bin/bash", "--login", "-c"]
ENV INSTALL_DIR="/usr/local"
ENV CONDA_DIR="/opt/conda"
ENV SHELL="/bin/bash"
ENV PATH="${CONDA_DIR}/bin:${PATH}"
ENV LD_LIBRARY_PATH="${INSTALL_DIR}/lib"

COPY --from=build_driver ${INSTALL_DIR}/bin/swiftest_driver ${CONDA_DIR}/bin/swiftest_driver
COPY --from=build_driver ${INSTALL_DIR}/lib/libswiftest.a ${CONDA_DIR}/conda/lib/libswiftest.a
COPY --from=build_driver /swiftest/include/ ${CONDA_DIR}/include/swiftest/
COPY ./python/. ${CONDA_DIR}/pkgs/swiftest/
COPY environment.yml .

RUN conda update --all -y && \
conda install conda-libmamba-solver -y && \
conda config --set solver libmamba && \
conda env create -f environment.yml && \
conda init bash && \
echo "conda activate swiftest-env" >> ~/.bashrc && \
conda clean --all -y && \
mkdir -p /.astropy && \
chmod -R 777 /.astropy && \
mkdir -p /.cache/matplotlib && \
mkdir -p /.config/matplotlib && \
chmod -R 777 /.cache/matplotlib && \
chmod -R 777 /.config/matplotlib

ENTRYPOINT ["conda", "run", "--no-capture-output", "-n", "swiftest-env"]
WORKDIR /swiftest
COPY . ./
RUN buildscripts/fetch_dependencies.sh
RUN if [ "$BUILDIMAGE" = "intel/oneapi-hpckit:2023.1.0-devel-ubuntu20.04" ]; then \
buildscripts/build_dependencies.sh Intel; \
else \
conda init bash && \
conda update --all -y && \
conda env create --file environment.yml --name swiftest-build-env && \
echo "conda activate swiftest-build-env" >> ~/.bashrc && \
source ~/.bashrc && \
conda update all -y && \
conda install -c conda-forge scikit-build cython cmake gfortran -y &&\
buildscripts/build_dependencies.sh GNU; \
fi

# RUN buildscripts/make_environment.sh
# RUN echo "conda activate swiftest-build-env" >> ~/.bashrc
# RUN source ~/.bashrc && conda activate swiftest-build-env
# RUN conda update all -y
# RUN conda install -c conda-forge scikit-build cython cmake gfortran --name swiftest-build-env -y
# RUN buildscripts/build_dependencies.sh GNU

# ENV INSTALL_DIR="/usr/local"
# ENV FC="${ONEAPI_ROOT}/mpi/latest/bin/mpiifort"
# ENV CC="${ONEAPI_ROOT}/mpi/latest/bin/mpicc -cc=icx"
# ENV CXX="${ONEAPI_ROOT}/mpi/latest/bin/mpicc -cc=icpx"
# ENV F77="${FC}"
# ENV CFLAGS="-fPIC"

# # Get the HDF5, NetCDF-C, and NetCDF-Fortran libraries
# RUN wget -qO- https://support.hdfgroup.org/ftp/HDF5/releases/hdf5-1.14/hdf5-1.14.1/src/hdf5-1.14.1-2.tar.gz | tar xvz && \
# wget -qO- https://github.com/Unidata/netcdf-c/archive/refs/tags/v4.9.2.tar.gz | tar xvz && \
# wget -qO- https://github.com/Unidata/netcdf-fortran/archive/refs/tags/v4.6.1.tar.gz | tar xvz && \
# wget -qO- https://www.zlib.net/zlib-1.2.13.tar.gz | tar xvz

# RUN apt-get update && \
# DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
# m4 && \
# rm -rf /var/lib/apt/lists/*

# RUN cd zlib-1.2.13 && \
# ./configure --prefix=${INSTALL_DIR} --static && \
# make && \
# make install

# RUN cd hdf5-1.14.1-2 && \
# ./configure --disable-shared \
# --enable-build-mode=production \
# --disable-fortran \
# --disable-java \
# --disable-cxx \
# --prefix=${INSTALL_DIR} \
# --with-zlib=${INSTALL_DIR} && \
# make && \
# make install

# RUN cd netcdf-c-4.9.2 && \
# ./configure --disable-shared \
# --disable-dap \
# --disable-libxml2 \
# --disable-byterange \
# --prefix=${INSTALL_DIR} && \
# make && \
# make install

# ENV NCDIR="${INSTALL_DIR}"
# ENV NFDIR="${INSTALL_DIR}"
# ENV HDF5_ROOT="${INSTALL_DIR}"
# ENV HDF5_LIBDIR="${HDF5_ROOT}/lib"
# ENV HDF5_INCLUDE_DIR="${HDF5_ROOT}/include"
# ENV HDF5_PLUGIN_PATH="${HDF5_LIBDIR}/plugin"

# # NetCDF-Fortran library
# ENV FCFLAGS="${CFLAGS} -standard-semantics"
# ENV FFLAGS=${CFLAGS}
# ENV CPPFLAGS="-I${INSTALL_DIR}/include"
# ENV LIBS="-L/usr/local/lib -L/usr/lib/x86_64-linux-gnu -lnetcdf -lhdf5_hl -lhdf5 -lm -lz"
# RUN cd netcdf-fortran-4.6.1 && \
# ./configure --disable-shared --prefix=${NFDIR} && \
# make && \
# make install

# FROM intel/oneapi-hpckit:2023.1.0-devel-ubuntu20.04 as build_driver
# SHELL ["/bin/bash", "-c"]

# # The MACHINE_CODE_VALUE argument is a string that is used when compiling the swiftest_driver. It is appended to the "-x" compiler
# # option: (-x${MACHINE_CODE_VALUE}). The default value is set to "sse2" which allows for certain SIMD instructions to be used while
# # remaining # compatible with a wide range of CPUs. To get the highest performance, you can pass "host" as an argument, but the
# # compiled binary # would only run on a CPU with an architecture compatible with the one that the build was performed on.
# # For more details and other options, see:
# # https://www.intel.com/content/www/us/en/docs/fortran-compiler/developer-guide-reference/2023-1/x-qx.html
# ARG MACHINE_CODE_VALUE="sse2"

# ARG BUILD_TYPE="RELEASE"

# # Additional CMAKE options:
# ARG EXTRA_CMAKE_OPTIONS=""

# ENV INSTALL_DIR="/usr/local"
# ENV NETCDF_HOME=${INSTALL_DIR}
# ENV NETCDF_FORTRAN_HOME=${NETCDF_HOME}
# ENV NETCDF_LIBRARY=${NETCDF_HOME}
# ENV FOR_COARRAY_NUM_IMAGES=1
# ENV OMP_NUM_THREADS=1
# ENV FC="${ONEAPI_ROOT}/mpi/latest/bin/mpiifort"
# ENV CC="${ONEAPI_ROOT}/mpi/latest/bin/mpicc"
# ENV CXX="${ONEAPI_ROOT}/mpi/latest/bin/mpicxx"
# ENV FFLAGS="-fPIC -standard-semantics"
# ENV LDFLAGS="-L${INSTALL_DIR}/lib"
# ENV LIBS="-lhdf5_hl -lhdf5 -lz"
# ENV PATH /root/miniconda3/bin:$PATH

# COPY --from=build_deps ${INSTALL_DIR}/. ${INSTALL_DIR}/

# COPY ./environment.yml /swiftest/

# RUN wget https://repo.anaconda.com/miniconda/Miniconda3-py311_23.5.2-0-Linux-x86_64.sh && \
# /bin/bash Miniconda3-py311_23.5.2-0-Linux-x86_64.sh -b && \
# /root/miniconda3/bin/conda init bash && \
# source /root/.bashrc && conda update --all -y && \
# conda install conda-libmamba-solver -y && \
# conda config --set solver libmamba && \
# cd swiftest && \
# conda env create -f environment.yml && \
# conda init bash && \
# echo "conda activate swiftest-env" >> ~/.bashrc && \
# source ~/.bashrc && \
# conda install -c conda-forge scikit-build -y&& \
# conda install -c anaconda cython -y

# COPY ./cmake/ /swiftest/cmake/
# COPY ./src/ /swiftest/src/
# COPY ./CMakeLists.txt /swiftest/
# COPY ./swiftest/ /swiftest/swiftest/
# COPY ./version.txt /swiftest/
# COPY ./setup.py /swiftest/
# COPY ./requirements.txt /swiftest/
# COPY ./pyproject.toml /swiftest/

# ENV CMAKE_ARGS="-DMACHINE_CODE_VALUE=${MACHINE_CODE_VALUE} -DCMAKE_BUILD_TYPE=${BUILD_TYPE} -DBUILD_SHARED_LIBS=OFF ${EXTRA_CMAKE_OPTIONS}"

# # RUN cd swiftest && \
# # pip install . -v

# # This build target creates a container that executes just the driver program
# FROM ubuntu:20.04 as driver
# COPY --from=build_driver /root/miniconda3/envs/swiftest-env/bin/swiftest_driver /usr/local/bin/
# ENTRYPOINT ["/usr/local/bin/swiftest_driver"]

# # This build target exports the binary to the host
# FROM scratch AS export_driver
# COPY --from=driver /usr/local/bin/swiftest_driver /

# # This build target creates a container with a conda environment with all dependencies needed to run the Python front end and
# # analysis tools
# FROM continuumio/miniconda3 as python
# SHELL ["/bin/bash", "--login", "-c"]
# ENV INSTALL_DIR="/usr/local"
# ENV CONDA_DIR="/opt/conda"
# ENV SHELL="/bin/bash"
# ENV PATH="${CONDA_DIR}/bin:${PATH}"

# COPY --from=build_driver /root/miniconda3/envs/swiftest-env/ ${CONDA_DIR}/envs/
# RUN conda update --all -y && \
# conda install conda-libmamba-solver -y && \
# conda config --set solver libmamba && \
# conda init bash && \
# echo "conda activate swiftest-env" >> ~/.bashrc && \
# conda clean --all -y && \
# mkdir -p /.astropy && \
# chmod -R 777 /.astropy && \
# mkdir -p /.cache/matplotlib && \
# mkdir -p /.config/matplotlib && \
# chmod -R 777 /.cache/matplotlib && \
# chmod -R 777 /.config/matplotlib

# ENTRYPOINT ["conda", "run", "--no-capture-output", "-n", "swiftest-env"]
1 change: 1 addition & 0 deletions buildscripts/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
!*.sh
Loading

0 comments on commit c052e4c

Please sign in to comment.