Fetch loads all resources into the content store and returns the image
(ctx context.Context, client *containerd.Client, ref string, config *FetchConfig)
| 155 | |
| 156 | // Fetch loads all resources into the content store and returns the image |
| 157 | func 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. |
no test coverage detected
searching dependent graphs…