Skip to content

Commit

Permalink
fix: propagate all tags, not just well known ones (#366)
Browse files Browse the repository at this point in the history
  • Loading branch information
ajaypbrt authored Sep 19, 2023
1 parent 7584c97 commit bb7e264
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 29 deletions.
2 changes: 1 addition & 1 deletion docs/image.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ This is similar to the same-named target created by rules_docker's `container_im
| <a id="oci_image-env"></a>env | Environment variables provisioned by default to the running container. See documentation above. | <code>None</code> |
| <a id="oci_image-cmd"></a>cmd | Command & argument configured by default in the running container. See documentation above. | <code>None</code> |
| <a id="oci_image-entrypoint"></a>entrypoint | Entrypoint configured by default in the running container. See documentation above. | <code>None</code> |
| <a id="oci_image-tags"></a>tags | Tags to propagate to targets declared by this macro. Input will be filtered to well known tags only. See [propagate_well_known_tags] (https://github.com/aspect-build/bazel-lib/blob/main/docs/utils.md#propagate_well_known_tags) for details. | <code>[]</code> |
| <a id="oci_image-tags"></a>tags | Tags to propagate to targets declared by this macro. | <code>[]</code> |
| <a id="oci_image-kwargs"></a>kwargs | other named arguments to [oci_image_rule](#oci_image_rule) | none |


2 changes: 1 addition & 1 deletion docs/push.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ Allows the remote_tags attribute to be a list of strings in addition to a text f
| :------------- | :------------- | :------------- |
| <a id="oci_push-name"></a>name | name of resulting oci_push_rule | none |
| <a id="oci_push-remote_tags"></a>remote_tags | a list of tags to apply to the image after pushing, or a label of a file containing tags one-per-line. See [stamped_tags](https://github.com/bazel-contrib/rules_oci/blob/main/examples/push/stamp_tags.bzl) as one example of a way to produce such a file. | <code>None</code> |
| <a id="oci_push-tags"></a>tags | Tags to propagate to targets declared by this macro. Input will be filtered to well known tags only. See [propagate_well_known_tags] (https://github.com/aspect-build/bazel-lib/blob/main/docs/utils.md#propagate_well_known_tags) for details. | <code>[]</code> |
| <a id="oci_push-tags"></a>tags | Tags to propagate to targets declared by this macro. | <code>[]</code> |
| <a id="oci_push-kwargs"></a>kwargs | other named arguments to [oci_push_rule](#oci_push_rule). | none |


44 changes: 17 additions & 27 deletions oci/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ load("//oci/private:push.bzl", _oci_push = "oci_push")
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_well_known_tags")
load("@bazel_skylib//lib:types.bzl", "types")
load("@bazel_skylib//rules:write_file.bzl", "write_file")

Expand Down Expand Up @@ -43,10 +42,7 @@ def oci_image(name, labels = None, annotations = None, env = None, cmd = None, e
env: Environment variables provisioned by default to the running container. See documentation above.
cmd: Command & argument configured by default in the running container. See documentation above.
entrypoint: Entrypoint configured by default in the running container. See documentation above.
tags: Tags to propagate to targets declared by this macro. Input will be filtered to well known tags only.
See [propagate_well_known_tags]
(https://github.com/aspect-build/bazel-lib/blob/main/docs/utils.md#propagate_well_known_tags)
for details.
tags: Tags to propagate to targets declared by this macro.
**kwargs: other named arguments to [oci_image_rule](#oci_image_rule)
"""
if types.is_dict(annotations):
Expand All @@ -55,7 +51,7 @@ def oci_image(name, labels = None, annotations = None, env = None, cmd = None, e
name = annotations_label,
out = "_{}.annotations.txt".format(name),
content = ["{}={}".format(key, value) for (key, value) in annotations.items()],
tags = propagate_well_known_tags(tags),
tags = tags,
)
annotations = annotations_label

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

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

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

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

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

Expand All @@ -116,7 +112,7 @@ def oci_image(name, labels = None, annotations = None, env = None, cmd = None, e
env = env,
cmd = cmd,
entrypoint = entrypoint,
tags = propagate_well_known_tags(tags),
tags = tags,
**kwargs
)

Expand All @@ -126,14 +122,14 @@ def oci_image(name, labels = None, annotations = None, env = None, cmd = None, e
name = "_{}_index_json".format(name),
directory = name,
path = "index.json",
tags = propagate_well_known_tags(tags),
tags = tags,
)

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

# Matches the [name].digest target produced by rules_docker container_image
Expand All @@ -143,7 +139,7 @@ def oci_image(name, labels = None, annotations = None, env = None, cmd = None, e
srcs = ["_{}_index.json".format(name)],
filter = """.manifests[0].digest""",
out = name + ".json.sha256", # path chosen to match rules_docker for easy migration
tags = propagate_well_known_tags(tags),
tags = tags,
)

def oci_push(name, remote_tags = None, tags = [], **kwargs):
Expand All @@ -157,10 +153,7 @@ def oci_push(name, remote_tags = None, tags = [], **kwargs):
or a label of a file containing tags one-per-line.
See [stamped_tags](https://github.com/bazel-contrib/rules_oci/blob/main/examples/push/stamp_tags.bzl)
as one example of a way to produce such a file.
tags: Tags to propagate to targets declared by this macro. Input will be filtered to well known tags only.
See [propagate_well_known_tags]
(https://github.com/aspect-build/bazel-lib/blob/main/docs/utils.md#propagate_well_known_tags)
for details.
tags: Tags to propagate to targets declared by this macro.
**kwargs: other named arguments to [oci_push_rule](#oci_push_rule).
"""
if types.is_list(remote_tags):
Expand All @@ -169,14 +162,14 @@ def oci_push(name, remote_tags = None, tags = [], **kwargs):
name = tags_label,
out = "_{}.tags.txt".format(name),
content = remote_tags,
tags = propagate_well_known_tags(tags),
tags = tags,
)
remote_tags = tags_label

oci_push_rule(
name = name,
remote_tags = remote_tags,
tags = propagate_well_known_tags(tags),
tags = tags,
**kwargs
)

Expand All @@ -191,10 +184,7 @@ def oci_tarball(name, repo_tags = None, tags = [], **kwargs):
or a label of a file containing tags one-per-line.
See [stamped_tags](https://github.com/bazel-contrib/rules_oci/blob/main/examples/push/stamp_tags.bzl)
as one example of a way to produce such a file.
tags: Tags to propagate to targets declared by this macro. Input will be filtered to well known tags only.
See [propagate_well_known_tags]
(https://github.com/aspect-build/bazel-lib/blob/main/docs/utils.md#propagate_well_known_tags)
for details.
tags: Tags to propagate to targets declared by this macro.
**kwargs: other named arguments to [oci_tarball_rule](#oci_tarball_rule).
"""
if types.is_list(repo_tags):
Expand All @@ -203,13 +193,13 @@ def oci_tarball(name, repo_tags = None, tags = [], **kwargs):
name = tags_label,
out = "_{}.tags.txt".format(name),
content = repo_tags,
tags = propagate_well_known_tags(tags),
tags = tags,
)
repo_tags = tags_label

oci_tarball_rule(
name = name,
repo_tags = repo_tags,
tags = propagate_well_known_tags(tags),
tags = tags,
**kwargs
)

0 comments on commit bb7e264

Please sign in to comment.