MCPcopy Index your code
hub / github.com/containerd/containerd / Fetch

Function Fetch

cmd/ctr/commands/content/fetch.go:157–209  ·  view source on GitHub ↗

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

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

Source from the content-addressed store, hash-verified

155
156// Fetch loads all resources into the content store and returns the image
157func Fetch(ctx context.Context, client *containerd.Client, ref string, config *FetchConfig) (images.Image, error) {
158 ongoing := NewJobs(ref)
159
160 if config.TraceHTTP {
161 ctx = httpdbg.WithClientTrace(ctx)
162 }
163
164 pctx, stopProgress := context.WithCancel(ctx)
165 progress := make(chan struct{})
166
167 go func() {
168 if config.ProgressOutput != nil {
169 // no progress bar, because it hides some debug logs
170 ShowProgress(pctx, ongoing, client.ContentStore(), config.ProgressOutput)
171 }
172 close(progress)
173 }()
174
175 h := images.HandlerFunc(func(ctx context.Context, desc ocispec.Descriptor) ([]ocispec.Descriptor, error) {
176 ongoing.Add(desc)
177 return nil, nil
178 })
179
180 log.G(pctx).WithField("image", ref).Debug("fetching")
181 labels := commands.LabelArgs(config.Labels)
182 opts := []containerd.RemoteOpt{
183 containerd.WithPullLabels(labels),
184 containerd.WithResolver(config.Resolver),
185 containerd.WithImageHandler(h),
186 }
187 opts = append(opts, config.RemoteOpts...)
188
189 if config.AllMetadata {
190 opts = append(opts, containerd.WithAllMetadata())
191 }
192
193 if config.PlatformMatcher != nil {
194 opts = append(opts, containerd.WithPlatformMatcher(config.PlatformMatcher))
195 } else {
196 for _, platform := range config.Platforms {
197 opts = append(opts, containerd.WithPlatform(platform))
198 }
199 }
200
201 img, err := client.Fetch(pctx, ref, opts...)
202 stopProgress()
203 if err != nil {
204 return images.Image{}, err
205 }
206
207 <-progress
208 return img, nil
209}
210
211// ShowProgress continuously updates the output with job progress
212// by checking status in the content store.

Callers 2

pull.goFile · 0.92
fetch.goFile · 0.70

Calls 8

AddMethod · 0.95
WithClientTraceFunction · 0.92
HandlerFuncFuncType · 0.92
LabelArgsFunction · 0.92
NewJobsFunction · 0.85
ShowProgressFunction · 0.85
ContentStoreMethod · 0.65
FetchMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…