From 984cfaca86aef28c839b14fa9927ac51ee0949ab Mon Sep 17 00:00:00 2001
From: Nicolas Richart <nicolas.richart@epfl.ch>
Date: Mon, 22 Jan 2024 19:28:20 +0100
Subject: [PATCH] Adding conf file and external bind for storage

---
 .gitlab-ci.yml | 53 ++++++++++++++++++++++++++++++++++----------------
 config.json    | 15 ++++++++++++++
 2 files changed, 51 insertions(+), 17 deletions(-)
 create mode 100644 config.json

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 5cf7a09..09aa8ef 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -16,6 +16,8 @@ workflow:
 
 variables:
   BUILDCACHE: "/scratch/richart/buildcache"
+  SPACK_PATH: "/work/scitas-ge/richart/ci_cache/spack"
+  STACK_PATH: "/work/scitas-ge/richart/ci_cache/stack"
   SPACK_DISABLE_LOCAL_CONFIG: "true"
   SPACK_USER_CACHE_PATH: "/tmp/spack_cache"
 
@@ -35,37 +37,54 @@ variables:
     - stack
   variables:
     COMMAND_OPTIONS_SBATCH: ${slurm_options}
-    APPTAINER_EXEC_OPTIONS: ${apptainer_options} --bind ${BUILDCACHE}:/buildcache:rw --writable-tmpfs
-
-.setup_spack:
-  before_script:
-    - /opt/spack/bin/spack gpg trust $GPG_PRIVATE_KEY
-
-    - mkdir -p extra_repos
-    - cd extra_repos
-
-    - git clone https://gitlab.epfl.ch/SCITAS/software-stack/spack-repo-externals.git
-    - git clone https://gitlab.epfl.ch/SCITAS/software-stack/scitas-spack-packages.git
+    APPTAINER_EXEC_OPTIONS: ${apptainer_options} --bind ${BUILDCACHE}:/buildcache:rw --bind ${SPACK_PATH}:/spack:rw --bind ${STACK_PATH}:/stack:rw
 
 # ------------------------------------------------------------------------------
 spack:setup:
   stage: environment
   extends:
     - .parallel_job
-    - .setup_spack
   script:
-    - >
-      if [ ! -d /buildcache/build_cache ]; then
-        /opt/spack/bin/spack gpg publish -d /buildcache
+    - SPACK_VERSION=$(jq .spack.version config.json)
+
+    - |
+      if [ ! -d /spack/spack ]; then
+        git clone https://github.com/spack/spack.git -b $SPACK_VERSION /spack/spack
+      else
+        cd /spack/spack
+        git fetch
+        git checkout $SPACK_VERSION
       fi
 
+    - /spack/spack/bin/spack gpg trust $GPG_PRIVATE_KEY
+
+    - |
+      mkdir -p /stack/extra_repos/
+
+      EXTERNAL_REPOS=$(jq '.spack.repos | .[]' config.json)
+      for repo in ${EXTERNAL_REPOS}
+      do
+        if [ ! -d /stack/extra_repos/${repo} ]; then
+          git clone -b $(jq ".spack.repos.${repos}.branch" config.json) $(jq ".spack.repos.${repos}.url" config.json) /stack/extra_repos/$repo
+        else
+          cd /stack/extra_repos/$repo
+          git fetch
+          git checkout $(jq ".spack.repos.${repos}.branch" config.json)
+        fi
+      done
+
+    - if [ ! -d /buildcache/build_cache ]; then
+        /spack/spack/bin/spack gpg publish -d /buildcache
+      fi
+
+
+
 spack:concretize:
   stage: concretize
   extends:
     - .parallel_job
-    - .setup_spack
   script:
-    - /opt/spack/bin/spack -e . concretize
+    - /spack/spack/bin/spack -e . concretize
   needs:
     - job: spack:setup
   artifacts:
diff --git a/config.json b/config.json
new file mode 100644
index 0000000..d16ff1d
--- /dev/null
+++ b/config.json
@@ -0,0 +1,15 @@
+{
+    "spack": {
+        "version": "v0.21.1",
+        "repos": {
+            "scitas-externals": {
+                "url": "https://gitlab.epfl.ch/SCITAS/software-stack/spack-repo-externals.git",
+                "branch": "release/syrah"
+            },
+            "sctias-packages": {
+                "url": "https://gitlab.epfl.ch/SCITAS/software-stack/spack-repo-externals.git",
+                "branch": "release/syrah"
+            }
+        }
+    }
+}
-- 
GitLab