mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
[Service.ResolveRepository] is a shallow wrapper around [newRepositoryInfo], from which we only consume the `Name` field. That field is a direct result of `reference.TrimNamed`, so we can replace this with that. [Service.ResolveRepository]:ecb03c4cda/registry/service.go (L106-L111)[newRepositoryInfo]:ecb03c4cda/registry/config.go (L392-L408)Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
49 lines
1.5 KiB
Go
49 lines
1.5 KiB
Go
package distribution
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/containerd/log"
|
|
"github.com/distribution/reference"
|
|
"github.com/docker/distribution"
|
|
"github.com/docker/docker/errdefs"
|
|
)
|
|
|
|
// GetRepositories returns a list of repositories configured for the given
|
|
// reference. Multiple repositories can be returned if the reference is for
|
|
// the default (Docker Hub) registry and a mirror is configured, but it omits
|
|
// registries that were not reachable (pinging the /v2/ endpoint failed).
|
|
//
|
|
// It returns an error if it was unable to reach any of the registries for
|
|
// the given reference, or if the provided reference is invalid.
|
|
func GetRepositories(ctx context.Context, ref reference.Named, config *ImagePullConfig) ([]distribution.Repository, error) {
|
|
repoName := reference.TrimNamed(ref)
|
|
// makes sure name is not empty or `scratch`
|
|
if err := validateRepoName(repoName); err != nil {
|
|
return nil, errdefs.InvalidParameter(err)
|
|
}
|
|
|
|
endpoints, err := config.RegistryService.LookupPullEndpoints(reference.Domain(repoName))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
var (
|
|
repositories []distribution.Repository
|
|
lastError error
|
|
)
|
|
for _, endpoint := range endpoints {
|
|
repo, err := newRepository(ctx, repoName, endpoint, nil, config.AuthConfig, "pull")
|
|
if err != nil {
|
|
log.G(ctx).WithFields(log.Fields{"endpoint": endpoint.URL.String(), "error": err}).Info("endpoint")
|
|
lastError = err
|
|
continue
|
|
}
|
|
repositories = append(repositories, repo)
|
|
}
|
|
if len(repositories) == 0 {
|
|
return nil, lastError
|
|
}
|
|
return repositories, nil
|
|
}
|