From 0977f2f4e16c5ae4257b648e9e920efbe45a7137 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20Sch=C3=BCtt?= Date: Thu, 22 May 2025 16:02:49 +0200 Subject: [PATCH] Docker: Add error message for missing spack cache --- tools/docker/Dockerfile.test_spack | 6 +++--- tools/docker/generate_dockerfiles.py | 6 +++--- tools/docker/scripts/setup_spack_cache.sh | 23 +++++++++++++++++++++++ 3 files changed, 29 insertions(+), 6 deletions(-) create mode 100755 tools/docker/scripts/setup_spack_cache.sh diff --git a/tools/docker/Dockerfile.test_spack b/tools/docker/Dockerfile.test_spack index cdc5cdf9f5..c04fea47b2 100644 --- a/tools/docker/Dockerfile.test_spack +++ b/tools/docker/Dockerfile.test_spack @@ -58,9 +58,9 @@ RUN spack compiler find RUN spack external find --all --not-buildable # Add local Spack cache. -ARG SPACK_CACHE -ENV SPACK_CACHE=${SPACK_CACHE:-"s3://spack-cache --s3-endpoint-url=http://localhost:9000"} -RUN spack mirror add --autopush --unsigned local-cache ${SPACK_CACHE} +ARG SPACK_CACHE="s3://spack-cache --s3-endpoint-url=http://localhost:9000" +COPY ./tools/docker/scripts/setup_spack_cache.sh ./ +RUN ./setup_spack_cache.sh # Copy Spack configuration and build recipes ARG CP2K_BUILD_TYPE diff --git a/tools/docker/generate_dockerfiles.py b/tools/docker/generate_dockerfiles.py index 29842a89b5..9b12038177 100755 --- a/tools/docker/generate_dockerfiles.py +++ b/tools/docker/generate_dockerfiles.py @@ -884,9 +884,9 @@ RUN spack compiler find RUN spack external find --all --not-buildable # Add local Spack cache. -ARG SPACK_CACHE -ENV SPACK_CACHE=${{SPACK_CACHE:-"s3://spack-cache --s3-endpoint-url=http://localhost:9000"}} -RUN spack mirror add --autopush --unsigned local-cache ${{SPACK_CACHE}} +ARG SPACK_CACHE="s3://spack-cache --s3-endpoint-url=http://localhost:9000" +COPY ./tools/docker/scripts/setup_spack_cache.sh ./ +RUN ./setup_spack_cache.sh # Copy Spack configuration and build recipes ARG CP2K_BUILD_TYPE diff --git a/tools/docker/scripts/setup_spack_cache.sh b/tools/docker/scripts/setup_spack_cache.sh new file mode 100755 index 0000000000..cc4fe02597 --- /dev/null +++ b/tools/docker/scripts/setup_spack_cache.sh @@ -0,0 +1,23 @@ +#!/bin/bash -e + +# author: Ole Schuett + +if [[ -n "${SPACK_CACHE}" ]]; then + if [[ "${SPACK_CACHE}" == *"http://localhost:9000"* ]]; then + if ! wget -q --tries=1 "http://localhost:9000/spack-cache"; then + echo "" + echo "ERROR: Could not connect to local Spack cache." + echo " Start the cache by running ./start_spack_cache.sh and then pass --network=host to podman." + echo " Alternatively, disable the cache by passing --build-arg SPACK_CACHE=\"\" to podman." + echo " See also: https://manual.cp2k.org/trunk/getting-started/build-with-spack.html" + echo "" + exit 1 + fi + fi + echo "Adding Spack cache: ${SPACK_CACHE}" + spack mirror add --autopush --unsigned local-cache "${SPACK_CACHE}" +else + echo "No Spack cache provided." +fi + +#EOF