diff --git a/Dockerfile b/Dockerfile index 0be8521645..c3e702a965 100644 --- a/Dockerfile +++ b/Dockerfile @@ -64,6 +64,8 @@ WORKDIR ${GOPATH}/src/github.com/kubernetes/kubernetes # force code generation RUN make WHAT=cmd/kube-apiserver ARG TAG +ARG MAJOR +ARG MINOR # build statically linked executables RUN echo "export GIT_COMMIT=$(git rev-parse HEAD)" \ >> /usr/local/go/bin/go-build-static-k8s.sh @@ -71,10 +73,14 @@ RUN echo "export BUILD_DATE=$(date -u +%Y-%m-%dT%H:%M:%SZ)" \ >> /usr/local/go/bin/go-build-static-k8s.sh RUN echo "export GO_LDFLAGS=\"-linkmode=external \ -X k8s.io/component-base/version.gitVersion=${TAG} \ + -X k8s.io/component-base/version.gitMajor=${MAJOR} \ + -X k8s.io/component-base/version.gitMinor=${MINOR} \ -X k8s.io/component-base/version.gitCommit=\${GIT_COMMIT} \ -X k8s.io/component-base/version.gitTreeState=clean \ -X k8s.io/component-base/version.buildDate=\${BUILD_DATE} \ -X k8s.io/client-go/pkg/version.gitVersion=${TAG} \ + -X k8s.io/client-go/pkg/version.gitMajor=${MAJOR} \ + -X k8s.io/client-go/pkg/version.gitMinor=${MINOR} \ -X k8s.io/client-go/pkg/version.gitCommit=\${GIT_COMMIT} \ -X k8s.io/client-go/pkg/version.gitTreeState=clean \ -X k8s.io/client-go/pkg/version.buildDate=\${BUILD_DATE} \ diff --git a/scripts/build-image-kubernetes b/scripts/build-image-kubernetes index 904461a234..847e1bca12 100755 --- a/scripts/build-image-kubernetes +++ b/scripts/build-image-kubernetes @@ -7,6 +7,8 @@ source ./scripts/version.sh DOCKER_BUILDKIT=${DOCKER_BUILDKIT:-1} docker image build \ --build-arg TAG=${VERSION} \ + --build-arg MAJOR=${VERSION_MAJOR} \ + --build-arg MINOR=${VERSION_MINOR} \ --build-arg KUBERNETES_VERSION=${KUBERNETES_VERSION} \ --tag ${REPO}/hardened-kubernetes:${DOCKERIZED_VERSION} \ --tag ${REPO}/hardened-kubernetes:${DOCKERIZED_VERSION}-${GOARCH} \ diff --git a/scripts/version.sh b/scripts/version.sh index fe77468a99..544b624957 100755 --- a/scripts/version.sh +++ b/scripts/version.sh @@ -53,4 +53,9 @@ else VERSION="${KUBERNETES_VERSION}-dev+${COMMIT:0:8}$DIRTY" fi +if [[ "${VERSION}" =~ ^v([0-9]+)\.([0-9]+)(\.[0-9]+)?([-+].*)?$ ]]; then + VERSION_MAJOR=${BASH_REMATCH[1]} + VERSION_MINOR=${BASH_REMATCH[2]} +fi + DOCKERIZED_VERSION="${VERSION/+/-}" # this mimics what kubernetes builds do