Ensure reproducible builds when build through docker

In d9cfd77149 and
d70d04f92b 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 <davanum@gmail.com>
This commit is contained in:
Davanum Srinivas 2021-01-04 19:16:02 -05:00
parent 564ffbd400
commit 4b3475bc65
No known key found for this signature in database
GPG Key ID: 80D83A796103BF59

View File

@ -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}")