Skip to content
This repository has been archived by the owner on Oct 2, 2023. It is now read-only.

Add support for stamping docker_push #56

Merged
merged 2 commits into from
Jun 22, 2017
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
6 changes: 3 additions & 3 deletions docker/docker.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,23 @@ 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."""
native.http_file(
name = "puller",
url = ("https://storage.googleapis.com/containerregistry-releases/" +
CONTAINERREGISTRY_RELEASE + "/puller.par"),
sha256 = "cfcf1b6478b9ad3297b52adb23d8e5f5dcdccc2028c6cf24f726db025f936b91",
sha256 = "90a76d01ee57a5df7353a533c96966822c9efda61636c11eac11344171556017",
executable = True,
)

native.http_file(
name = "pusher",
url = ("https://storage.googleapis.com/containerregistry-releases/" +
CONTAINERREGISTRY_RELEASE + "/pusher.par"),
sha256 = "c7a55f3159bd1974a0de5fc80665afdc41606d9e04a3be560326f1eae221ae4c",
sha256 = "1989ceb41144784dccb3476cea5b5f1bef112bb0aae56544b9c56572894c38ab",
executable = True,
)

Expand Down
2 changes: 1 addition & 1 deletion docker/push-tag.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@

%{docker_pusher} \
--name=%{registry}/%{repository}:%{tag} \
--tarball=%{image} "$@"
%{stamp} --tarball=%{image} "$@"
17 changes: 16 additions & 1 deletion docker/push.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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 = {
Expand All @@ -61,6 +72,10 @@ _docker_push = rule(
executable = True,
allow_files = True,
),
"stamp": attr.bool(
default = False,
mandatory = False,
),
},
executable = True,
implementation = _impl,
Expand Down
16 changes: 15 additions & 1 deletion docker/testdata/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -246,6 +251,15 @@ docker_build(
},
)

docker_push(
name = "push_stamp",
image = ":link_with_files_base",
registry = "gcr.io",
repository = "convoy-adapter/bazel-test",
Copy link
Contributor

Choose a reason for hiding this comment

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

@samuraisam's note from #54: it might be worth putting a stamped value in here too. (it seems to work, but it'd be good to test.)

stamp = True,
tag = "{BUILD_USER}",
)

docker_build(
name = "pause_based",
base = ":pause.tar",
Expand Down