Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSami Hiltunen <shiltunen@gitlab.com>2022-07-28 17:01:27 +0300
committerSami Hiltunen <shiltunen@gitlab.com>2022-07-28 17:07:25 +0300
commit6641d296e96cf74a16316ae007f67006fdf0e6cd (patch)
tree8346f37331f3ebd081a78ad4f45dd82e91e9bfef
parent973fc1f2b985c808e442792238f2cddcc53005fe (diff)
Clean up go build cache if it exceeds a thresholdsmh-clean-build-cache
Our build process never cleans up the go build cache and neither does go. Users are expected to run `go clean --cache` occassionally to clean up old files. This has so far been generally fine, given each build didn't bloat the cache too much. With the introduction of packed binaries in 861730ac, the build cache grows at a much higher rate due to the embedded binaries. This has resulted the CI also running out of space. This commit adds a configurable threshold for cleaning up Go's build cache and sets the default at 5 GB. If the build cache is larger than 5GB at the beginning of the build, the build cache is automatically cleaned.
-rw-r--r--Makefile10
1 files changed, 9 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index 5c0addbfb..081847887 100644
--- a/Makefile
+++ b/Makefile
@@ -279,6 +279,8 @@ debug_go_tests = PATH='${SOURCE_DIR}/internal/testhelper/testdata/home/bin:${PAT
${DELVE} test --build-flags="-ldflags '${GO_LDFLAGS}' -tags '${SERVER_BUILD_TAGS},${GIT2GO_BUILD_TAGS}'" ${TEST_PACKAGES} -- ${DEBUG_OPTIONS}
unexport GOROOT
+## GOCACHE_MAX_SIZE_KB is the maximum size of Go's build cache in kilobytes before it is cleaned up.
+GOCACHE_MAX_SIZE_KB ?= 5000000
export GOCACHE ?= ${BUILD_DIR}/cache
export GOPROXY ?= https://proxy.golang.org
export PATH := ${BUILD_DIR}/bin:${PATH}
@@ -606,12 +608,18 @@ ${BUILD_DIR}/bin/%: ${BUILD_DIR}/intermediate/% | ${BUILD_DIR}/bin
remove-legacy-go-mod:
${Q}rm -f $(addprefix ${BUILD_DIR}/, go.mod go.sum)
+# clear-go-build-cache-if-needed cleans the Go build cache if it exceeds the maximum size as
+# configured in GOCACHE_MAX_SIZE_KB.
+.PHONY: clear-go-build-cache-if-needed
+clear-go-build-cache-if-needed:
+ ${Q}if [ $$(du -sk ${GOCACHE} | cut -f 1) -gt ${GOCACHE_MAX_SIZE_KB} ]; then go clean --cache; fi
+
${BUILD_DIR}/intermediate/gitaly: GO_BUILD_TAGS = ${SERVER_BUILD_TAGS}
${BUILD_DIR}/intermediate/gitaly: remove-legacy-go-mod ${GITALY_PACKED_EXECUTABLES}
${BUILD_DIR}/intermediate/praefect: GO_BUILD_TAGS = ${SERVER_BUILD_TAGS}
${BUILD_DIR}/intermediate/gitaly-git2go-v15: GO_BUILD_TAGS = ${GIT2GO_BUILD_TAGS}
${BUILD_DIR}/intermediate/gitaly-git2go-v15: libgit2
-${BUILD_DIR}/intermediate/%: .FORCE
+${BUILD_DIR}/intermediate/%: clear-go-build-cache-if-needed .FORCE
@ # We're building intermediate binaries first which contain a fixed build ID
@ # of "TEMP_GITALY_BUILD_ID". In the final binary we replace this build ID with
@ # the computed build ID for this binary.