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 and alexeagle committed Jun 26, 2024
1 parent 7bece45 commit 9a32fc2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
16 changes: 16 additions & 0 deletions e2e/assertion/wksp/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
load("@aspect_bazel_lib//lib:diff_test.bzl", "diff_test")
load("@bazel_skylib//rules:write_file.bzl", "write_file")
load("@rules_oci//oci:defs.bzl", "oci_image", "oci_push")

oci_image(
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",
)
13 changes: 13 additions & 0 deletions oci/private/pull.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,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 @@ -320,6 +326,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 @@ -339,6 +351,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 9a32fc2

Please sign in to comment.