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

Function buildImageConfig

pkg/cmd/image/import.go:243–276  ·  view source on GitHub ↗
(diffID digest.Digest, options types.ImageImportOptions)

Source from the content-addressed store, hash-verified

241}
242
243func buildImageConfig(diffID digest.Digest, options types.ImageImportOptions) ([]byte, digest.Digest, error) {
244 ociplat := platforms.DefaultSpec()
245 if options.Platform != "" {
246 if p, err := platforms.Parse(options.Platform); err == nil {
247 ociplat = p
248 }
249 }
250
251 created := time.Now().UTC()
252 imgConfig := ocispec.Image{
253 Platform: ocispec.Platform{
254 Architecture: ociplat.Architecture,
255 OS: ociplat.OS,
256 OSVersion: ociplat.OSVersion,
257 Variant: ociplat.Variant,
258 },
259 Created: &created,
260 Config: ocispec.ImageConfig{},
261 RootFS: ocispec.RootFS{
262 Type: "layers",
263 DiffIDs: []digest.Digest{diffID},
264 },
265 History: []ocispec.History{{
266 Created: &created,
267 Comment: options.Message,
268 }},
269 }
270
271 configJSON, err := json.Marshal(imgConfig)
272 if err != nil {
273 return nil, "", err
274 }
275 return configJSON, digest.FromBytes(configJSON), nil
276}
277
278func readLayerContent(ctx context.Context, cs content.Store, layerDigest digest.Digest, size int64) ([]byte, error) {
279 ra, err := cs.ReaderAt(ctx, ocispec.Descriptor{Digest: layerDigest, Size: size})

Callers 1

Calls 3

MarshalMethod · 0.80
DefaultSpecMethod · 0.65
ParseMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…