From 8d97718733b9f9404abf03c017e4c4f667562682 Mon Sep 17 00:00:00 2001 From: Sasha Date: Tue, 9 May 2023 10:04:08 +1000 Subject: [PATCH 1/2] Support push_targets --- container/bundle.bzl | 17 ++++++++++++++++- container/providers.bzl | 3 +++ container/push.bzl | 3 +++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/container/bundle.bzl b/container/bundle.bzl index 625481f3c..209f8fb73 100644 --- a/container/bundle.bzl +++ b/container/bundle.bzl @@ -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", @@ -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, @@ -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( diff --git a/container/providers.bzl b/container/providers.bzl index 4c04fbc95..e24b80e90 100644 --- a/container/providers.bzl +++ b/container/providers.bzl @@ -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 diff --git a/container/push.bzl b/container/push.bzl index baef9c25f..85be1cd4a 100644 --- a/container/push.bzl +++ b/container/push.bzl @@ -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, ), ] From 6c6211aafc18c996f93743ca527cb706ab1bb963 Mon Sep 17 00:00:00 2001 From: Sasha Date: Tue, 9 May 2023 10:10:15 +1000 Subject: [PATCH 2/2] add tests --- tests/container/BUILD | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/container/BUILD b/tests/container/BUILD index afd029d32..aa911a34e 100644 --- a/tests/container/BUILD +++ b/tests/container/BUILD @@ -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"],