File: repository.go

package info (click to toggle)
docker.io 27.5.1%2Bdfsg4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 67,384 kB
  • sloc: sh: 5,847; makefile: 1,146; ansic: 664; python: 162; asm: 133
file content (51 lines) | stat: -rw-r--r-- 1,649 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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) {
	repoInfo, err := config.RegistryService.ResolveRepository(ref)
	if err != nil {
		return nil, errdefs.InvalidParameter(err)
	}
	// makes sure name is not empty or `scratch`
	if err := validateRepoName(repoInfo.Name); err != nil {
		return nil, errdefs.InvalidParameter(err)
	}

	endpoints, err := config.RegistryService.LookupPullEndpoints(reference.Domain(repoInfo.Name))
	if err != nil {
		return nil, err
	}

	var (
		repositories []distribution.Repository
		lastError    error
	)
	for _, endpoint := range endpoints {
		repo, err := newRepository(ctx, repoInfo, 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
}