From 9a32fc23620317e12ea0cbfc3b053d79ac7a4786 Mon Sep 17 00:00:00 2001 From: Ignas Anikevicius <240938+aignas@users.noreply.github.com> Date: Wed, 26 Jun 2024 20:21:07 +0900 Subject: [PATCH] feat: expose the digest as a filegroup (#542) --- e2e/assertion/wksp/BUILD.bazel | 16 ++++++++++++++++ oci/private/pull.bzl | 13 +++++++++++++ 2 files changed, 29 insertions(+) diff --git a/e2e/assertion/wksp/BUILD.bazel b/e2e/assertion/wksp/BUILD.bazel index 216cbe50..65594de8 100644 --- a/e2e/assertion/wksp/BUILD.bazel +++ b/e2e/assertion/wksp/BUILD.bazel @@ -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( @@ -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", +) diff --git a/oci/private/pull.bzl b/oci/private/pull.bzl index 9a96da54..4e95f2fd 100644 --- a/oci/private/pull.bzl +++ b/oci/private/pull.bzl @@ -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( @@ -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}", @@ -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"]: