try http for docker manifest --insecure

Signed-off-by: Tengfei Wang <tfwang@alauda.io>
This commit is contained in:
Tengfei Wang 2020-03-24 23:42:33 +08:00
parent 7d407207c3
commit 83478fe7cb
1 changed files with 17 additions and 6 deletions

View File

@ -138,16 +138,27 @@ func (c *client) GetTags(ctx context.Context, ref reference.Named) ([]string, er
} }
func (c *client) getRepositoryForReference(ctx context.Context, ref reference.Named, repoEndpoint repositoryEndpoint) (distribution.Repository, error) { func (c *client) getRepositoryForReference(ctx context.Context, ref reference.Named, repoEndpoint repositoryEndpoint) (distribution.Repository, error) {
httpTransport, err := c.getHTTPTransportForRepoEndpoint(ctx, repoEndpoint)
if err != nil {
if strings.Contains(err.Error(), "server gave HTTP response to HTTPS client") {
return nil, ErrHTTPProto{OrigErr: err.Error()}
}
}
repoName, err := reference.WithName(repoEndpoint.Name()) repoName, err := reference.WithName(repoEndpoint.Name())
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "failed to parse repo name from %s", ref) return nil, errors.Wrapf(err, "failed to parse repo name from %s", ref)
} }
httpTransport, err := c.getHTTPTransportForRepoEndpoint(ctx, repoEndpoint)
if err != nil {
if !strings.Contains(err.Error(), "server gave HTTP response to HTTPS client") {
return nil, err
}
if !repoEndpoint.endpoint.TLSConfig.InsecureSkipVerify {
return nil, ErrHTTPProto{OrigErr: err.Error()}
}
// --insecure was set; fall back to plain HTTP
if url := repoEndpoint.endpoint.URL; url != nil && url.Scheme == "https" {
url.Scheme = "http"
httpTransport, err = c.getHTTPTransportForRepoEndpoint(ctx, repoEndpoint)
if err != nil {
return nil, err
}
}
}
return distributionclient.NewRepository(repoName, repoEndpoint.BaseURL(), httpTransport) return distributionclient.NewRepository(repoName, repoEndpoint.BaseURL(), httpTransport)
} }