Skip to content

Commit

Permalink
Ensure reproducible builds - support for SOURCE_DATE_EPOCH with docke…
Browse files Browse the repository at this point in the history
…rized builds

- Pass in SOURCE_DATE_EPOCH when we run the docker container
- Looks like cleaning up symbol table also helps
- Also trimming the path

Tips from
- https://blog.filippo.io/reproducing-go-binaries-byte-by-byte/
- https://blog.filippo.io/shrink-your-go-binaries-with-this-one-weird-trick/

Change-Id: Iedba85d9c1a36790fb8814795f7c27c1371cff1b
  • Loading branch information
dims committed Sep 26, 2018
1 parent 8c1fe2e commit d9cfd77
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions build/common.sh
Expand Up @@ -600,6 +600,7 @@ function kube::build::run_build_command_ex() {
--env "GOFLAGS=${GOFLAGS:-}"
--env "GOLDFLAGS=${GOLDFLAGS:-}"
--env "GOGCFLAGS=${GOGCFLAGS:-}"
--env "SOURCE_DATE_EPOCH=${SOURCE_DATE_EPOCH:-}"
)

if [[ -n "${DOCKER_CGROUP_PARENT:-}" ]]; then
Expand Down
11 changes: 8 additions & 3 deletions hack/lib/golang.sh
Expand Up @@ -557,6 +557,7 @@ kube::golang::build_some_binaries() {
fi
else
V=2 kube::log::info "Coverage is disabled."
kube::log::status "go install" "${build_args[@]}" "$@"
go install "${build_args[@]}" "$@"
fi
}
Expand Down Expand Up @@ -586,6 +587,7 @@ kube::golang::build_binaries_for_platform() {
-installsuffix static
${goflags:+"${goflags[@]}"}
-gcflags "${gogcflags:-}"
-asmflags "${goasmflags:-}"
-ldflags "${goldflags:-}"
)
CGO_ENABLED=0 kube::golang::build_some_binaries "${statics[@]}"
Expand All @@ -595,6 +597,7 @@ kube::golang::build_binaries_for_platform() {
build_args=(
${goflags:+"${goflags[@]}"}
-gcflags "${gogcflags:-}"
-asmflags "${goasmflags:-}"
-ldflags "${goldflags:-}"
)
kube::golang::build_some_binaries "${nonstatics[@]}"
Expand All @@ -608,6 +611,7 @@ kube::golang::build_binaries_for_platform() {
go test -c \
${goflags:+"${goflags[@]}"} \
-gcflags "${gogcflags:-}" \
-asmflags "${goasmflags:-}" \
-ldflags "${goldflags:-}" \
-o "${outfile}" \
"${testpkg}"
Expand Down Expand Up @@ -661,10 +665,11 @@ kube::golang::build_binaries() {
host_platform=$(kube::golang::host_platform)

# Use eval to preserve embedded quoted strings.
local goflags goldflags gogcflags
local goflags goldflags goasmflags gogcflags
eval "goflags=(${GOFLAGS:-})"
goldflags="${GOLDFLAGS:-} $(kube::version::ldflags)"
gogcflags="${GOGCFLAGS:-}"
goldflags="${GOLDFLAGS:-} -s -w $(kube::version::ldflags)"
goasmflags="-trimpath=${KUBE_ROOT}"
gogcflags="${GOGCFLAGS:-} -trimpath=${KUBE_ROOT}"

local -a targets=()
local arg
Expand Down

0 comments on commit d9cfd77

Please sign in to comment.