From 6e179b8c0935c7be286e256f1bfde07d6e0788fd Mon Sep 17 00:00:00 2001 From: Aaron Son Date: Thu, 28 Sep 2023 10:46:20 -0700 Subject: [PATCH] TEMP COMMIT. --- WORKSPACE | 5 +++++ oci/defs.bzl | 31 +++++++++++++++++-------------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/WORKSPACE b/WORKSPACE index 3b3602ad..83c9c862 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -2,6 +2,11 @@ # This is *not* included in the published distribution. workspace(name = "rules_oci") +local_repository( + name = "aspect_bazel_lib", + path = "/Users/aaronson/src/bazel-lib", +) + load(":internal_deps.bzl", "rules_oci_internal_deps") # Fetch deps needed only locally for development diff --git a/oci/defs.bzl b/oci/defs.bzl index 40261526..10905981 100644 --- a/oci/defs.bzl +++ b/oci/defs.bzl @@ -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") @@ -21,7 +22,7 @@ oci_image_rule = _oci_image oci_image_index = _oci_image_index oci_push_rule = _oci_push -def oci_image(name, labels = None, annotations = None, env = None, cmd = None, entrypoint = None, tags = [], testonly = False, **kwargs): +def oci_image(name, labels = None, annotations = None, env = None, cmd = None, entrypoint = None, tags = [], **kwargs): """Macro wrapper around [oci_image_rule](#oci_image_rule). Allows labels and annotations to be provided as a dictionary, in addition to a text file. @@ -45,6 +46,8 @@ 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( @@ -52,7 +55,7 @@ def oci_image(name, labels = None, annotations = None, env = None, cmd = None, e out = "_{}.annotations.txt".format(name), content = ["{}={}".format(key, value) for (key, value) in annotations.items()], tags = tags, - testonly = testonly, + **forwarded_kwargs, ) annotations = annotations_label @@ -63,7 +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, - testonly = testonly, + **forwarded_kwargs, ) labels = labels_label @@ -74,7 +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, - testonly = testonly, + **forwarded_kwargs, ) env = env_label @@ -85,7 +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, - testonly = testonly, + **forwarded_kwargs, ) env = env_label @@ -96,7 +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, - testonly = testonly, + **forwarded_kwargs, ) cmd = cmd_label @@ -107,7 +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, - testonly = testonly, + **forwarded_kwargs, ) entrypoint = entrypoint_label @@ -119,7 +122,6 @@ def oci_image(name, labels = None, annotations = None, env = None, cmd = None, e cmd = cmd, entrypoint = entrypoint, tags = tags, - testonly = testonly, **kwargs ) @@ -130,7 +132,7 @@ def oci_image(name, labels = None, annotations = None, env = None, cmd = None, e directory = name, path = "index.json", tags = tags, - testonly = testonly, + **forwarded_kwargs, ) copy_file( @@ -138,7 +140,7 @@ def oci_image(name, labels = None, annotations = None, env = None, cmd = None, e src = "_{}_index_json".format(name), out = "_{}_index.json".format(name), tags = tags, - testonly = testonly, + **forwarded_kwargs, ) # Matches the [name].digest target produced by rules_docker container_image @@ -149,7 +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, - testonly = testonly, + **forwarded_kwargs, ) def oci_push(name, remote_tags = None, tags = [], **kwargs): @@ -183,7 +185,7 @@ def oci_push(name, remote_tags = None, tags = [], **kwargs): **kwargs ) -def oci_tarball(name, repo_tags = None, tags = [], testonly = False, **kwargs): +def oci_tarball(name, repo_tags = None, tags = [], **kwargs): """Macro wrapper around [oci_tarball_rule](#oci_tarball_rule). Allows the repo_tags attribute to be a list of strings in addition to a text file. @@ -197,6 +199,8 @@ def oci_tarball(name, repo_tags = None, tags = [], testonly = False, **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( @@ -204,7 +208,7 @@ def oci_tarball(name, repo_tags = None, tags = [], testonly = False, **kwargs): out = "_{}.tags.txt".format(name), content = repo_tags, tags = tags, - testonly = testonly, + **forwarded_kwargs, ) repo_tags = tags_label @@ -212,6 +216,5 @@ def oci_tarball(name, repo_tags = None, tags = [], testonly = False, **kwargs): name = name, repo_tags = repo_tags, tags = tags, - testonly = testonly, **kwargs )