From dc72a87bc71e2f3169392edd44c132d2efa73ca7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Batuhan=20Apayd=C4=B1n?= Date: Wed, 19 Jan 2022 23:54:47 +0300 Subject: [PATCH] chore(makefile): enhance reproducible build (#1181) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Batuhan Apaydın Co-authored-by: Morten Linderud Signed-off-by: Batuhan Apaydın Co-authored-by: Morten Linderud --- Makefile | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 8e7ea7a1295a..d94131ea350a 100644 --- a/Makefile +++ b/Makefile @@ -2,8 +2,16 @@ RELEASE_REPO ?= public.ecr.aws/karpenter RELEASE_VERSION ?= $(shell git describe --tags --always) RELEASE_PLATFORM ?= --platform=linux/amd64,linux/arm64 +# https://reproducible-builds.org/docs/source-date-epoch/ +DATE_FMT = +%Y-%m-%dT%H:%M:%SZ +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 + ## Inject these annotations to cosign signing -COSIGN_FLAGS ?= -a GIT_HASH=$(shell git rev-parse HEAD) -a GIT_VERSION=${RELEASE_VERSION} -a BUILD_DATE=$(shell date +'%Y-%m-%dT%H:%M:%SZ') +COSIGN_FLAGS ?= -a GIT_HASH=$(shell git rev-parse HEAD) -a GIT_VERSION=${RELEASE_VERSION} -a BUILD_DATE=$BUILD_DATE ## Inject the app version into project.Version LDFLAGS ?= "-ldflags=-X=github.com/aws/karpenter/pkg/utils/project.Version=$(RELEASE_VERSION)"