Skip to content

Commit

Permalink
TEMP COMMIT.
Browse files Browse the repository at this point in the history
  • Loading branch information
reltuk committed Sep 28, 2023
1 parent f421c11 commit 6e179b8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
5 changes: 5 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 17 additions & 14 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 All @@ -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.
Expand All @@ -45,14 +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,
testonly = testonly,
**forwarded_kwargs,
)
annotations = annotations_label

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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
)

Expand All @@ -130,15 +132,15 @@ 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(
name = "_{}_index_json_cp".format(name),
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
Expand All @@ -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):
Expand Down Expand Up @@ -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.
Expand All @@ -197,21 +199,22 @@ 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(
name = tags_label,
out = "_{}.tags.txt".format(name),
content = repo_tags,
tags = tags,
testonly = testonly,
**forwarded_kwargs,
)
repo_tags = tags_label

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

0 comments on commit 6e179b8

Please sign in to comment.