@@ -15,21 +15,23 @@ import (
15
15
"github.com/moby/buildkit/util/estargz"
16
16
"github.com/moby/buildkit/util/push"
17
17
"github.com/moby/buildkit/util/resolver"
18
+ resolverconfig "github.com/moby/buildkit/util/resolver/config"
18
19
"github.com/moby/buildkit/util/resolver/limited"
19
20
digest "github.com/opencontainers/go-digest"
20
21
ocispecs "github.com/opencontainers/image-spec/specs-go/v1"
21
22
"github.com/pkg/errors"
22
23
)
23
24
24
- func canonicalizeRef (rawRef string ) (string , error ) {
25
+ func canonicalizeRef (rawRef string ) (reference. Named , error ) {
25
26
if rawRef == "" {
26
- return "" , errors .New ("missing ref" )
27
+ return nil , errors .New ("missing ref" )
27
28
}
28
29
parsed , err := reference .ParseNormalizedNamed (rawRef )
29
30
if err != nil {
30
- return "" , err
31
+ return nil , err
31
32
}
32
- return reference .TagNameOnly (parsed ).String (), nil
33
+ parsed = reference .TagNameOnly (parsed )
34
+ return parsed , nil
33
35
}
34
36
35
37
const (
@@ -38,6 +40,7 @@ const (
38
40
attrLayerCompression = "compression"
39
41
attrForceCompression = "force-compression"
40
42
attrCompressionLevel = "compression-level"
43
+ attrInsecure = "registry.insecure"
41
44
)
42
45
43
46
func ResolveCacheExporterFunc (sm * session.Manager , hosts docker.RegistryHosts ) remotecache.ResolveCacheExporterFunc {
@@ -50,6 +53,7 @@ func ResolveCacheExporterFunc(sm *session.Manager, hosts docker.RegistryHosts) r
50
53
if err != nil {
51
54
return nil , err
52
55
}
56
+ refString := ref .String ()
53
57
ociMediatypes := true
54
58
if v , ok := attrs [attrOCIMediatypes ]; ok {
55
59
b , err := strconv .ParseBool (v )
@@ -58,12 +62,22 @@ func ResolveCacheExporterFunc(sm *session.Manager, hosts docker.RegistryHosts) r
58
62
}
59
63
ociMediatypes = b
60
64
}
61
- remote := resolver .DefaultPool .GetResolver (hosts , ref , "push" , sm , g )
62
- pusher , err := push .Pusher (ctx , remote , ref )
65
+ insecure := false
66
+ if v , ok := attrs [attrInsecure ]; ok {
67
+ b , err := strconv .ParseBool (v )
68
+ if err != nil {
69
+ return nil , errors .Wrapf (err , "failed to parse %s" , attrInsecure )
70
+ }
71
+ insecure = b
72
+ }
73
+
74
+ scope , hosts := registryConfig (hosts , ref , "push" , insecure )
75
+ remote := resolver .DefaultPool .GetResolver (hosts , refString , scope , sm , g )
76
+ pusher , err := push .Pusher (ctx , remote , refString )
63
77
if err != nil {
64
78
return nil , err
65
79
}
66
- return remotecache .NewExporter (contentutil .FromPusher (pusher ), ref , ociMediatypes , * compressionConfig ), nil
80
+ return remotecache .NewExporter (contentutil .FromPusher (pusher ), refString , ociMediatypes , * compressionConfig ), nil
67
81
}
68
82
}
69
83
@@ -73,8 +87,19 @@ func ResolveCacheImporterFunc(sm *session.Manager, cs content.Store, hosts docke
73
87
if err != nil {
74
88
return nil , ocispecs.Descriptor {}, err
75
89
}
76
- remote := resolver .DefaultPool .GetResolver (hosts , ref , "pull" , sm , g )
77
- xref , desc , err := remote .Resolve (ctx , ref )
90
+ refString := ref .String ()
91
+ insecure := false
92
+ if v , ok := attrs [attrInsecure ]; ok {
93
+ b , err := strconv .ParseBool (v )
94
+ if err != nil {
95
+ return nil , ocispecs.Descriptor {}, errors .Wrapf (err , "failed to parse %s" , attrInsecure )
96
+ }
97
+ insecure = b
98
+ }
99
+
100
+ scope , hosts := registryConfig (hosts , ref , "pull" , insecure )
101
+ remote := resolver .DefaultPool .GetResolver (hosts , refString , scope , sm , g )
102
+ xref , desc , err := remote .Resolve (ctx , refString )
78
103
if err != nil {
79
104
return nil , ocispecs.Descriptor {}, err
80
105
}
@@ -83,8 +108,8 @@ func ResolveCacheImporterFunc(sm *session.Manager, cs content.Store, hosts docke
83
108
return nil , ocispecs.Descriptor {}, err
84
109
}
85
110
src := & withDistributionSourceLabel {
86
- Provider : contentutil .FromFetcher (limited .Default .WrapFetcher (fetcher , ref )),
87
- ref : ref ,
111
+ Provider : contentutil .FromFetcher (limited .Default .WrapFetcher (fetcher , refString )),
112
+ ref : refString ,
88
113
source : cs ,
89
114
}
90
115
return remotecache .NewImporter (src ), desc , nil
@@ -164,3 +189,18 @@ func attrsToCompression(attrs map[string]string) (*compression.Config, error) {
164
189
}
165
190
return & compressionConfig , nil
166
191
}
192
+
193
+ func registryConfig (hosts docker.RegistryHosts , ref reference.Named , scope string , insecure bool ) (string , docker.RegistryHosts ) {
194
+ if insecure {
195
+ insecureTrue := true
196
+ httpTrue := true
197
+ hosts = resolver .NewRegistryConfig (map [string ]resolverconfig.RegistryConfig {
198
+ reference .Domain (ref ): {
199
+ Insecure : & insecureTrue ,
200
+ PlainHTTP : & httpTrue ,
201
+ },
202
+ })
203
+ scope += ":insecure"
204
+ }
205
+ return scope , hosts
206
+ }
0 commit comments