Skip to content

Commit

Permalink
Add import_tags attribute to oci_pull (#573)
Browse files Browse the repository at this point in the history
  • Loading branch information
steve-261370 authored Jun 7, 2024
1 parent 3d43cb1 commit ed99403
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
3 changes: 2 additions & 1 deletion docs/pull.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions oci/private/pull.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ copy_to_directory(
"oci-layout",
"index.json",
],
tags = {bazel_tags},
visibility = ["//visibility:public"]
)
"""
Expand Down Expand Up @@ -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(
Expand All @@ -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,
Expand Down
5 changes: 4 additions & 1 deletion oci/pull.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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(
Expand Down

0 comments on commit ed99403

Please sign in to comment.