From f73e3cbb30bdfa8a8cb7d513231d29d6b513b82f Mon Sep 17 00:00:00 2001 From: Jeff Grafton Date: Wed, 26 Apr 2017 16:52:52 -0700 Subject: [PATCH] Use munged semantic version for side-loaded docker tag --- BUILD.bazel | 2 +- build/BUILD | 11 +++++++---- build/lib/release.sh | 15 +++++++++------ hack/print-workspace-status.sh | 1 + 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/BUILD.bazel b/BUILD.bazel index 259f84de349e7..4a499336a50c4 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -72,6 +72,6 @@ filegroup( genrule( name = "save_git_version", outs = ["version"], - cmd = "grep ^STABLE_BUILD_SCM_REVISION bazel-out/stable-status.txt | cut -d' ' -f2 >$@", + cmd = "grep ^STABLE_BUILD_SCM_REVISION bazel-out/stable-status.txt | awk '{print $$2}' >$@", stamp = 1, ) diff --git a/build/BUILD b/build/BUILD index ff7d2ea9a960f..feb2439099e90 100644 --- a/build/BUILD +++ b/build/BUILD @@ -1,7 +1,7 @@ package(default_visibility = ["//visibility:public"]) load("@io_bazel//tools/build_defs/docker:docker.bzl", "docker_build") -load("@io_kubernetes_build//defs:build.bzl", "md5sum", "release_filegroup") +load("@io_kubernetes_build//defs:build.bzl", "release_filegroup") filegroup( name = "package-srcs", @@ -63,9 +63,12 @@ DOCKERIZED_BINARIES = { }, } -[md5sum( - name = binary + ".docker_tag", - src = meta["target"], +[genrule( + name = binary + "_docker_tag", + srcs = [meta["target"]], + outs = [binary + ".docker_tag"], + cmd = "grep ^STABLE_DOCKER_TAG bazel-out/stable-status.txt | awk '{print $$2}' >$@", + stamp = 1, ) for binary, meta in DOCKERIZED_BINARIES.items()] [docker_build( diff --git a/build/lib/release.sh b/build/lib/release.sh index 5cf716e10ed4b..eb594e7dd2074 100644 --- a/build/lib/release.sh +++ b/build/lib/release.sh @@ -278,9 +278,12 @@ function kube::release::create_docker_images_for_server() { kube::log::status "Starting Docker build for image: ${binary_name}" ( - local md5_sum - md5_sum=$(kube::release::md5 "${binary_dir}/${binary_name}") - + # Docker tags cannot contain '+' + local docker_tag="${KUBE_GIT_VERSION/+/_}" + if [[ -z "${docker_tag}" ]]; then + kube::log::error "git version information missing; cannot create Docker tag" + return 1 + fi local docker_build_path="${binary_dir}/${binary_name}.dockerbuild" local docker_file_path="${docker_build_path}/Dockerfile" local binary_file_path="${binary_dir}/${binary_name}" @@ -292,15 +295,15 @@ function kube::release::create_docker_images_for_server() { if [[ ${arch} == "amd64" ]]; then # If we are building a amd64 docker image, preserve the original image name - local docker_image_tag=gcr.io/google_containers/${binary_name}:${md5_sum} + local docker_image_tag="gcr.io/google_containers/${binary_name}:${docker_tag}" else # If we are building a docker image for another architecture, append the arch in the image tag - local docker_image_tag=gcr.io/google_containers/${binary_name}-${arch}:${md5_sum} + local docker_image_tag="gcr.io/google_containers/${binary_name}-${arch}:${docker_tag}" fi "${DOCKER[@]}" build --pull -q -t "${docker_image_tag}" ${docker_build_path} >/dev/null "${DOCKER[@]}" save ${docker_image_tag} > ${binary_dir}/${binary_name}.tar - echo $md5_sum > ${binary_dir}/${binary_name}.docker_tag + echo "${docker_tag}" > ${binary_dir}/${binary_name}.docker_tag rm -rf ${docker_build_path} diff --git a/hack/print-workspace-status.sh b/hack/print-workspace-status.sh index 81816e5954bd6..a20e593a140c4 100755 --- a/hack/print-workspace-status.sh +++ b/hack/print-workspace-status.sh @@ -35,6 +35,7 @@ STABLE_BUILD_SCM_STATUS ${KUBE_GIT_TREE_STATE-} STABLE_BUILD_SCM_REVISION ${KUBE_GIT_VERSION-} STABLE_BUILD_MAJOR_VERSION ${KUBE_GIT_MAJOR-} STABLE_BUILD_MINOR_VERSION ${KUBE_GIT_MINOR-} +STABLE_DOCKER_TAG ${KUBE_GIT_VERSION/+/_} gitCommit ${KUBE_GIT_COMMIT-} gitTreeState ${KUBE_GIT_TREE_STATE-} gitVersion ${KUBE_GIT_VERSION-}