From cbe74b24c4fa391d0e1c32a2ea002689e93b7d01 Mon Sep 17 00:00:00 2001 From: decentral1se Date: Tue, 10 Aug 2021 13:16:41 +0200 Subject: [PATCH] fix: support different type of registry response --- client/registry.go | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/client/registry.go b/client/registry.go index 89d6d7963..4af111372 100644 --- a/client/registry.go +++ b/client/registry.go @@ -116,7 +116,7 @@ func GetTagDigest(image reference.Named) (string, error) { return "", err } - registryRes := struct { + registryResT1 := struct { SchemaVersion int MediaType string Manifests []struct { @@ -130,17 +130,39 @@ func GetTagDigest(image reference.Named) (string, error) { } }{} - if err := json.Unmarshal(body, ®istryRes); err != nil { + registryResT2 := struct { + SchemaVersion int + MediaType string + Config struct { + MediaType string + Size int + Digest string + } + Layers []struct { + MediaType string + Size int + Digest string + } + }{} + + if err := json.Unmarshal(body, ®istryResT1); err != nil { return "", err } var digest string - for _, manifest := range registryRes.Manifests { + for _, manifest := range registryResT1.Manifests { if string(manifest.Platform.Architecture) == "amd64" { digest = strings.Split(manifest.Digest, ":")[1][:7] } } + if digest == "" { + if err := json.Unmarshal(body, ®istryResT2); err != nil { + return "", err + } + digest = strings.Split(registryResT2.Config.Digest, ":")[1][:7] + } + if digest == "" { return "", fmt.Errorf("Unable to retrieve amd64 digest for '%s'", image) }