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

Support push_targets in container_bundle #2253

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
17 changes: 16 additions & 1 deletion container/bundle.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"""Rule for bundling Container images into a tarball."""

load("@bazel_skylib//lib:dicts.bzl", "dicts")
load("@io_bazel_rules_docker//container:providers.bzl", "BundleInfo", "STAMP_ATTR", "StampSettingInfo")
load("@io_bazel_rules_docker//container:providers.bzl", "BundleInfo", "PushInfo", "STAMP_ATTR", "StampSettingInfo")
load(
"//container:layer_tools.bzl",
_assemble_image = "assemble",
Expand Down Expand Up @@ -63,6 +63,20 @@ def _container_bundle_impl(ctx):
runfiles += layer.get("diff_id", [])
if layer.get("legacy"):
runfiles.append(layer.get("legacy"))
for push_target in ctx.attr.push_targets:
push_info = push_target[PushInfo]
tag = push_info.registry + "/" + push_info.repository + ":" + push_info.tag

layer = _get_layers(ctx, ctx.label.name, push_info.image)
images[tag] = layer
runfiles.append(layer.get("config"))
runfiles.append(layer.get("config_digest"))
runfiles += layer.get("unzipped_layer", [])
runfiles += layer.get("diff_id", [])
if layer.get("legacy"):
runfiles.append(layer.get("legacy"))
if push_info.tag_file:
runfiles.append(push_info.tag_file)

_incr_load(
ctx,
Expand Down Expand Up @@ -102,6 +116,7 @@ container_bundle_ = rule(
# Implicit dependencies.
"image_targets": attr.label_list(allow_files = True),
"images": attr.string_dict(),
"push_targets": attr.label_list(allow_files = True, providers = [PushInfo]),
"stamp": STAMP_ATTR,
"tar_output": attr.output(),
"experimental_tarball_format": attr.string(
Expand Down
3 changes: 3 additions & 0 deletions container/providers.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ LayerInfo = provider(fields = [
PushInfo = provider(fields = [
"registry",
"repository",
"image",
"digest",
"tag",
"tag_file",
])

# A provider containing information exposed by filter_layer rules
Expand Down
3 changes: 3 additions & 0 deletions container/push.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,10 @@ def _impl(ctx):
PushInfo(
registry = registry,
repository = repository,
image = ctx.attr.image,
digest = ctx.outputs.digest,
tag = tag,
tag_file = ctx.file.tag_file,
),
]

Expand Down
23 changes: 23 additions & 0 deletions tests/container/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,29 @@ docker_push_all(
bundle = ":three_images_bundle",
)

container_bundle(
name = "push_targets_bundle",
push_targets = [
":new_push_test_oci",
":new_push_test_oci_from_new_puller",
":new_push_test_legacy_from_container_img",
":new_push_test_legacy_from_container_img_with_auth",
":new_push_test_legacy_from_new_puller",
":new_push_test_legacy_from_old_puller",
":new_push_test_tar",
":new_push_test_old_puller_tar",
":new_push_test_oci_tag_file",
":new_push_test_legacy_tag_file",
":new_push_stamped_test_legacy",
":new_push_stamped_test_oci",
]
)

docker_push_all(
name = "test_docker_push_push_targets_bundle",
bundle = ":push_targets_bundle",
)

py_test(
name = "build_tar_test",
srcs = ["build_tar_test.py"],
Expand Down