Skip to content

Commit 18aa033

Browse files
committed
Get digest of multi-arch images
Fixes #4156 Signed-off-by: David Gageot <[email protected]>
1 parent 1110eb1 commit 18aa033

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

pkg/skaffold/docker/remote.go

+28-6
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,17 @@ func AddRemoteTag(src, target string, insecureRegistries map[string]bool) error
5050
}
5151

5252
func getRemoteDigest(identifier string, insecureRegistries map[string]bool) (string, error) {
53-
img, err := remoteImage(identifier, insecureRegistries)
54-
if err != nil {
55-
return "", fmt.Errorf("getting image: %w", err)
53+
idx, err := remoteIndex(identifier, insecureRegistries)
54+
if err == nil {
55+
return digest(idx)
5656
}
5757

58-
h, err := img.Digest()
58+
img, err := remoteImage(identifier, insecureRegistries)
5959
if err != nil {
60-
return "", fmt.Errorf("getting digest: %w", err)
60+
return "", fmt.Errorf("getting image: %w", err)
6161
}
6262

63-
return h.String(), nil
63+
return digest(img)
6464
}
6565

6666
// RetrieveRemoteConfig retrieves the remote config file for an image
@@ -101,6 +101,15 @@ func remoteImage(identifier string, insecureRegistries map[string]bool) (v1.Imag
101101
return getRemoteImageImpl(ref)
102102
}
103103

104+
func remoteIndex(identifier string, insecureRegistries map[string]bool) (v1.ImageIndex, error) {
105+
ref, err := parseReference(identifier, insecureRegistries)
106+
if err != nil {
107+
return nil, err
108+
}
109+
110+
return remote.Index(ref, remote.WithAuthFromKeychain(masterKeychain))
111+
}
112+
104113
// IsInsecure tests if an image is pulled from an insecure registry; default is false
105114
func IsInsecure(ref name.Reference, insecureRegistries map[string]bool) bool {
106115
return insecureRegistries[ref.Context().Registry.Name()]
@@ -125,3 +134,16 @@ func parseReference(s string, insecureRegistries map[string]bool, opts ...name.O
125134

126135
return ref, nil
127136
}
137+
138+
type digester interface {
139+
Digest() (v1.Hash, error)
140+
}
141+
142+
func digest(d digester) (string, error) {
143+
h, err := d.Digest()
144+
if err != nil {
145+
return "", fmt.Errorf("getting digest: %w", err)
146+
}
147+
148+
return h.String(), nil
149+
}

0 commit comments

Comments
 (0)