diff options
author | Sami Hiltunen <shiltunen@gitlab.com> | 2022-07-28 17:01:27 +0300 |
---|---|---|
committer | Sami Hiltunen <shiltunen@gitlab.com> | 2022-07-28 17:07:25 +0300 |
commit | 6641d296e96cf74a16316ae007f67006fdf0e6cd (patch) | |
tree | 8346f37331f3ebd081a78ad4f45dd82e91e9bfef | |
parent | 973fc1f2b985c808e442792238f2cddcc53005fe (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-- | Makefile | 10 |
1 files changed, 9 insertions, 1 deletions
@@ -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. |