diff options
author | Will Chandler <wchandler@gitlab.com> | 2022-07-29 17:47:20 +0300 |
---|---|---|
committer | Will Chandler <wchandler@gitlab.com> | 2022-07-29 17:47:20 +0300 |
commit | 31ea786fbf0a7874b44efcb1f8b43bc4536d9b7e (patch) | |
tree | b93e99f09dc9b846451b2a7f3cf3c07399ecbfe9 | |
parent | cfd27a4402af9c7ccfa8ab21a49339f4bb2d949f (diff) | |
parent | 6641d296e96cf74a16316ae007f67006fdf0e6cd (diff) |
Merge branch 'smh-clean-build-cache' into 'master'
Clean up go build cache if it exceeds a threshold
Closes #4392
See merge request gitlab-org/gitaly!4765
-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} @@ -610,12 +612,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. |