Skip to content
Snippets Groups Projects
Commit 846693d7 authored by Wouter Deconinck's avatar Wouter Deconinck
Browse files

feat: split spack into separate image

parent f940abce
No related branches found
No related tags found
1 merge request!659feat: split spack into separate image
......@@ -4,10 +4,10 @@ ARG BASE_IMAGE="debian_stable_base"
ARG INTERNAL_TAG="testing"
## ========================================================================================
## STAGE1: spack builder image
## EIC builder image with spack
## STAGE0: spack image
## EIC spack image with spack and eic-spack repositories
## ========================================================================================
FROM ${DOCKER_REGISTRY}${BASE_IMAGE}:${INTERNAL_TAG} as builder
FROM ${DOCKER_REGISTRY}${BASE_IMAGE}:${INTERNAL_TAG} as spack
ARG TARGETPLATFORM
## install some extra spack dependencies
......@@ -20,8 +20,7 @@ RUN --mount=type=cache,target=/var/cache/apt,sharing=locked,id=${TARGETPLATFORM}
python3-dev \
python3-distutils \
python3-boto3 \
python-is-python3 \
&& rm -rf /var/lib/apt/lists/*
python-is-python3
## Setup spack
ENV SPACK_ROOT=/opt/spack
......@@ -43,6 +42,7 @@ RUN git clone https://github.com/${SPACK_ORGREPO}.git ${SPACK_ROOT} \
SHELL ["docker-shell"]
## Setup build configuration
ARG jobs=64
RUN declare -A target=( \
["linux/amd64"]="x86_64_v2" \
......@@ -62,8 +62,8 @@ RUN declare -A target=( \
&& spack config blame compilers
## Setup local buildcache mirrors
RUN --mount=type=cache,target=/var/cache/spack-mirror \
spack mirror add local /var/cache/spack-mirror/${SPACK_VERSION} \
RUN --mount=type=cache,target=/var/cache/spack \
spack mirror add local /var/cache/spack/mirror/${SPACK_VERSION} \
&& spack buildcache update-index local \
&& spack mirror list
......@@ -72,7 +72,7 @@ RUN --mount=type=cache,target=/var/cache/spack-mirror \
## - the write-enabled mirror is provided later as a secret mount
ARG S3_ACCESS_KEY=""
ARG S3_SECRET_KEY=""
RUN --mount=type=cache,target=/var/cache/spack-mirror \
RUN --mount=type=cache,target=/var/cache/spack \
if [ -n "${S3_ACCESS_KEY}" ] ; then \
spack mirror add --scope site \
--s3-endpoint-url https://eics3.sdcc.bnl.gov:9000 \
......@@ -82,12 +82,7 @@ RUN --mount=type=cache,target=/var/cache/spack-mirror \
; fi \
&& spack mirror list
## This variable will change whenever either spack.yaml or our spack package
## overrides change, triggering a rebuild
ARG CACHE_BUST="hash"
ARG CACHE_NUKE=""
## Setup our custom package overrides
## Setup eic-spack
ENV EICSPACK_ROOT=${SPACK_ROOT}/var/spack/repos/eic-spack
ARG EICSPACK_ORGREPO="eic/eic-spack"
ARG EICSPACK_VERSION="$SPACK_VERSION"
......@@ -100,12 +95,18 @@ RUN git clone https://github.com/${EICSPACK_ORGREPO}.git ${EICSPACK_ROOT} \
fi \
&& spack repo add --scope site "${EICSPACK_ROOT}"
## ========================================================================================
## STAGE1: builder
## EIC builder image with spack environment
## ========================================================================================
FROM spack as builder
## Setup our custom environment (secret mount for write-enabled mirror)
COPY --from=spack-environment . /opt/spack-environment/
ARG ENV=dev
ENV SPACK_ENV=/opt/spack-environment/${ENV}
RUN --mount=type=cache,target=/ccache,id=${TARGETPLATFORM} \
--mount=type=cache,target=/var/cache/spack-mirror \
--mount=type=cache,target=/var/cache/spack \
--mount=type=secret,id=mirrors,target=/opt/spack/etc/spack/mirrors.yaml \
source $SPACK_ROOT/share/spack/setup-env.sh \
&& export CCACHE_DIR=/ccache \
......@@ -116,7 +117,7 @@ RUN --mount=type=cache,target=/ccache,id=${TARGETPLATFORM} \
&& ccache --show-stats
## Create view at /usr/local
RUN --mount=type=cache,target=/var/cache/spack-mirror \
RUN --mount=type=cache,target=/var/cache/spack \
source $SPACK_ROOT/share/spack/setup-env.sh \
&& spack env activate --dir ${SPACK_ENV} \
&& rm -r /usr/local \
......@@ -125,9 +126,10 @@ RUN --mount=type=cache,target=/var/cache/spack-mirror \
## Optional, nuke the buildcache after install, before (re)caching
## This is useful when going to completely different containers,
## or intermittently to keep the buildcache step from taking too much time
RUN --mount=type=cache,target=/var/cache/spack-mirror,sharing=locked \
ARG CACHE_NUKE=""
RUN --mount=type=cache,target=/var/cache/spack,sharing=locked \
[ -z "${CACHE_NUKE}" ] \
|| rm -rf /var/cache/spack-mirror/${SPACK_VERSION}/build_cache/*
|| rm -rf /var/cache/spack/mirror/${SPACK_VERSION}/build_cache/*
## Extra post-spack steps:
## - Python packages
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment