@@ -50,17 +50,17 @@ func AddRemoteTag(src, target string, insecureRegistries map[string]bool) error
50
50
}
51
51
52
52
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 )
56
56
}
57
57
58
- h , err := img . Digest ( )
58
+ img , err := remoteImage ( identifier , insecureRegistries )
59
59
if err != nil {
60
- return "" , fmt .Errorf ("getting digest : %w" , err )
60
+ return "" , fmt .Errorf ("getting image : %w" , err )
61
61
}
62
62
63
- return h . String (), nil
63
+ return digest ( img )
64
64
}
65
65
66
66
// RetrieveRemoteConfig retrieves the remote config file for an image
@@ -101,6 +101,15 @@ func remoteImage(identifier string, insecureRegistries map[string]bool) (v1.Imag
101
101
return getRemoteImageImpl (ref )
102
102
}
103
103
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
+
104
113
// IsInsecure tests if an image is pulled from an insecure registry; default is false
105
114
func IsInsecure (ref name.Reference , insecureRegistries map [string ]bool ) bool {
106
115
return insecureRegistries [ref .Context ().Registry .Name ()]
@@ -125,3 +134,16 @@ func parseReference(s string, insecureRegistries map[string]bool, opts ...name.O
125
134
126
135
return ref , nil
127
136
}
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