Skip to content

Commit

Permalink
remove separate build stage and use hybrid apt-get + spack
Browse files Browse the repository at this point in the history
  • Loading branch information
gknapp1 committed Sep 11, 2024
1 parent 9bc61ab commit 040a6ff
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 94 deletions.
102 changes: 24 additions & 78 deletions docker/ubuntu
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
# Build stage with Spack pre-installed and ready to be used
FROM spack/ubuntu-jammy:develop AS builder
FROM spack/ubuntu-jammy:develop

# Get Ubuntu packages
RUN apt-get update \
&& apt-get upgrade \
&& apt-get install -y python3-dev python-is-python3 \
build-essential cmake vim emacs wget \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

# What we want to install and how we want to install it
# is specified in a manifest file (spack.yaml)
RUN mkdir -p /opt/spack-environment && \
set -o noclobber \
&& (echo spack: \
&& echo ' specs:' \
&& echo ' - cmake' \
&& echo ' - vim' \
&& echo ' - emacs' \
&& echo ' - wget' \
&& echo ' - py-pip' \
&& echo ' - py-numpy@1.25' \
&& echo ' - py-pyaml' \
&& echo ' - py-polars' \
&& echo ' - py-pandas~performance' \
&& echo ' - py-matplotlib' \
&& echo ' - mesa~llvm' \
&& echo ' - vtk~mpi~opengl2+python' \
&& echo ' - py-h5py' \
&& echo ' - exaca@master' \
&& echo ' - additivefoam@main' \
&& echo ' concretizer:' \
Expand All @@ -28,22 +23,22 @@ set -o noclobber \
&& echo ' install_tree: /opt/software' \
&& echo ' view: /opt/views/view') > /opt/spack-environment/spack.yaml

# Install the software
RUN cd /opt/spack-environment && spack env activate . && spack install --fail-fast

# Strip all the binaries
RUN find -L /opt/views/view/* -type f -exec readlink -f '{}' \; | \
# Build the spack environment
RUN cd /opt/spack-environment \
&& spack env activate . \
&& spack external find \
&& spack install --fail-fast \
&& find -L /opt/views/view/* -type f -exec readlink -f '{}' \; | \
xargs file -i | \
grep 'charset=binary' | \
grep 'x-executable\|x-archive\|x-sharedlib' | \
awk -F: '{print $1}' | xargs strip
awk -F: '{print $1}' | xargs strip \
&& spack gc -y

# Modifications to the environment that are necessary to run
RUN cd /opt/spack-environment && \
spack env activate --sh -d . > activate.sh


# This section should eventually be moved into spack installs
# Install 3DThesis
ENV THESIS_DIR=/opt/3DThesis
RUN . /opt/spack-environment/activate.sh && \
Expand All @@ -53,47 +48,15 @@ RUN . /opt/spack-environment/activate.sh && \
wget --quiet ${THESIS_URL} --output-document=${THESIS_ARCHIVE} && \
mkdir -p 3dthesis && \
tar -xf ${THESIS_ARCHIVE} -C 3dthesis --strip-components=1 && \
rm -f ${THESIS_ARCHIVE} && \
cd 3dthesis && \
cmake -B build \
-D CMAKE_INSTALL_PREFIX=${THESIS_DIR} \
-D CMAKE_BUILD_TYPE=Debug && \
cmake --build build && \
cmake --install build
RUN echo 'PATH="/opt/3DThesis/bin:$PATH"' >> activate.sh
RUN echo 'export PATH="/opt/3DThesis/bin:$PATH"' >> activate.sh

# Get Mist
ENV MIST_DIR=/opt/mist
RUN . /opt/spack-environment/activate.sh && \
MIST_VERSION=main.tar.gz && \
MIST_ARCHIVE=mist-${MIST_VERSION} && \
MIST_URL=https://github.com/ORNL-MDF/Mist/archive/refs/heads/${MIST_VERSION} && \
wget --quiet ${MIST_URL} --output-document=${MIST_ARCHIVE} && \
mkdir -p ${MIST_DIR} && \
tar -xf ${MIST_ARCHIVE} -C ${MIST_DIR} --strip-components=1 && \
python3 -m pip --upgrade && \
python3 -m pip install ${MIST_DIR} --root-user-action=ignore
# Get bnpy
ENV BNPY_DIR=/opt/bnpy
RUN . /opt/spack-environment/activate.sh && \
BNPY_VERSION=master.tar.gz && \
BNPY_ARCHIVE=bnpy-${BNPY_VERSION} && \
BNPY_URL=https://github.com/gknapp1/bnpy/archive/refs/heads/${BNPY_VERSION} && \
wget --quiet ${BNPY_URL} --output-document=${BNPY_ARCHIVE} && \
mkdir -p ${BNPY_DIR} && \
tar -xf ${BNPY_ARCHIVE} -C ${BNPY_DIR} --strip-components=1 && \
python3 -m pip --upgrade && \
python3 -m pip install ${BNPY_DIR} --root-user-action=ignore
# Get pyebsd
ENV PYEBSD_DIR=/opt/pyebsd
RUN . /opt/spack-environment/activate.sh && \
PYEBSD_VERSION=master.tar.gz && \
PYEBSD_ARCHIVE=pyebsd-${PYEBSD_VERSION} && \
PYEBSD_URL=https://github.com/arthursn/pyebsd/archive/refs/heads/${PYEBSD_VERSION} && \
wget --quiet ${PYEBSD_URL} --output-document=${PYEBSD_ARCHIVE} && \
mkdir -p ${PYEBSD_DIR} && \
tar -xf ${PYEBSD_ARCHIVE} -C ${PYEBSD_DIR} --strip-components=1 && \
python3 -m pip --upgrade && \
python3 -m pip install ${PYEBSD_DIR} --root-user-action=ignore
# Get Myna
ENV MYNA_DIR=/opt/myna
RUN . /opt/spack-environment/activate.sh && \
Expand All @@ -103,27 +66,12 @@ RUN . /opt/spack-environment/activate.sh && \
wget --quiet ${MYNA_URL} --output-document=${MYNA_ARCHIVE} && \
mkdir -p ${MYNA_DIR} && \
tar -xf ${MYNA_ARCHIVE} -C ${MYNA_DIR} --strip-components=1 && \
rm -f ${MYNA_ARCHIVE} && \
python3 -m pip --upgrade && \
python3 -m pip install ${MYNA_DIR} --root-user-action=ignore

# Clean up packages
RUN spack gc -y


# Bare OS image to run the installed executables
FROM ubuntu:22.04

COPY --from=builder /opt/spack-environment /opt/spack-environment
COPY --from=builder /opt/software /opt/software
COPY --from=builder /opt/3DThesis /opt/3DThesis
COPY --from=builder /opt/mist /opt/mist
COPY --from=builder /opt/bnpy /opt/bnpy
COPY --from=builder /opt/pyebsd /opt/pyebsd
COPY --from=builder /opt/myna /opt/myna

# paths.view is a symlink, so copy the parent to avoid dereferencing and duplicating it
COPY --from=builder /opt/views /opt/views
python3 -m pip install ${MYNA_DIR} --root-user-action=ignore && \
python3 -m pip cache purge

# Set entry point
RUN { \
echo '#!/bin/sh' \
&& echo '.' /opt/spack-environment/activate.sh \
Expand All @@ -132,7 +80,5 @@ RUN { \
&& chmod a+x /entrypoint.sh \
&& ln -s /opt/views/view /opt/view


ENTRYPOINT [ "/entrypoint.sh" ]
CMD [ "/bin/bash" ]

CMD [ "/bin/bash" ]
16 changes: 0 additions & 16 deletions spack.yaml
Original file line number Diff line number Diff line change
@@ -1,21 +1,5 @@
spack:
specs:
- cmake
- vim
- emacs
- wget
# (can eventually be removed with myna install)
- py-pip
- py-numpy@1.25
- py-pyaml
- py-polars
# Enabling "performance" substantially increases build times
- py-pandas~performance
- py-matplotlib
# Only to simplify the stack (vtk dep)
- mesa~llvm
- vtk~mpi~opengl2+python
- py-h5py
# Myna apps (can eventually be replaced with "myna +exaca +additivefoam")
- exaca@master
- additivefoam@main

0 comments on commit 040a6ff

Please sign in to comment.