(ctx context.Context, rCtx *RemoteContext, ref string, limit int)
| 190 | } |
| 191 | |
| 192 | func (c *Client) fetch(ctx context.Context, rCtx *RemoteContext, ref string, limit int) (images.Image, error) { |
| 193 | ctx, span := tracing.StartSpan(ctx, tracing.Name(pullSpanPrefix, "fetch")) |
| 194 | defer span.End() |
| 195 | store := c.ContentStore() |
| 196 | name, desc, err := rCtx.Resolver.Resolve(ctx, ref) |
| 197 | if err != nil { |
| 198 | return images.Image{}, fmt.Errorf("failed to resolve reference %q: %w", ref, err) |
| 199 | } |
| 200 | |
| 201 | fetcher, err := rCtx.Resolver.Fetcher(ctx, name) |
| 202 | if err != nil { |
| 203 | return images.Image{}, fmt.Errorf("failed to get fetcher for %q: %w", name, err) |
| 204 | } |
| 205 | |
| 206 | var ( |
| 207 | handler images.Handler |
| 208 | |
| 209 | isConvertible bool |
| 210 | converterFunc func(context.Context, ocispec.Descriptor) (ocispec.Descriptor, error) |
| 211 | limiter *semaphore.Weighted |
| 212 | ) |
| 213 | if desc.MediaType == images.MediaTypeDockerSchema1Manifest { |
| 214 | return images.Image{}, fmt.Errorf("%w: media type %q is no longer supported since containerd v2.1, please rebuild the image as %q or %q", |
| 215 | errdefs.ErrNotImplemented, |
| 216 | images.MediaTypeDockerSchema1Manifest, images.MediaTypeDockerSchema2Manifest, ocispec.MediaTypeImageManifest) |
| 217 | } |
| 218 | // Get all the children for a descriptor |
| 219 | childrenHandler := images.ChildrenHandler(store) |
| 220 | if rCtx.ReferrersProvider != nil { |
| 221 | childrenHandler = images.SetReferrers(rCtx.ReferrersProvider, childrenHandler) |
| 222 | } |
| 223 | // Set any children labels for that content |
| 224 | childrenHandler = images.SetChildrenMappedLabels(store, childrenHandler, rCtx.ChildLabelMap) |
| 225 | if rCtx.AllMetadata { |
| 226 | // Filter manifests by platforms but allow to handle manifest |
| 227 | // and configuration for not-target platforms |
| 228 | childrenHandler = remotes.FilterManifestByPlatformHandler(childrenHandler, rCtx.PlatformMatcher) |
| 229 | } else { |
| 230 | // Filter children by platforms if specified. |
| 231 | childrenHandler = images.FilterPlatforms(childrenHandler, rCtx.PlatformMatcher) |
| 232 | } |
| 233 | // Sort and limit manifests if a finite number is needed |
| 234 | if limit > 0 { |
| 235 | childrenHandler = images.LimitManifests(childrenHandler, rCtx.PlatformMatcher, limit) |
| 236 | } |
| 237 | |
| 238 | // set isConvertible to true if there is application/octet-stream media type |
| 239 | convertibleHandler := images.HandlerFunc( |
| 240 | func(_ context.Context, desc ocispec.Descriptor) ([]ocispec.Descriptor, error) { |
| 241 | if desc.MediaType == docker.LegacyConfigMediaType { |
| 242 | isConvertible = true |
| 243 | } |
| 244 | |
| 245 | return []ocispec.Descriptor{}, nil |
| 246 | }, |
| 247 | ) |
| 248 | |
| 249 | appendDistSrcLabelHandler, err := docker.AppendDistributionSourceLabel(store, ref) |
no test coverage detected