@@ -51,16 +51,35 @@ img_for() {
5151 esac
5252}
5353
54+ # Layer caching (opt-in via CACHE; default off so local/podman builds are
55+ # unchanged). CACHE=gha uses buildx + the GitHub Actions cache backend, which is
56+ # why ci.yaml sets it but publish.yaml does NOT -- release builds intentionally
57+ # miss the cache for reproducibility (see docs/UPSTREAM_REVIEW.md A4). Cache is
58+ # scoped per target so webgui and cluster don't evict each other. buildx needs
59+ # --load to put the image in the local store for the smoke/test `docker run`.
60+ CACHE=" ${CACHE:- } "
61+
5462for t in $TARGETS ; do
5563 tag=" $( img_for " $t " ) "
56- echo " >>> build target=$t -> $tag (FVS_VARIANT=$FVS_VARIANT FVS_BASE=$FVS_BASE )"
57- " $ENGINE " build -f docker/Dockerfile --target " $t " \
58- --build-arg " FVS_VARIANT=${FVS_VARIANT} " \
59- --build-arg " FVS_BASE=${FVS_BASE} " \
60- --build-arg " VCS_REF=${VCS_REF} " \
61- --build-arg " FVS_SOURCE_REF=${FVS_SOURCE_REF} " \
62- --build-arg " BUILD_DATE=${BUILD_DATE} " \
63- -t " $tag " .
64+ echo " >>> build target=$t -> $tag (FVS_VARIANT=$FVS_VARIANT FVS_BASE=$FVS_BASE CACHE=${CACHE:- off} )"
65+ common_args=(
66+ -f docker/Dockerfile --target " $t "
67+ --build-arg " FVS_VARIANT=${FVS_VARIANT} "
68+ --build-arg " FVS_BASE=${FVS_BASE} "
69+ --build-arg " VCS_REF=${VCS_REF} "
70+ --build-arg " FVS_SOURCE_REF=${FVS_SOURCE_REF} "
71+ --build-arg " BUILD_DATE=${BUILD_DATE} "
72+ -t " $tag "
73+ )
74+ if [ " $CACHE " = " gha" ]; then
75+ scope=" ${FVS_VARIANT} -${FVS_BASE} -${t} "
76+ " $ENGINE " buildx build " ${common_args[@]} " \
77+ --cache-from " type=gha,scope=${scope} " \
78+ --cache-to " type=gha,mode=max,scope=${scope} " \
79+ --load .
80+ else
81+ " $ENGINE " build " ${common_args[@]} " .
82+ fi
6483done
6584
6685# Smoke test inside each built image. smoke_test.R is baked into the image (at
0 commit comments