From 1402145cdd169aede0bdc51ff025abe05a6a1a53 Mon Sep 17 00:00:00 2001 From: Ainar Garipov Date: Fri, 30 Apr 2021 19:51:23 +0300 Subject: [PATCH] Pull request: all: improve build reproducibility Updates #2959. Squashed commit of the following: commit 2178c73835454b75b6b0790322df3975e1d14f10 Author: Ainar Garipov Date: Fri Apr 30 19:34:39 2021 +0300 all: improve build reproducibility --- scripts/README.md | 4 +++- scripts/make/go-build.sh | 14 +++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/scripts/README.md b/scripts/README.md index 68831ab6..d6ad3ada 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -65,7 +65,7 @@ Optional environment: verbosity level `2` in `go-build.sh`, set this to `3` when calling `build-release.sh`. * `VERSION`: release version. Will be set by `version.sh` if it is unset or - it has the default `Makefile` value of `v0.0.0`. + if it has the default `Makefile` value of `v0.0.0`. ### `clean.sh`: Cleanup @@ -78,6 +78,8 @@ Required environment: ### `go-build.sh`: Build The Backend Optional environment: + * `BUILD_TIME`: If set, overrides the build time information. Useful for + reproducible builds. * `GOARM`: ARM processor options for the Go compiler. * `GOMIPS`: ARM processor options for the Go compiler. * `GO`: set an alternarive name for the Go compiler. diff --git a/scripts/make/go-build.sh b/scripts/make/go-build.sh index 610e9ab0..1f7bcc96 100644 --- a/scripts/make/go-build.sh +++ b/scripts/make/go-build.sh @@ -10,7 +10,7 @@ # every package that is processed if the caller requested verbosity # level greater than 0. Also show subcommands if the requested # verbosity level is greater than 1. Otherwise, do nothing. -verbose="${VERBOSE:-0}" +readonly verbose="${VERBOSE:-0}" if [ "$verbose" -gt '1' ] then env @@ -33,10 +33,10 @@ fi set -e -f -u # Allow users to set the Go version. -go="${GO:-go}" +readonly go="${GO:-go}" # Require the channel to be set and validate the value. -channel="$CHANNEL" +readonly channel="$CHANNEL" case "$channel" in ('development'|'edge'|'beta'|'release') @@ -52,10 +52,10 @@ esac # Require the version to be set. # # TODO(a.garipov): Additional validation? -version="$VERSION" +readonly version="$VERSION" -# Set date and time of the current build. -buildtime="$(date -u +%FT%TZ%z)" +# Set date and time of the current build unless already set. +readonly buildtime="${BUILD_TIME:-$( date -u +%FT%TZ%z )}" # Set the linker flags accordingly: set the release channel and the # current version as well as goarm and gomips variable values, if the @@ -106,7 +106,7 @@ fi export CGO_ENABLED="$cgo_enabled" export GO111MODULE='on' -readonly build_flags="${BUILD_FLAGS:-$race_flags $out_flags $par_flags $v_flags $x_flags}" +readonly build_flags="${BUILD_FLAGS:-$race_flags --trimpath $out_flags $par_flags $v_flags $x_flags}" # Don't use quotes with flag variables to get word splitting. "$go" generate $v_flags $x_flags ./main.go