MCPcopy Create free account
hub / github.com/containerd/nerdctl / Pull

Function Pull

pkg/imgutil/pull/pull.go:52–102  ·  view source on GitHub ↗

Pull loads all resources into the content store and returns the image

(ctx context.Context, client *containerd.Client, ref string, config *Config)

Source from the content-addressed store, hash-verified

50
51// Pull loads all resources into the content store and returns the image
52func Pull(ctx context.Context, client *containerd.Client, ref string, config *Config) (containerd.Image, error) {
53 ongoing := jobs.New(ref)
54
55 pctx, stopProgress := context.WithCancel(ctx)
56 progress := make(chan struct{})
57
58 go func() {
59 if config.ProgressOutput != nil {
60 // no progress bar, because it hides some debug logs
61 jobs.ShowProgress(pctx, ongoing, client.ContentStore(), config.ProgressOutput)
62 }
63 close(progress)
64 }()
65
66 h := images.HandlerFunc(func(ctx context.Context, desc ocispec.Descriptor) ([]ocispec.Descriptor, error) {
67 if desc.MediaType != images.MediaTypeDockerSchema1Manifest {
68 ongoing.Add(desc)
69 }
70 return nil, nil
71 })
72
73 log.G(pctx).WithField("image", ref).Debug("fetching")
74 platformMC := platformutil.NewMatchComparerFromOCISpecPlatformSlice(config.Platforms)
75 opts := []containerd.RemoteOpt{
76 containerd.WithResolver(config.Resolver),
77 containerd.WithImageHandler(h),
78 containerd.WithPlatformMatcher(platformMC),
79 }
80 opts = append(opts, config.RemoteOpts...)
81
82 var (
83 img containerd.Image
84 err error
85 )
86 if len(config.Platforms) == 1 {
87 // client.Pull is for single-platform (w/ unpacking)
88 img, err = client.Pull(pctx, ref, opts...)
89 } else {
90 // client.Fetch is for multi-platform (w/o unpacking)
91 var imagesImg images.Image
92 imagesImg, err = client.Fetch(pctx, ref, opts...)
93 img = containerd.NewImageWithPlatform(client, imagesImg, platformMC)
94 }
95 stopProgress()
96 if err != nil {
97 return nil, err
98 }
99
100 <-progress
101 return img, nil
102}

Callers 1

PullImageFunction · 0.92

Calls 6

NewFunction · 0.92
ShowProgressFunction · 0.92
AddMethod · 0.80
PullMethod · 0.80
FetchMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…