From 34e571d3146eea754e3a421cb5bc175ec205403e Mon Sep 17 00:00:00 2001 From: Manuel Dewald Date: Thu, 20 Jul 2023 16:48:42 +0200 Subject: [PATCH] Reintroduce old digest functionality * This digest function executes HEAD requests instead of querying the manifest * GET requests are ratelimited in some registries --- lib/docker_registry2.rb | 4 ++++ lib/registry/registry.rb | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/lib/docker_registry2.rb b/lib/docker_registry2.rb index a7740e5..b29f068 100644 --- a/lib/docker_registry2.rb +++ b/lib/docker_registry2.rb @@ -22,4 +22,8 @@ def self.tags(repository) def self.manifest(repository, tag) @reg.manifest(repository, tag) end + + def self.manifest_digest(repository, tag) + @reg.manifest_digest(repository, tag) + end end diff --git a/lib/registry/registry.rb b/lib/registry/registry.rb index edbbffe..5f804e0 100644 --- a/lib/registry/registry.rb +++ b/lib/registry/registry.rb @@ -126,6 +126,14 @@ def blob(repo, digest, outpath = nil) end end + def manifest_digest(repo, tag) + tag_path = "/v2/#{repo}/manifests/#{tag}" + dohead(tag_path).headers[:docker_content_digest] + rescue DockerRegistry2::InvalidMethod + # Pre-2.3.0 registries didn't support manifest HEAD requests + doget(tag_path).headers[:docker_content_digest] + end + def digest(image, tag, architecture = nil, os = nil, variant = nil) manifest = manifest(image, tag) parsed_manifest = JSON.parse(manifest.body)