From 76284b4f55a4fe64d8ce9f605d3144358dd0bd42 Mon Sep 17 00:00:00 2001
From: Wouter Deconinck <wdconinc@gmail.com>
Date: Thu, 24 Nov 2022 22:26:07 +0000
Subject: [PATCH] feat: use S3 buildcache

---
 .gitlab-ci.yml                |  4 ++++
 containers/jug/dev.Dockerfile | 15 +++++++++++++++
 2 files changed, 19 insertions(+)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index b49504295..0bdef49bf 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -252,6 +252,8 @@ jug_dev:default:
                    --build-arg EICSPACK_ORGREPO="${EICSPACK_ORGREPO}"
                    --build-arg EICSPACK_VERSION="${EICSPACK_VERSION}"
                    --build-arg EICSPACK_CHERRYPICKS="${EICSPACK_CHERRYPICKS}"
+                   --build-arg S3_ACCESS_KEY="${S3_ACCESS_KEY}"
+                   --build-arg S3_SECRET_KEY="${S3_SECRET_KEY}"
                    --build-arg CACHE_BUST=${PACKAGE_HASH}
                    --build-arg INTERNAL_TAG=${INTERNAL_TAG}
                    --build-arg JUG_VERSION=${INTERNAL_TAG}-$(git rev-parse HEAD)
@@ -266,6 +268,8 @@ jug_dev:default:
                    --build-arg EICSPACK_ORGREPO="${EICSPACK_ORGREPO}"
                    --build-arg EICSPACK_VERSION="${EICSPACK_VERSION}"
                    --build-arg EICSPACK_CHERRYPICKS="${EICSPACK_CHERRYPICKS}"
+                   --build-arg S3_ACCESS_KEY="${S3_ACCESS_KEY}"
+                   --build-arg S3_SECRET_KEY="${S3_SECRET_KEY}"
                    --build-arg CACHE_BUST=${PACKAGE_HASH}
                    --build-arg INTERNAL_TAG=${INTERNAL_TAG}
                    --build-arg JUG_VERSION=${INTERNAL_TAG}-$(git rev-parse HEAD)
diff --git a/containers/jug/dev.Dockerfile b/containers/jug/dev.Dockerfile
index b5da3e9b4..e399852d7 100644
--- a/containers/jug/dev.Dockerfile
+++ b/containers/jug/dev.Dockerfile
@@ -17,6 +17,7 @@ RUN --mount=type=cache,target=/var/cache/apt                            \
         python3                                                         \
         python3-dev                                                     \
         python3-distutils                                               \
+        python3-boto3                                                   \
         python-is-python3                                               \
  && rm -rf /var/lib/apt/lists/*
 
@@ -66,6 +67,20 @@ RUN --mount=type=cache,target=/var/cache/spack-mirror                   \
  && spack mirror add docker /var/cache/spack-mirror                     \
  && spack mirror list
 
+## Setup eic-spack buildcache mirrors (FIXME: leaks credentials into layer)
+ARG S3_ACCESS_KEY=""
+ARG S3_SECRET_KEY=""
+RUN --mount=type=cache,target=/var/cache/spack-mirror                   \
+    export PATH=$PATH:$SPACK_ROOT/bin                                   \
+ && if [ -n $S3_ACCESS_KEY ] ; then                                     \
+    spack mirror add --scope site                                       \
+      --s3-endpoint-url https://dtn01.sdcc.bnl.gov:9000                 \
+      --s3-access-key-id ${S3_ACCESS_KEY}                               \
+      --s3-access-key-secret ${S3_SECRET_KEY}                           \
+      eic-spack s3://eictest/EPIC/spack                                 \
+    ; fi                                                                \
+ && spack mirror list
+
 ## This variable will change whenevery either spack.yaml or our spack package
 ## overrides change, triggering a rebuild
 ARG CACHE_BUST="hash"
-- 
GitLab