Share Go pkg cache in CI
This will decrease build times for scripts/gazelle.sh invocations, which will
otherwise re-download all modules every time.
There's likely a small risk of corrupting the shared cache, at which point it
would have to cleaned manually.
According to this GitHub issue, what we're doing is supported:
https://github.com/golang/go/issues/26794
Due to the lockfile, this also serializes builds that need to download new packages.
If this ever becomes an issue, we can create a per-working copy cache like we do for Bazel.
Test Plan:
Re-ran CI build multiple times, packages were not re-downloaded.
Build time decreased by ~5-7s.
X-Origin-Diff: phab/D374
GitOrigin-RevId: ec2f347d791f2915c5ecc04d9b67029de386aae9
diff --git a/scripts/run_ci.sh b/scripts/run_ci.sh
index 302bcfd..d8fcf81 100755
--- a/scripts/run_ci.sh
+++ b/scripts/run_ci.sh
@@ -22,6 +22,9 @@
CACHE_VOLUME=bazel-cache-$(getWorkingCopyID)
+# The Go pkg cache is safe to use concurrently.
+GOPKG_VOLUME=gopkg-cache
+
# We do our own image caching since the podman build step cache does
# not work across different repository checkouts and is also easily
# invalidated by multiple in-flight revisions with different Dockerfiles.
@@ -41,6 +44,7 @@
trap cleanup EXIT
! podman volume create --opt o=nodev,exec ${CACHE_VOLUME}
+! podman volume create --opt o=nodev ${GOPKG_VOLUME}
podman pod create --name ${POD}
@@ -48,6 +52,7 @@
--rm \
-v $(pwd):/work \
-v ${CACHE_VOLUME}:/user/.cache/bazel/_bazel_root \
+ -v ${GOPKG_VOLUME}:/user/go/pkg \
--privileged \
${TAG} \
scripts/gazelle.sh
@@ -67,6 +72,7 @@
podman run \
-v $(pwd):/work \
-v ${CACHE_VOLUME}:/user/.cache/bazel/_bazel_root \
+ -v ${GOPKG_VOLUME}:/user/go/pkg \
--device /dev/kvm \
--privileged \
--pod ${POD} \