From ed99403eaa04d924bec2ecdd0ece54b74216b9f4 Mon Sep 17 00:00:00 2001 From: steve-261370 <61995836+steve-261370@users.noreply.github.com> Date: Fri, 7 Jun 2024 10:43:43 -0700 Subject: [PATCH] Add import_tags attribute to oci_pull (#573) --- docs/pull.md | 3 ++- oci/private/pull.bzl | 7 +++++++ oci/pull.bzl | 5 ++++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/docs/pull.md b/docs/pull.md index 65c4c7b8..63b08f3e 100644 --- a/docs/pull.md +++ b/docs/pull.md @@ -94,7 +94,7 @@ See the [examples/credential_helper](/examples/credential_helper/auth.sh) direct
oci_pull(name, image, repository, registry, platforms, digest, tag, reproducible, is_bzlmod, config, - config_path) + config_path, bazel_tags)Repository macro to fetch image manifest data from a remote docker registry. @@ -123,5 +123,6 @@ in rules like `oci_image`. | is_bzlmod | whether the oci_pull is being called from a module extension |
False
|
| config | Label to a .docker/config.json
file. | None
|
| config_path | Deprecated. use config
attribute or DOCKER_CONFIG environment variable. | None
|
+| bazel_tags | Bazel tags to be propagated to generated rules. | []
|
diff --git a/oci/private/pull.bzl b/oci/private/pull.bzl
index 64b21cbf..ab897c33 100644
--- a/oci/private/pull.bzl
+++ b/oci/private/pull.bzl
@@ -178,6 +178,7 @@ copy_to_directory(
"oci-layout",
"index.json",
],
+ tags = {bazel_tags},
visibility = ["//visibility:public"]
)
"""
@@ -274,8 +275,11 @@ def _oci_pull_impl(rctx):
))
rctx.file("oci-layout", json.encode_indent({"imageLayoutVersion": "1.0.0"}, indent = " "))
+ bazel_tags = "[\"{}\"]".format("\", \"".join(rctx.attr.bazel_tags))
+
rctx.file("BUILD.bazel", content = _BUILD_FILE_TMPL.format(
target_name = rctx.attr.target_name,
+ bazel_tags = bazel_tags,
))
oci_pull = repository_rule(
@@ -290,6 +294,9 @@ oci_pull = repository_rule(
doc = "Name given for the image target, e.g. 'image'",
mandatory = True,
),
+ "bazel_tags": attr.string_list(
+ doc = "Bazel tags to apply to generated targets of this rule",
+ ),
},
),
environ = authn.ENVIRON,
diff --git a/oci/pull.bzl b/oci/pull.bzl
index c5ab6979..024f9b77 100644
--- a/oci/pull.bzl
+++ b/oci/pull.bzl
@@ -103,7 +103,7 @@ _PLATFORM_TO_BAZEL_CPU = {
"linux/mips64le": "@platforms//cpu:mips64",
}
-def oci_pull(name, image = None, repository = None, registry = None, platforms = None, digest = None, tag = None, reproducible = True, is_bzlmod = False, config = None, config_path = None):
+def oci_pull(name, image = None, repository = None, registry = None, platforms = None, digest = None, tag = None, reproducible = True, is_bzlmod = False, config = None, config_path = None, bazel_tags = []):
"""Repository macro to fetch image manifest data from a remote docker registry.
To use the resulting image, you can use the `@wkspc` shorthand label, for example
@@ -138,6 +138,7 @@ def oci_pull(name, image = None, repository = None, registry = None, platforms =
config: Label to a `.docker/config.json` file.
config_path: Deprecated. use `config` attribute or DOCKER_CONFIG environment variable.
is_bzlmod: whether the oci_pull is being called from a module extension
+ bazel_tags: Bazel tags to be propagated to generated rules.
"""
# Check syntax sugar for registry/repository in place of image
@@ -184,6 +185,7 @@ def oci_pull(name, image = None, repository = None, registry = None, platforms =
config = config,
# TODO(2.0): remove
config_path = config_path,
+ bazel_tags = bazel_tags,
)
if plat in _PLATFORM_TO_BAZEL_CPU:
@@ -208,6 +210,7 @@ def oci_pull(name, image = None, repository = None, registry = None, platforms =
config = config,
# TODO(2.0): remove
config_path = config_path,
+ bazel_tags = bazel_tags,
)
oci_alias(