From d984acbe7e09a3670571ef3dd13b6d48f0f88d17 Mon Sep 17 00:00:00 2001
From: Sylvester Joosten <sjoosten@anl.gov>
Date: Sat, 21 Nov 2020 02:44:29 +0000
Subject: [PATCH] moved detector build to the initialize CI step to avoid race
 conditions in multi-process jobs

---
 .gitlab-ci.yml  | 22 +++++++++++++++++++++-
 dis/config.yml  |  2 +-
 dis/dis.sh      |  3 ++-
 dvcs/config.yml |  1 +
 dvmp/config.yml |  4 ++--
 dvmp/dvmp.sh    |  3 ++-
 6 files changed, 29 insertions(+), 6 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 58e58a0c..0a96f1ce 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -7,11 +7,31 @@ default:
     expire_in: 3 days
 
 stages:
-  - generate
+  - initialize
   - process
   - collect
   - finish
 
+detector:
+  stage: initialize
+  needs: []
+  timeout: 1 hour
+  cache:
+    key:
+      files:
+        - config/env.sh
+        - util/build_detector.sh
+      prefix: "$CI_COMMIT_REF_SLUG"
+    paths:
+      - .local/detector
+      - .local/lib
+    artifacts:
+      paths:
+        - .local/detector
+        - .local/lib
+    script:
+      - ./util/build_detector.sh
+
 include:
   - local: 'dis/config.yml'
   - local: 'dvmp/config.yml'
diff --git a/dis/config.yml b/dis/config.yml
index c6985df9..68e9d09d 100644
--- a/dis/config.yml
+++ b/dis/config.yml
@@ -10,7 +10,7 @@ dis:generate:
 
 dis:process:
   stage: process
-  needs: ["dis:generate"]
+  needs: ["detector", "dis:generate"]
   timeout: 1 hour
   artifacts:
     paths:
diff --git a/dis/dis.sh b/dis/dis.sh
index fa87f1c4..171c792a 100644
--- a/dis/dis.sh
+++ b/dis/dis.sh
@@ -43,7 +43,8 @@ export JUGGLER_REC_FILE="rec_${JUGGLER_FILE_NAME_TAG}.root"
 
 ## =============================================================================
 ## Step 1: Build/install the desired detector package
-bash util/build_detector.sh
+## TODO remove this
+#bash util/build_detector.sh
 
 ## =============================================================================
 ## Step 2: Run the simulation
diff --git a/dvcs/config.yml b/dvcs/config.yml
index 94f5e0fc..1255c602 100644
--- a/dvcs/config.yml
+++ b/dvcs/config.yml
@@ -1,6 +1,7 @@
 dvcs:process:
   stage: process
   timeout: 1 hour
+  needs: ["detector"]
   script:
     - echo "dvcd benchmark"
   artifacts:
diff --git a/dvmp/config.yml b/dvmp/config.yml
index 645f0be9..3266b84f 100644
--- a/dvmp/config.yml
+++ b/dvmp/config.yml
@@ -1,6 +1,6 @@
 dvmp:generate:
   image: eicweb.phy.anl.gov:4567/monte_carlo/lager/lager:unstable
-  stage: generate
+  stage: initialize
   needs: []
   timeout: 1 hours
   cache:
@@ -19,7 +19,7 @@ dvmp:generate:
 
 dvmp:process:
   stage: process
-  needs: ["dvmp:generate"]
+  needs: ["detector", "dvmp:generate"]
   timeout: 1 hour
   script:
     - ./util/run_many.py dvmp/dvmp.sh --energy 10x100 --config jpsi_central --decay muon --decay electron --leading jpsi
diff --git a/dvmp/dvmp.sh b/dvmp/dvmp.sh
index 1baa6726..09bdac80 100755
--- a/dvmp/dvmp.sh
+++ b/dvmp/dvmp.sh
@@ -76,7 +76,8 @@ PLOT_PREFIX=${DATA_PATH}/`util/print_fname.sh \
 
 ## =============================================================================
 ## Step 1: Build/install the desired detector package
-bash util/build_detector.sh
+# moved to different CI step TODO remove
+#bash util/build_detector.sh
 
 ## =============================================================================
 ## Step 2: Run the simulation
-- 
GitLab