diff --git a/docker/docker.bzl b/docker/docker.bzl index d0b08ba3b..23866c67f 100644 --- a/docker/docker.bzl +++ b/docker/docker.bzl @@ -25,7 +25,7 @@ load(":pull.bzl", "docker_pull") load(":push.bzl", "docker_push") # The release of the github.com/google/containerregistry to consume. -CONTAINERREGISTRY_RELEASE = "v0.0.10" +CONTAINERREGISTRY_RELEASE = "v0.0.11" def docker_repositories(): """Download dependencies of docker rules.""" @@ -33,7 +33,7 @@ def docker_repositories(): name = "puller", url = ("https://storage.googleapis.com/containerregistry-releases/" + CONTAINERREGISTRY_RELEASE + "/puller.par"), - sha256 = "cfcf1b6478b9ad3297b52adb23d8e5f5dcdccc2028c6cf24f726db025f936b91", + sha256 = "90a76d01ee57a5df7353a533c96966822c9efda61636c11eac11344171556017", executable = True, ) @@ -41,7 +41,7 @@ def docker_repositories(): name = "pusher", url = ("https://storage.googleapis.com/containerregistry-releases/" + CONTAINERREGISTRY_RELEASE + "/pusher.par"), - sha256 = "c7a55f3159bd1974a0de5fc80665afdc41606d9e04a3be560326f1eae221ae4c", + sha256 = "1989ceb41144784dccb3476cea5b5f1bef112bb0aae56544b9c56572894c38ab", executable = True, ) diff --git a/docker/push-tag.sh.tpl b/docker/push-tag.sh.tpl index 04672759a..fcaf09463 100644 --- a/docker/push-tag.sh.tpl +++ b/docker/push-tag.sh.tpl @@ -15,4 +15,4 @@ %{docker_pusher} \ --name=%{registry}/%{repository}:%{tag} \ - --tarball=%{image} "$@" + %{stamp} --tarball=%{image} "$@" diff --git a/docker/push.bzl b/docker/push.bzl index b6b2c87c5..fdca81f24 100644 --- a/docker/push.bzl +++ b/docker/push.bzl @@ -17,8 +17,18 @@ This wraps the containerregistry.tools.docker_pusher executable in a Bazel rule for publishing base images without a Docker client. """ +load( + ":path.bzl", + _get_runfile_path = "runfile", +) + def _impl(ctx): """Core implementation of docker_push.""" + stamp_inputs = [] + if ctx.attr.stamp: + stamp_inputs = [ctx.info_file, ctx.version_file] + + stamp_arg = " ".join(["--stamp-info-file=%s" % f.short_path for f in stamp_inputs]) ctx.template_action( template = ctx.file._tag_tpl, @@ -27,6 +37,7 @@ def _impl(ctx): "registry", ctx.attr.registry, {}), "%{repository}": ctx.expand_make_variables( "repository", ctx.attr.repository, {}), + "%{stamp}": stamp_arg, "%{tag}": ctx.expand_make_variables( "tag", ctx.attr.tag, {}), "%{image}": ctx.file.image.short_path, @@ -39,7 +50,7 @@ def _impl(ctx): return struct(runfiles = ctx.runfiles(files = [ ctx.file.image, ctx.executable._pusher - ])) + ] + stamp_inputs)) _docker_push = rule( attrs = { @@ -61,6 +72,10 @@ _docker_push = rule( executable = True, allow_files = True, ), + "stamp": attr.bool( + default = False, + mandatory = False, + ), }, executable = True, implementation = _impl, diff --git a/docker/testdata/BUILD b/docker/testdata/BUILD index c49315b3e..fe6d77e72 100644 --- a/docker/testdata/BUILD +++ b/docker/testdata/BUILD @@ -13,7 +13,12 @@ # limitations under the License. package(default_visibility = ["//docker:__subpackages__"]) -load("//docker:docker.bzl", "docker_build", "docker_bundle") +load( + "//docker:docker.bzl", + "docker_build", + "docker_bundle", + "docker_push", +) genrule( name = "gen", @@ -246,6 +251,15 @@ docker_build( }, ) +docker_push( + name = "push_stamp", + image = ":link_with_files_base", + registry = "gcr.io", + repository = "convoy-adapter/bazel-test", + stamp = True, + tag = "{BUILD_USER}", +) + docker_build( name = "pause_based", base = ":pause.tar",