Skip to content

Commit

Permalink
fix: forward common rule attributes like testonly to targets created …
Browse files Browse the repository at this point in the history
…by oci_image and oci_tarball macros.
  • Loading branch information
reltuk committed Sep 28, 2023
1 parent 036ddb0 commit a903022
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions oci/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ load("@rules_oci//oci:defs.bzl", ...)
load("@aspect_bazel_lib//lib:copy_file.bzl", "copy_file")
load("@aspect_bazel_lib//lib:directory_path.bzl", "directory_path")
load("@aspect_bazel_lib//lib:jq.bzl", "jq")
load("@aspect_bazel_lib//lib:utils.bzl", "propagate_common_rule_attributes")
load("@bazel_skylib//lib:types.bzl", "types")
load("@bazel_skylib//rules:write_file.bzl", "write_file")
load("//oci/private:image.bzl", _oci_image = "oci_image")
Expand Down Expand Up @@ -45,13 +46,16 @@ def oci_image(name, labels = None, annotations = None, env = None, cmd = None, e
tags: Tags to propagate to targets declared by this macro.
**kwargs: other named arguments to [oci_image_rule](#oci_image_rule)
"""
forwarded_kwargs = propagate_common_rule_attributes(kwargs)

if types.is_dict(annotations):
annotations_label = "_{}_write_annotations".format(name)
write_file(
name = annotations_label,
out = "_{}.annotations.txt".format(name),
content = ["{}={}".format(key, value) for (key, value) in annotations.items()],
tags = tags,
**forwarded_kwargs,
)
annotations = annotations_label

Expand All @@ -62,6 +66,7 @@ def oci_image(name, labels = None, annotations = None, env = None, cmd = None, e
out = "_{}.labels.txt".format(name),
content = ["{}={}".format(key, value) for (key, value) in labels.items()],
tags = tags,
**forwarded_kwargs,
)
labels = labels_label

Expand All @@ -72,6 +77,7 @@ def oci_image(name, labels = None, annotations = None, env = None, cmd = None, e
out = "_{}.env.txt".format(name),
content = ["{}={}".format(key, value) for (key, value) in env.items()],
tags = tags,
**forwarded_kwargs,
)
env = env_label

Expand All @@ -82,6 +88,7 @@ def oci_image(name, labels = None, annotations = None, env = None, cmd = None, e
out = "_{}.env.txt".format(name),
content = ["{}={}".format(key, value) for (key, value) in env.items()],
tags = tags,
**forwarded_kwargs,
)
env = env_label

Expand All @@ -92,6 +99,7 @@ def oci_image(name, labels = None, annotations = None, env = None, cmd = None, e
out = "_{}.cmd.txt".format(name),
content = [",".join(cmd)],
tags = tags,
**forwarded_kwargs,
)
cmd = cmd_label

Expand All @@ -102,6 +110,7 @@ def oci_image(name, labels = None, annotations = None, env = None, cmd = None, e
out = "_{}.entrypoint.txt".format(name),
content = [",".join(entrypoint)],
tags = tags,
**forwarded_kwargs,
)
entrypoint = entrypoint_label

Expand All @@ -123,13 +132,15 @@ def oci_image(name, labels = None, annotations = None, env = None, cmd = None, e
directory = name,
path = "index.json",
tags = tags,
**forwarded_kwargs,
)

copy_file(
name = "_{}_index_json_cp".format(name),
src = "_{}_index_json".format(name),
out = "_{}_index.json".format(name),
tags = tags,
**forwarded_kwargs,
)

# Matches the [name].digest target produced by rules_docker container_image
Expand All @@ -140,6 +151,7 @@ def oci_image(name, labels = None, annotations = None, env = None, cmd = None, e
filter = """.manifests[0].digest""",
out = name + ".json.sha256", # path chosen to match rules_docker for easy migration
tags = tags,
**forwarded_kwargs,
)

def oci_push(name, remote_tags = None, tags = [], **kwargs):
Expand Down Expand Up @@ -187,13 +199,16 @@ def oci_tarball(name, repo_tags = None, tags = [], **kwargs):
tags: Tags to propagate to targets declared by this macro.
**kwargs: other named arguments to [oci_tarball_rule](#oci_tarball_rule).
"""
forwarded_kwargs = propagate_common_rule_attributes(kwargs)

if types.is_list(repo_tags):
tags_label = "_{}_write_tags".format(name)
write_file(
name = tags_label,
out = "_{}.tags.txt".format(name),
content = repo_tags,
tags = tags,
**forwarded_kwargs,
)
repo_tags = tags_label

Expand Down

0 comments on commit a903022

Please sign in to comment.