MCPcopy
hub / github.com/containerd/containerd / Resolve

Method Resolve

core/remotes/docker/resolver.go:236–445  ·  view source on GitHub ↗
(ctx context.Context, ref string)

Source from the content-addressed store, hash-verified

234var _ remotes.ResolverWithOptions = &dockerResolver{}
235
236func (r *dockerResolver) Resolve(ctx context.Context, ref string) (string, ocispec.Descriptor, error) {
237 base, err := r.resolveDockerBase(ref)
238 if err != nil {
239 return "", ocispec.Descriptor{}, err
240 }
241 refspec := base.refspec
242 if refspec.Object == "" {
243 return "", ocispec.Descriptor{}, reference.ErrObjectRequired
244 }
245
246 var (
247 paths [][]string
248 dgst = refspec.Digest()
249 caps = HostCapabilityPull
250 )
251
252 if dgst != "" {
253 if err := dgst.Validate(); err != nil {
254 // need to fail here, since we can't actually resolve the invalid
255 // digest.
256 return "", ocispec.Descriptor{}, err
257 }
258
259 // turns out, we have a valid digest, make a url.
260 paths = append(paths, []string{"manifests", dgst.String()})
261
262 // fallback to blobs on not found.
263 paths = append(paths, []string{"blobs", dgst.String()})
264 } else {
265 // Add
266 paths = append(paths, []string{"manifests", refspec.Object})
267 caps |= HostCapabilityResolve
268 }
269
270 hosts := base.filterHosts(caps)
271 if len(hosts) == 0 {
272 return "", ocispec.Descriptor{}, fmt.Errorf("no resolve hosts: %w", errdefs.ErrNotFound)
273 }
274
275 ctx, err = ContextWithRepositoryScope(ctx, refspec, false)
276 if err != nil {
277 return "", ocispec.Descriptor{}, err
278 }
279
280 var (
281 // firstErr is the most relevant error encountered during resolution.
282 // We use this to determine the error to return, making sure that the
283 // error created furthest through the resolution process is returned.
284 firstErr error
285 firstErrPriority int
286 )
287
288 nextHostOrFail := func(i int) string {
289 if i < len(hosts)-1 {
290 return "trying next host"
291 }
292 return "fetch failed"
293 }

Callers

nothing calls this directly

Calls 15

resolveDockerBaseMethod · 0.95
unexpectedResponseErrFunction · 0.85
getManifestMediaTypeFunction · 0.85
filterHostsMethod · 0.80
requestMethod · 0.80
addNamespaceMethod · 0.80
sanitizedURLMethod · 0.80
doWithRetriesMethod · 0.80
CopyMethod · 0.80
DigestMethod · 0.65
HostnameMethod · 0.65

Tested by

no test coverage detected