Make build reproducible (#499)

By setting SOURCE_DATE_EPOCH builds the build binaries can become
reproducible as a rebuild will take the old build date as input.

Motivation: https://reproducible-builds.org
This commit is contained in:
Jelle van der Waa
2021-09-20 15:26:27 +02:00
committed by GitHub
parent dd2b144004
commit b19654fa48

View File

@@ -3,10 +3,17 @@ help: ## Display this help message.
@grep '^[a-zA-Z]' $(MAKEFILE_LIST) | \ @grep '^[a-zA-Z]' $(MAKEFILE_LIST) | \
awk -F ':.*?## ' 'NF==2 {printf " %-26s%s\n", $$1, $$2}' awk -F ':.*?## ' 'NF==2 {printf " %-26s%s\n", $$1, $$2}'
DATE_FMT = +%FT%T%z
ifdef SOURCE_DATE_EPOCH
BUILD_DATE ?= $(shell date -u -d "@$(SOURCE_DATE_EPOCH)" "$(DATE_FMT)" 2>/dev/null || date -u -r "$(SOURCE_DATE_EPOCH)" "$(DATE_FMT)" 2>/dev/null || date -u "$(DATE_FMT)")
else
BUILD_DATE ?= $(shell date "$(DATE_FMT)")
endif
GO := go GO := go
pkgs = $(shell find . -type d -name "pt-*" -exec basename {} \;) pkgs = $(shell find . -type d -name "pt-*" -exec basename {} \;)
VERSION=$(shell git describe --abbrev=0 --tags) VERSION=$(shell git describe --abbrev=0 --tags)
BUILD=$(shell date +%FT%T%z) BUILD=$(BUILD_DATE)
GOVERSION=$(shell go version | cut --delimiter=" " -f3) GOVERSION=$(shell go version | cut --delimiter=" " -f3)
COMMIT=$(shell git rev-list -1 HEAD) COMMIT=$(shell git rev-list -1 HEAD)
GOUTILSDIR ?= $(GOPATH)/bin GOUTILSDIR ?= $(GOPATH)/bin