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

View File

@@ -88,21 +88,20 @@ func ConfigureHosts(ctx context.Context, options HostOptions) docker.RegistryHos
if hosts == nil {
hosts = make([]hostConfig, 1)
}
if len(hosts) > 1 {
if hosts[len(hosts)-1].host == "" {
if host == "docker.io" {
hosts[len(hosts)-1].scheme = "https"
hosts[len(hosts)-1].host = "https://registry-1.docker.io"
if len(hosts) >= 1 && hosts[len(hosts)-1].host == "" {
if host == "docker.io" {
hosts[len(hosts)-1].scheme = "https"
hosts[len(hosts)-1].host = "registry-1.docker.io"
} else {
hosts[len(hosts)-1].host = host
if options.DefaultScheme != "" {
hosts[len(hosts)-1].scheme = options.DefaultScheme
} else {
hosts[len(hosts)-1].host = host
if options.DefaultScheme != "" {
hosts[len(hosts)-1].scheme = options.DefaultScheme
} else {
hosts[len(hosts)-1].scheme = "https"
}
hosts[len(hosts)-1].scheme = "https"
}
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{