Skip to content

Commit

Permalink
feat: expose the digest as a filegroup (#542)
Browse files Browse the repository at this point in the history
  • Loading branch information
aignas authored Jun 26, 2024
1 parent 360df7a commit 899af81
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
16 changes: 16 additions & 0 deletions e2e/pull/wksp/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
load("@rules_oci//oci:defs.bzl", "oci_image", "oci_push")
load("@aspect_bazel_lib//lib:diff_test.bzl", "diff_test")
load("@bazel_skylib//rules:write_file.bzl", "write_file")

oci_image(
name = "empty",
Expand All @@ -12,3 +14,17 @@ oci_push(
remote_tags = ["latest"],
repository = "localhost/empty_image",
)

write_file(
name = "want_digest_contents",
out = "want_image_digest.json",
content = [
"sha256:2d4595bbc0fabeb1489b1071f56c26f44a2f495afaa9386ad7d24e7b3d8dfd3e",
],
)

diff_test(
name = "check_they_match",
file1 = "want_digest_contents",
file2 = "@empty_image//:digest",
)
2 changes: 2 additions & 0 deletions e2e/pull/wksp/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

bazel_dep(name = "rules_oci", version = "0.0.0", dev_dependency = True)
bazel_dep(name = "platforms", version = "0.0.7")
bazel_dep(name = "bazel_skylib", version = "1.5.0")
bazel_dep(name = "aspect_bazel_lib", version = "2.1.0")

local_path_override(
module_name = "rules_oci",
Expand Down
13 changes: 13 additions & 0 deletions oci/private/pull.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,12 @@ oci_pull = repository_rule(
)

_MULTI_PLATFORM_IMAGE_ALIAS_TMPL = """\
filegroup(
name = "digest",
srcs = ["digest.txt"],
visibility = ["//visibility:public"],
)
alias(
name = "{target_name}",
actual = select(
Expand All @@ -314,6 +320,12 @@ alias(
"""

_SINGLE_PLATFORM_IMAGE_ALIAS_TMPL = """\
filegroup(
name = "digest",
srcs = ["digest.txt"],
visibility = ["//visibility:public"],
)
alias(
name = "{target_name}",
actual = "@{original}//:{original}",
Expand All @@ -333,6 +345,7 @@ def _oci_alias_impl(rctx):
available_platforms = []

manifest, _, digest = downloader.download_manifest(rctx.attr.identifier, "mf.json")
rctx.file("digest.txt", digest)

if rctx.attr.platforms:
if manifest["mediaType"] in _SUPPORTED_MEDIA_TYPES["index"]:
Expand Down

0 comments on commit 899af81

Please sign in to comment.