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

feat: install environment and push to buildcache with Makefile

parent 0d0eb73b
No related branches found
No related tags found
1 merge request!540feat: install environment and push to buildcache with Makefile
...@@ -36,6 +36,9 @@ variables: ...@@ -36,6 +36,9 @@ variables:
65bd9b9ac556480b4a9dcc60f7539492af195d4a 65bd9b9ac556480b4a9dcc60f7539492af195d4a
1a32cea11495cbdd699fea4fe622babab83e630d 1a32cea11495cbdd699fea4fe622babab83e630d
6edc4807369a05786e36f63b5d959588ae94a1fa 6edc4807369a05786e36f63b5d959588ae94a1fa
af74680405c931dab16c6674f9b97a32bf3f1122
0a952f8b7bf6f70009dd5821bccbaf9170c73d07
f050b1cf7835fd31992b020e1061c52294ff7330
## Ref: https://github.com/spack/spack/commit/[hash] ## Ref: https://github.com/spack/spack/commit/[hash]
## [hash]: [description] ## [hash]: [description]
## b5ef5c2eb5145020f9de1bcb964626ce6ac2d02e: geant4: version bumps for Geant4 11.1.0 ## b5ef5c2eb5145020f9de1bcb964626ce6ac2d02e: geant4: version bumps for Geant4 11.1.0
...@@ -62,6 +65,9 @@ variables: ...@@ -62,6 +65,9 @@ variables:
## 65bd9b9ac556480b4a9dcc60f7539492af195d4a: podio, edm4hep: add v0.7.2 and v0.16.1 respectively ## 65bd9b9ac556480b4a9dcc60f7539492af195d4a: podio, edm4hep: add v0.7.2 and v0.16.1 respectively
## 1a32cea11495cbdd699fea4fe622babab83e630d: podio: add v0.16.2 ## 1a32cea11495cbdd699fea4fe622babab83e630d: podio: add v0.16.2
## 6edc4807369a05786e36f63b5d959588ae94a1fa: podio: Add version 0.16.3 ## 6edc4807369a05786e36f63b5d959588ae94a1fa: podio: Add version 0.16.3
## af74680405c931dab16c6674f9b97a32bf3f1122: depfile: improve tab completion
## 0a952f8b7bf6f70009dd5821bccbaf9170c73d07: docs updates for spack env depfile
## f050b1cf7835fd31992b020e1061c52294ff7330: depfile: variable with all identifiers
## EIC spack organization and repository, e.g. eic/eic-spack ## EIC spack organization and repository, e.g. eic/eic-spack
EICSPACK_ORGREPO: "eic/eic-spack" EICSPACK_ORGREPO: "eic/eic-spack"
......
...@@ -100,77 +100,21 @@ RUN git clone https://github.com/${EICSPACK_ORGREPO}.git ${EICSPACK_ROOT} \ ...@@ -100,77 +100,21 @@ RUN git clone https://github.com/${EICSPACK_ORGREPO}.git ${EICSPACK_ROOT} \
## Setup our custom environment ## Setup our custom environment
COPY --from=spack spack-environment/ /opt/spack-environment/ COPY --from=spack spack-environment/ /opt/spack-environment/
ARG ENV=dev ARG ENV=dev
RUN rm -r /usr/local \ RUN --mount=type=cache,target=/var/cache/spack-mirror,sharing=locked \
&& cd /opt/spack-environment \ cd /opt/spack-environment \
&& rm -r /usr/local \
&& source $SPACK_ROOT/share/spack/setup-env.sh \ && source $SPACK_ROOT/share/spack/setup-env.sh \
&& spack env activate --dir /opt/spack-environment/${ENV} \ && spack env activate --dir /opt/spack-environment/${ENV} \
&& spack concretize --fresh && make -C /opt/spack-environment SPACK_ENV=${ENV} \
BUILDCACHE_DIR=/var/cache/spack-mirror \
BUILDCACHE_MIRROR=eic-spack
## Now execute the main build (or fetch from cache if possible)
## note, no-check-signature is needed to allow the quicker signature-less
## packages from the internal (docker) buildcache
##
## 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 \
## Update the local build cache if needed. Consists of 3 steps: [ -z "${CACHE_NUKE}" ] \
## 1. Remove the eic-spack buildcache on S3 || rm -rf /var/cache/spack-mirror/build_cache/*
## 2. Get a list of all packages, and compare with what is already on
## the buildcache (using package hash)
## 3. Add packages that need to be added to buildcache if any
RUN --mount=type=cache,target=/var/cache/spack-mirror \
cd /opt/spack-environment \
&& source $SPACK_ROOT/share/spack/setup-env.sh \
&& spack env activate --dir /opt/spack-environment/${ENV} \
&& status=0 \
&& spack install -j64 --no-check-signature \
|| spack install -j64 --no-check-signature \
|| spack install -j64 --no-check-signature --show-log-on-error \
|| status=$? \
&& spack mirror rm --scope site eic-spack \
&& [ -z "${CACHE_NUKE}" ] \
|| rm -rf /var/cache/spack-mirror/build_cache/* \
&& mkdir -p /var/cache/spack-mirror/build_cache \
&& spack buildcache update-index -d /var/cache/spack-mirror \
&& spack buildcache list --allarch --very-long \
| sed '/^$/d;/^--/d;s/@.\+//;s/\([a-z0-9]*\) \(.*\)/\2\/\1/' \
| sort > buildcache.local.txt \
&& spack find --format {name}/{hash} | sort \
| comm -23 - buildcache.local.txt \
| xargs --verbose --no-run-if-empty \
spack buildcache create --allow-root --only package --unsigned \
--directory /var/cache/spack-mirror \
--rebuild-index \
&& spack clean -a \
&& exit $status
## Update the S3 build cache (without local cache mount)
ARG S3RW_ACCESS_KEY=""
ARG S3RW_SECRET_KEY=""
RUN cd /opt/spack-environment \
&& source $SPACK_ROOT/share/spack/setup-env.sh \
&& spack env activate --dir /opt/spack-environment/${ENV} \
&& if [ -n "${S3RW_ACCESS_KEY}" ] ; then \
spack mirror add --scope site \
--s3-endpoint-url https://eics3.sdcc.bnl.gov:9000 \
--s3-access-key-id "${S3RW_ACCESS_KEY}" \
--s3-access-key-secret "${S3RW_SECRET_KEY}" \
eic-spack s3://eictest/EPIC/spack \
&& spack mirror list \
&& spack buildcache list --allarch --very-long \
| sed '/^$/d;/^--/d;s/@.\+//;s/\([a-z0-9]*\) \(.*\)/\2\/\1/' \
| sort > buildcache.eic-spack.txt \
&& spack find --format {name}/{hash} | sort \
| comm -23 - buildcache.eic-spack.txt \
| xargs --verbose --no-run-if-empty \
spack buildcache create --allow-root --only package --unsigned \
--mirror-name eic-spack \
&& spack buildcache update-index --mirror-url eic-spack \
&& spack mirror rm --scope site eic-spack \
; fi \
&& spack mirror list
## Extra post-spack steps: ## Extra post-spack steps:
## - Python packages ## - Python packages
......
MAKEFLAGS += -Orecurse
SPACK ?= spack
SPACK_INSTALL_FLAGS += --no-check-signature
export SPACK_COLOR = always
SPACK_ENV ?= dev
BUILDCACHE_DIR := $(SPACK_ENV)/cache
BUILDCACHE_MIRROR :=
.PHONY: all clean
all: $(SPACK_ENV)/push
ifeq (,$(filter clean,$(MAKECMDGOALS)))
include $(SPACK_ENV)/spack.mk
endif
$(SPACK_ENV)/push: $(addprefix $(SPACK_ENV)/push/,$($(SPACK_ENV)/SPACK_PACKAGE_IDS))
@mkdir -p $(BUILDCACHE_DIR)
$(foreach buildcache, $(BUILDCACHE_DIR), $(SPACK) buildcache update-index --mirror-url $(buildcache) ;)
$(foreach buildcache, $(BUILDCACHE_MIRROR), $(SPACK) buildcache update-index --mirror-url $(buildcache) ;)
$(SPACK_ENV)/push/%: $(SPACK_ENV)/install/%
@mkdir -p $(dir $@)
$(foreach buildcache, $(BUILDCACHE_DIR), $(SPACK) buildcache create --allow-root --only=package --unsigned --directory $(buildcache) /$(HASH) ;) # push $(SPEC)
$(foreach buildcache, $(BUILDCACHE_MIRROR), $(SPACK) buildcache create --allow-root --only=package --unsigned --mirror-name $(buildcache) /$(HASH) ;) # push $(SPEC)
@touch $@
$(SPACK_ENV)/spack.lock: $(SPACK_ENV)/spack.yaml Makefile
$(SPACK) concretize --force --fresh
$(SPACK_ENV)/spack.mk: $(SPACK_ENV)/spack.lock Makefile
$(SPACK) env depfile --output $@ --make-target-prefix $(SPACK_ENV)
clean:
rm -rf $(SPACK_ENV)/spack.lock $(SPACK_ENV)/spack.mk
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