Skip to content

Commit 833b91d

Browse files
Multi stage docker file
1 parent 6cf880e commit 833b91d

File tree

1 file changed

+25
-15
lines changed

1 file changed

+25
-15
lines changed

spack/Dockerfile

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
# syntax=docker/dockerfile:1
1+
# syntax=docker/dockerfile:1.3
22
ARG BASEIMAGE=ubuntu:22.04
33

4-
FROM $BASEIMAGE
4+
FROM $BASEIMAGE AS base
55

66
ARG SPACK_VERSION=0.19.0
77
ARG RECIPES_BRANCH=main
@@ -30,21 +30,31 @@ ADD import_signing_key.sh /tmp
3030

3131
RUN --mount=type=secret,id=signingkey,uid=1000 /tmp/import_signing_key.sh /run/secrets/signingkey
3232

33-
RUN --mount=type=cache,target=/buildcache,source=buildcache source /spack/share/spack/setup-env.sh && \
33+
FROM base AS builder
34+
35+
RUN --mount=type=cache,target=/buildcache source /spack/share/spack/setup-env.sh && \
3436
spack mirror add cache /buildcache && \
35-
spack buildcache update-index -d /buildcache
37+
spack buildcache update-index -d /buildcache && \
38+
spack buildcache list --allarch
39+
40+
# Populate cache with build tools
41+
# Uninstall to avoid bad reuse
42+
RUN --mount=type=cache,target=/buildcache source /spack/share/spack/setup-env.sh && \
43+
spack env create tools --without-view && \
44+
spack env activate tools && \
45+
spack add cmake autotools && \
46+
spack concretize -f && spack install --fail-fast && \
47+
spack buildcache create -a -m cache && \
48+
spack uninstall --all
3649

3750
# Define and compile an alien environment
38-
RUN --mount=type=cache,target=/home/user/buildcache,source=buildcache source /spack/share/spack/setup-env.sh && \
51+
RUN --mount=type=cache,target=/buildcache source /spack/share/spack/setup-env.sh && \
52+
spack buildcache update-index -d /buildcache && \
3953
spack env create alien --without-view && \
4054
spack env activate alien && \
4155
spack add alien +hypre+petsc+xml+hdf5+move+ref ginkgo=omp trilinos=omp && \
42-
spack concretize -f && spack install --fail-fast
43-
44-
RUN --mount=type=cache,target=/outcache,source=outcache source /spack/share/spack/setup-env.sh && \
45-
ls -ld /outcache && \
46-
spack env activate alien && \
47-
spack buildcache create -a -d /outcache
56+
spack concretize -f && spack install --fail-fast && \
57+
spack buildcache create -a -m cache
4858

4959
# # Define and compile an arcane environment
5060
# RUN source /spack/share/spack/setup-env.sh && \
@@ -61,8 +71,8 @@ RUN --mount=type=cache,target=/outcache,source=outcache source /spack/share/spac
6171
# spack add arcane ~wrapper~monoembed && \
6272
# spack concretize -f && spack install --fail-fast
6373

64-
RUN source /spack/share/spack/setup-env.sh && \
65-
spack clean -a
74+
# RUN source /spack/share/spack/setup-env.sh && \
75+
# spack clean -a
6676

67-
USER root
68-
RUN rm -rf /tmp/* || true
77+
FROM base AS final
78+
COPY --from=builder /spack/opt/ /spack/

0 commit comments

Comments
 (0)