bugfix: add default host config if not set

If there is not specific host config, like ctr does, the resolver will
fail to get host path. And this patch is to add default host config if
needs.

And default config host config should have all caps for pull and push.

Signed-off-by: Wei Fu <fuweid89@gmail.com>
This commit is contained in:
Wei Fu 2020-04-04 14:09:35 +08:00 committed by Derek McGowan
parent fe7bfffbf4
commit d9a1c3f9e4
No known key found for this signature in database
GPG Key ID: F58C5D0A4405ACDB

View File

@ -88,11 +88,10 @@ func ConfigureHosts(ctx context.Context, options HostOptions) docker.RegistryHos
if hosts == nil { if hosts == nil {
hosts = make([]hostConfig, 1) hosts = make([]hostConfig, 1)
} }
if len(hosts) > 1 { if len(hosts) >= 1 && hosts[len(hosts)-1].host == "" {
if hosts[len(hosts)-1].host == "" {
if host == "docker.io" { if host == "docker.io" {
hosts[len(hosts)-1].scheme = "https" hosts[len(hosts)-1].scheme = "https"
hosts[len(hosts)-1].host = "https://registry-1.docker.io" hosts[len(hosts)-1].host = "registry-1.docker.io"
} else { } else {
hosts[len(hosts)-1].host = host hosts[len(hosts)-1].host = host
if options.DefaultScheme != "" { if options.DefaultScheme != "" {
@ -102,7 +101,7 @@ func ConfigureHosts(ctx context.Context, options HostOptions) docker.RegistryHos
} }
} }
hosts[len(hosts)-1].path = "/v2" hosts[len(hosts)-1].path = "/v2"
} hosts[len(hosts)-1].capabilities = docker.HostCapabilityPull | docker.HostCapabilityResolve | docker.HostCapabilityPush
} }
defaultTransport := &http.Transport{ defaultTransport := &http.Transport{