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

fix: forward well known attributes to macro expanded targets #370

Merged
merged 5 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module(
compatibility_level = 1,
)

bazel_dep(name = "aspect_bazel_lib", version = "1.32.0")
bazel_dep(name = "aspect_bazel_lib", version = "1.35.0")
bazel_dep(name = "bazel_skylib", version = "1.4.1")
bazel_dep(name = "platforms", version = "0.0.5")

Expand Down
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,
thesayyn marked this conversation as resolved.
Show resolved Hide resolved
**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
6 changes: 3 additions & 3 deletions oci/dependencies.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def rules_oci_dependencies():

http_archive(
name = "aspect_bazel_lib",
sha256 = "f1c181b910f821072f38ee45bb87db6b56275458c7f832c54c54ba6334119eca",
strip_prefix = "bazel-lib-1.32.0",
url = "https://github.com/aspect-build/bazel-lib/releases/download/v1.32.0/bazel-lib-v1.32.0.tar.gz",
sha256 = "e9505bd956da64b576c433e4e41da76540fd8b889bbd17617fe480a646b1bfb9",
strip_prefix = "bazel-lib-1.35.0",
url = "https://github.com/aspect-build/bazel-lib/releases/download/v1.35.0/bazel-lib-v1.35.0.tar.gz",
)