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