From 4b3475bc653b762b44eabed211ccb80f52ad06fa Mon Sep 17 00:00:00 2001 From: Davanum Srinivas Date: Mon, 4 Jan 2021 19:16:02 -0500 Subject: [PATCH] Ensure reproducible builds when build through docker In d9cfd77149bc84fe755b68794528e7d7cb114d1a and d70d04f92b0bcc277c759c3bfb05cb1ec911b500 we added support for reproducible builds for individual binaries (like kube-apiserver), however we need to thread this support when we build binaries with docker as well (say during "make quick-release"). Essentially, if GOLDFLAGS is set explicitly by someone either to a valid value they would like to use or empty ("") then we pick that up. If it is not set we should avoid setting GOLDFLAGS to empty. This ensures that we support the same functionality documented here: https://github.com/kubernetes/kubernetes/blob/master/build/root/Makefile#L82-L85 Signed-off-by: Davanum Srinivas --- build/common.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/build/common.sh b/build/common.sh index 9e344a6aee6..a7a84b6ebf4 100755 --- a/build/common.sh +++ b/build/common.sh @@ -574,11 +574,17 @@ function kube::build::run_build_command_ex() { --env "KUBE_BUILD_WITH_COVERAGE=${KUBE_BUILD_WITH_COVERAGE:-}" --env "KUBE_BUILD_PLATFORMS=${KUBE_BUILD_PLATFORMS:-}" --env "GOFLAGS=${GOFLAGS:-}" - --env "GOLDFLAGS=${GOLDFLAGS:-}" --env "GOGCFLAGS=${GOGCFLAGS:-}" --env "SOURCE_DATE_EPOCH=${SOURCE_DATE_EPOCH:-}" ) + # use GOLDFLAGS only if it is set explicitly. + if [[ -v GOLDFLAGS ]]; then + docker_run_opts+=( + --env "GOLDFLAGS=${GOLDFLAGS:-}" + ) + fi + if [[ -n "${DOCKER_CGROUP_PARENT:-}" ]]; then kube::log::status "Using ${DOCKER_CGROUP_PARENT} as container cgroup parent" docker_run_opts+=(--cgroup-parent "${DOCKER_CGROUP_PARENT}")