Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Forward SOURCE_DATE_EPOCH to embedded k8s binaries #3542

Merged
merged 1 commit into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -197,7 +193,9 @@ k0s.exe k0s: $(GO_SRCS) $(codegen_targets) go.sum
&& mv [email protected] $@

.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
Expand Down
5 changes: 5 additions & 0 deletions embedded-bins/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) \
Expand Down
2 changes: 1 addition & 1 deletion embedded-bins/Makefile.variables
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion embedded-bins/kubernetes/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -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}"; \
Expand All @@ -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; \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a deliberate change or is something that you commited accidentally? I'm not against it but I find this line surprising.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, this prints out the arguments for the build, which is quite handy and is what I used to verify that the build picks up a custom SOURCE_DATE_EPOCH:

https://github.com/k0sproject/k0s/actions/runs/6378582878/job/17309435491?pr=3542#step:7:11718

Building binaries with GCFLAGS=all=-trimpath=/go/src/github.com/kubernetes/kubernetes/_output/local/go/src/k8s.io/kubernetes ASMFLAGS=all=-trimpath=/go/src/github.com/kubernetes/kubernetes/_output/local/go/src/k8s.io/kubernetes LDFLAGS=all=-X 'k8s.io/kubernetes/vendor/k8s.io/client-go/pkg/version.buildDate=2023-10-02T09:52:01Z' -X 'k8s.io/kubernetes/vendor/k8s.io/component-base/version.buildDate=2023-10-02T09:52:01Z' -X 'k8s.io/client-go/pkg/version.buildDate=2023-10-02T09:52:01Z' -X 'k8s.io/component-base/version.buildDate=2023-10-02T09:52:01Z' -X 'k8s.io/kubernetes/vendor/k8s.io/client-go/pkg/version.gitCommit=89a4ea3e1e4ddd7f7572286090359983e0387b2f' -X 'k8s.io/kubernetes/vendor/k8s.io/component-base/version.gitCommit=89a4ea3e1e4ddd7f7572286090359983e0387b2f' -X 'k8s.io/client-go/pkg/version.gitCommit=89a4ea3e1e4ddd7f7572286090359983e0387b2f' -X 'k8s.io/component-base/version.gitCommit=89a4ea3e1e4ddd7f7572286090359983e0387b2f' -X 'k8s.io/kubernetes/vendor/k8s.io/client-go/pkg/version.gitTreeState=clean' -X 'k8s.io/kubernetes/vendor/k8s.io/component-base/version.gitTreeState=clean' -X 'k8s.io/client-go/pkg/version.gitTreeState=clean' -X 'k8s.io/component-base/version.gitTreeState=clean' -X 'k8s.io/kubernetes/vendor/k8s.io/client-go/pkg/version.gitVersion=v1.28.2+k0s' -X 'k8s.io/kubernetes/vendor/k8s.io/component-base/version.gitVersion=v1.28.2+k0s' -X 'k8s.io/client-go/pkg/version.gitVersion=v1.28.2+k0s' -X 'k8s.io/component-base/version.gitVersion=v1.28.2+k0s' -X 'k8s.io/kubernetes/vendor/k8s.io/client-go/pkg/version.gitMajor=1' -X 'k8s.io/kubernetes/vendor/k8s.io/component-base/version.gitMajor=1' -X 'k8s.io/client-go/pkg/version.gitMajor=1' -X 'k8s.io/component-base/version.gitMajor=1' -X 'k8s.io/kubernetes/vendor/k8s.io/client-go/pkg/version.gitMinor=28' -X 'k8s.io/kubernetes/vendor/k8s.io/component-base/version.gitMinor=28' -X 'k8s.io/client-go/pkg/version.gitMinor=28' -X 'k8s.io/component-base/version.gitMinor=28' -extldflags=-static -s -w

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; \
Expand Down
Loading