diff --git a/Makefile b/Makefile index 32e7f7f29c8c..ec3f418b5a60 100644 --- a/Makefile +++ b/Makefile @@ -41,13 +41,9 @@ endif # https://reproducible-builds.org/docs/source-date-epoch/#makefile # https://reproducible-builds.org/docs/source-date-epoch/#git -# https://stackoverflow.com/a/15103333 +SOURCE_DATE_EPOCH ?= $(shell git log -1 --pretty=%ct || date -u +%s) BUILD_DATE_FMT = %Y-%m-%dT%H:%M:%SZ -ifdef SOURCE_DATE_EPOCH - BUILD_DATE ?= $(shell date -u -d "@$(SOURCE_DATE_EPOCH)" "+$(BUILD_DATE_FMT)" 2>/dev/null || date -u -r "$(SOURCE_DATE_EPOCH)" "+$(BUILD_DATE_FMT)" 2>/dev/null || date -u "+$(BUILD_DATE_FMT)") -else - BUILD_DATE ?= $(shell TZ=UTC git log -1 --pretty=%cd --date='format-local:$(BUILD_DATE_FMT)' || date -u +$(BUILD_DATE_FMT)) -endif +BUILD_DATE ?= $(shell date -u -d "@$(SOURCE_DATE_EPOCH)" "+$(BUILD_DATE_FMT)" 2>/dev/null || date -u -r "$(SOURCE_DATE_EPOCH)" "+$(BUILD_DATE_FMT)" 2>/dev/null || date -u "+$(BUILD_DATE_FMT)") LD_FLAGS += -X github.com/k0sproject/k0s/pkg/build.Version=$(VERSION) LD_FLAGS += -X github.com/k0sproject/k0s/pkg/build.RuncVersion=$(runc_version) @@ -197,7 +193,9 @@ k0s.exe k0s: $(GO_SRCS) $(codegen_targets) go.sum && mv $@.tmp $@ .bins.windows.stamp .bins.linux.stamp: embedded-bins/Makefile.variables - $(MAKE) -C embedded-bins buildmode=$(EMBEDDED_BINS_BUILDMODE) TARGET_OS=$(patsubst .bins.%.stamp,%,$@) + $(MAKE) -C embedded-bins \ + TARGET_OS=$(patsubst .bins.%.stamp,%,$@) \ + SOURCE_DATE_EPOCH=$(SOURCE_DATE_EPOCH) touch $@ .PHONY: codegen diff --git a/embedded-bins/Makefile b/embedded-bins/Makefile index 5babe263845d..8b833a6d8087 100644 --- a/embedded-bins/Makefile +++ b/embedded-bins/Makefile @@ -6,6 +6,10 @@ export GOOS TARGET_OS ?= linux export TARGET_OS +# https://reproducible-builds.org/docs/source-date-epoch/#makefile +# https://reproducible-builds.org/docs/source-date-epoch/#git +SOURCE_DATE_EPOCH ?= $(shell git log -1 --pretty=%ct || date -u +%s) + bindir = staging/${TARGET_OS}/bin posix_bins = runc kubelet containerd containerd-shim containerd-shim-runc-v1 containerd-shim-runc-v2 kube-apiserver kube-scheduler kube-controller-manager etcd kine konnectivity-server xtables-legacy-multi xtables-nft-multi windows_bins = kubelet.exe kube-proxy.exe containerd.exe containerd-shim-runhcs-v1.exe @@ -79,6 +83,7 @@ build_docker_image = \ --build-arg CONTAINERD_BINS="$(containerd_bins)" \ --build-arg KUBERNETES_BINS="$(kubernetes_bins)" \ --build-arg VERSION=$($(patsubst %/Dockerfile,%,$<)_version) \ + --build-arg SOURCE_DATE_EPOCH=$(SOURCE_DATE_EPOCH) \ --build-arg BUILDIMAGE=$($(patsubst %/Dockerfile,%,$<)_buildimage) \ --build-arg BUILD_GO_TAGS=$($(patsubst %/Dockerfile,%,$<)_build_go_tags) \ --build-arg BUILD_GO_CGO_ENABLED=$($(patsubst %/Dockerfile,%,$<)_build_go_cgo_enabled) \ diff --git a/embedded-bins/Makefile.variables b/embedded-bins/Makefile.variables index a8350b9d3f9c..5e05d5a935cf 100644 --- a/embedded-bins/Makefile.variables +++ b/embedded-bins/Makefile.variables @@ -30,7 +30,7 @@ kubernetes_build_go_tags = "providerless" #kubernetes_build_go_cgo_cflags = kubernetes_build_go_flags = "-v" #kubernetes_build_go_ldflags = -kubernetes_build_go_ldflags_extra = "-w -s -extldflags=-static" +kubernetes_build_go_ldflags_extra = "-extldflags=-static" kine_version = 0.10.3 kine_buildimage = $(golang_buildimage) diff --git a/embedded-bins/kubernetes/Dockerfile b/embedded-bins/kubernetes/Dockerfile index a453ad7c3b9c..99b023fd5b07 100644 --- a/embedded-bins/kubernetes/Dockerfile +++ b/embedded-bins/kubernetes/Dockerfile @@ -9,6 +9,7 @@ RUN git -c advice.detachedHead=false clone -b v$VERSION --depth=1 https://github WORKDIR /go/src/github.com/kubernetes/kubernetes ARG TARGET_OS \ + SOURCE_DATE_EPOCH \ BUILD_GO_TAGS \ BUILD_GO_CGO_ENABLED \ BUILD_GO_FLAGS \ @@ -17,7 +18,7 @@ ARG TARGET_OS \ KUBERNETES_BINS RUN \ - set -e; \ + set -ex; \ export GOPATH=/go; \ if [ "${TARGET_OS}" = windows ]; then \ commands="${KUBERNETES_BINS}"; \ @@ -34,7 +35,9 @@ RUN \ export KUBE_STATIC_OVERRIDES=$commands; \ fi; \ mkdir /out; \ + export SOURCE_DATE_EPOCH=$SOURCE_DATE_EPOCH; \ export FORCE_HOST_GO=y; \ + export KUBE_VERBOSE=9; \ export KUBE_GIT_VERSION="v$VERSION+k0s"; \ for cmd in $commands; do \ make GOFLAGS="${BUILD_GO_FLAGS} -tags=${BUILD_GO_TAGS}" GOLDFLAGS="${BUILD_GO_LDFLAGS_EXTRA}" WHAT=cmd/$cmd; \