Skip to content

Commit

Permalink
Separate out spack.yaml; Dockerfile optimisations
Browse files Browse the repository at this point in the history
  • Loading branch information
jwallwork23 committed Aug 29, 2024
1 parent b12e037 commit 78ec591
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 34 deletions.
58 changes: 24 additions & 34 deletions docker/Dockerfile.devenv
Original file line number Diff line number Diff line change
@@ -1,32 +1,18 @@
# Build stage with Spack pre-installed and ready to be used
FROM spack/ubuntu-jammy:0.21 AS builder

# What we want to install and how we want to install it
# is specified in a manifest file (spack.yaml)
RUN mkdir /opt/spack-environment \
&& (echo spack: \
&& echo ' packages:' \
&& echo ' all:' \
&& echo ' compiler: [gcc@11.4.0]' \
&& echo ' specs:' \
&& echo ' - cmake@3.27.7' \
&& echo ' - gmake' \
&& echo ' - hdf5@1.14.3' \
&& echo ' - netcdf-c@4.9.2+mpi+parallel-netcdf' \
&& echo ' - netcdf-fortran' \
&& echo ' - openmpi@4.1.6' \
&& echo ' concretizer:' \
&& echo ' unify: true' \
&& echo ' config:' \
&& echo ' install_missing_compilers: true' \
&& echo ' install_tree: /opt/software' \
&& echo ' view: /opt/views/view') > /opt/spack-environment/spack.yaml

# Install the software, remove unnecessary deps
RUN cd /opt/spack-environment && spack env activate . && spack install --fail-fast && spack gc -y
# Install software from spack.yaml
RUN mkdir /opt/spack-environment
COPY docker/spack.yaml /opt/spack-environment/spack.yaml
RUN cd /opt/spack-environment \
&& spack env activate . \
&& spack install --fail-fast \
&& spack gc -y

# Install perl URI lib
RUN apt update && apt install -y libany-uri-escape-perl
RUN apt update \
&& apt install -y --no-install-recommends libany-uri-escape-perl \
&& rm -rf /var/lib/apt/lists/*

# Strip all the binaries
RUN find -L /opt/views/view/* -type f -exec readlink -f '{}' \; | \
Expand All @@ -36,27 +22,31 @@ RUN find -L /opt/views/view/* -type f -exec readlink -f '{}' \; | \
awk -F: '{print $1}' | xargs strip

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

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

# Copy necessary files from the builder stage
COPY --from=builder /opt/spack-environment /opt/spack-environment
COPY --from=builder /opt/software /opt/software
COPY --from=builder /usr /usr

# paths.view is a symlink, so copy the parent to avoid dereferencing and duplicating it
COPY --from=builder /opt/views /opt/views

# Create entrypoint script
RUN { \
echo '#!/bin/sh' \
&& echo '.' /opt/spack-environment/activate.sh \
&& echo 'exec "$@"'; \
echo '#!/bin/sh'; \
echo '. /opt/spack-environment/activate.sh'; \
echo 'exec "$@"'; \
} > /entrypoint.sh \
&& chmod a+x /entrypoint.sh \
&& ln -s /opt/views/view /opt/view \
&& apt update && apt install -y ca-certificates cpp m4
&& chmod a+x /entrypoint.sh \
&& ln -s /opt/views/view /opt/view \
&& apt update \
&& apt install -y --no-install-recommends ca-certificates cpp m4
&& rm -rf /var/lib/apt/lists/*

# Set entrypoint and default command
ENTRYPOINT [ "/entrypoint.sh" ]
CMD [ "/bin/bash" ]
17 changes: 17 additions & 0 deletions docker/spack.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
spack:
packages:
all:
compiler: [gcc@11.4.0]
specs:
- cmake
- gmake
- hdf5
- netcdf-c+mpi+parallel-netcdf
- netcdf-fortran
- openmpi
concretizer:
unify: true
config:
install_missing_compilers: true
install_tree: /opt/software
view: /opt/views/view

0 comments on commit 78ec591

Please sign in to comment.