MCPcopy
hub / github.com/containerd/containerd / Pull

Method Pull

client/pull.go:43–190  ·  view source on GitHub ↗

Pull downloads the provided content into containerd's content store and returns a platform specific image object

(ctx context.Context, ref string, opts ...RemoteOpt)

Source from the content-addressed store, hash-verified

41// Pull downloads the provided content into containerd's content store
42// and returns a platform specific image object
43func (c *Client) Pull(ctx context.Context, ref string, opts ...RemoteOpt) (_ Image, retErr error) {
44 ctx, span := tracing.StartSpan(ctx, tracing.Name(pullSpanPrefix, "Pull"))
45 defer span.End()
46
47 pullCtx := defaultRemoteContext()
48
49 for _, o := range opts {
50 if err := o(c, pullCtx); err != nil {
51 return nil, err
52 }
53 }
54
55 if resolver, ok := pullCtx.Resolver.(remotes.ResolverWithOptions); ok {
56 resolver.SetOptions(
57 transfer.WithConcurrentLayerFetchBuffer(pullCtx.ConcurrentLayerFetchBuffer),
58 transfer.WithMaxConcurrentDownloads(pullCtx.MaxConcurrentDownloads),
59 transfer.WithDownloadLimiter(pullCtx.DownloadLimiter),
60 )
61 }
62
63 if pullCtx.PlatformMatcher == nil {
64 if len(pullCtx.Platforms) > 1 {
65 return nil, errors.New("cannot pull multiplatform image locally, try Fetch")
66 } else if len(pullCtx.Platforms) == 0 {
67 pullCtx.PlatformMatcher = c.platform
68 } else {
69 p, err := platforms.Parse(pullCtx.Platforms[0])
70 if err != nil {
71 return nil, fmt.Errorf("invalid platform %s: %w", pullCtx.Platforms[0], err)
72 }
73
74 pullCtx.PlatformMatcher = platforms.Only(p)
75 }
76 }
77
78 span.SetAttributes(
79 tracing.Attribute("image.ref", ref),
80 tracing.Attribute("unpack", pullCtx.Unpack),
81 tracing.Attribute("max.concurrent.downloads", pullCtx.MaxConcurrentDownloads),
82 tracing.Attribute("concurrent.layer.fetch.buffer", pullCtx.ConcurrentLayerFetchBuffer),
83 tracing.Attribute("platforms.count", len(pullCtx.Platforms)),
84 )
85
86 ctx, done, err := c.WithLease(ctx)
87 if err != nil {
88 return nil, err
89 }
90 defer done(ctx)
91
92 var unpacker *unpack.Unpacker
93
94 if pullCtx.Unpack {
95 snapshotterName, err := c.resolveSnapshotterName(ctx, pullCtx.Snapshotter)
96 if err != nil {
97 return nil, fmt.Errorf("unable to resolve snapshotter: %w", err)
98 }
99 span.SetAttributes(tracing.Attribute("snapshotter.name", snapshotterName))
100

Callers

nothing calls this directly

Calls 15

WithLeaseMethod · 0.95
SnapshotServiceMethod · 0.95
DiffServiceMethod · 0.95
ContentStoreMethod · 0.95
WaitMethod · 0.95
UnpackMethod · 0.95
fetchMethod · 0.95
createNewImageMethod · 0.95
StartSpanFunction · 0.92
NameFunction · 0.92

Tested by

no test coverage detected