@@ -275,22 +275,24 @@ func (i *containerImageRef) extractRootfs(opts ExtractRootfsOptions) (io.ReadClo
275
275
}
276
276
277
277
type manifestBuilder interface {
278
+ // addLayer adds a note in the manifest about the layer. The blobs are
279
+ // identified by their possibly- compressed blob digests.
278
280
addLayer (layerBlobSum digest.Digest , layerBlobSize int64 , diffID digest.Digest )
279
281
computeLayerMIMEType (what string , layerCompression archive.Compression ) error
280
282
buildHistory (extraImageContentDiff string , extraImageContentDiffDigest digest.Digest ) error
281
283
manifestAndConfig () ([]byte , []byte , error )
282
284
}
283
285
284
286
type dockerSchema2ManifestBuilder struct {
285
- i * containerImageRef
286
- mediaType string
287
- dimage docker.V2Image
288
- dmanifest docker.V2S2Manifest
287
+ i * containerImageRef
288
+ layerMediaType string
289
+ dimage docker.V2Image
290
+ dmanifest docker.V2S2Manifest
289
291
}
290
292
291
293
// Build fresh copies of the container configuration structures so that we can edit them
292
294
// without making unintended changes to the original Builder (Docker schema 2).
293
- func newDockerSchema2ManifestBuilder (i * containerImageRef ) (manifestBuilder , error ) {
295
+ func (i * containerImageRef ) newDockerSchema2ManifestBuilder ( ) (manifestBuilder , error ) {
294
296
created := time .Now ().UTC ()
295
297
if i .created != nil {
296
298
created = * i .created
@@ -343,11 +345,11 @@ func newDockerSchema2ManifestBuilder(i *containerImageRef) (manifestBuilder, err
343
345
dimage .Config .ExposedPorts = nil
344
346
}
345
347
346
- // Build empty manifest. The Layers lists will be populated later.
348
+ // Return partial manifest. The Layers lists will be populated later.
347
349
return & dockerSchema2ManifestBuilder {
348
- i : i ,
349
- mediaType : docker .V2S2MediaTypeUncompressedLayer ,
350
- dimage : dimage ,
350
+ i : i ,
351
+ layerMediaType : docker .V2S2MediaTypeUncompressedLayer ,
352
+ dimage : dimage ,
351
353
dmanifest : docker.V2S2Manifest {
352
354
V2Versioned : docker.V2Versioned {
353
355
SchemaVersion : 2 ,
@@ -363,7 +365,7 @@ func newDockerSchema2ManifestBuilder(i *containerImageRef) (manifestBuilder, err
363
365
364
366
func (mb * dockerSchema2ManifestBuilder ) addLayer (layerBlobSum digest.Digest , layerBlobSize int64 , diffID digest.Digest ) {
365
367
dlayerDescriptor := docker.V2S2Descriptor {
366
- MediaType : mb .mediaType ,
368
+ MediaType : mb .layerMediaType ,
367
369
Digest : layerBlobSum ,
368
370
Size : layerBlobSize ,
369
371
}
@@ -397,24 +399,21 @@ func (mb *dockerSchema2ManifestBuilder) computeLayerMIMEType(what string, layerC
397
399
logrus .Debugf ("compressing %s with unknown compressor(?)" , what )
398
400
}
399
401
}
400
- mb .mediaType = dmediaType
402
+ mb .layerMediaType = dmediaType
401
403
return nil
402
404
}
403
405
404
406
func (mb * dockerSchema2ManifestBuilder ) buildHistory (extraImageContentDiff string , extraImageContentDiffDigest digest.Digest ) error {
405
- // Build history notes in the image configurations .
407
+ // Build history notes in the image configuration .
406
408
appendHistory := func (history []v1.History , empty bool ) {
407
409
for i := range history {
408
- var created * time.Time
410
+ var created time.Time
409
411
if history [i ].Created != nil {
410
412
copiedTimestamp := * history [i ].Created
411
- created = & copiedTimestamp
412
- }
413
- if created == nil {
414
- created = & time.Time {}
413
+ created = copiedTimestamp
415
414
}
416
415
dnews := docker.V2S2History {
417
- Created : * created ,
416
+ Created : created ,
418
417
CreatedBy : history [i ].CreatedBy ,
419
418
Author : history [i ].Author ,
420
419
Comment : history [i ].Comment ,
@@ -513,15 +512,15 @@ func (mb *dockerSchema2ManifestBuilder) manifestAndConfig() ([]byte, []byte, err
513
512
}
514
513
515
514
type ociManifestBuilder struct {
516
- i * containerImageRef
517
- mediaType string
518
- oimage v1.Image
519
- omanifest v1.Manifest
515
+ i * containerImageRef
516
+ layerMediaType string
517
+ oimage v1.Image
518
+ omanifest v1.Manifest
520
519
}
521
520
522
521
// Build fresh copies of the container configuration structures so that we can edit them
523
522
// without making unintended changes to the original Builder (OCI manifest).
524
- func newOCIManifestBuilder (i * containerImageRef ) (manifestBuilder , error ) {
523
+ func (i * containerImageRef ) newOCIManifestBuilder ( ) (manifestBuilder , error ) {
525
524
created := time .Now ().UTC ()
526
525
if i .created != nil {
527
526
created = * i .created
@@ -560,12 +559,12 @@ func newOCIManifestBuilder(i *containerImageRef) (manifestBuilder, error) {
560
559
oimage .Config .ExposedPorts = nil
561
560
}
562
561
563
- // Build empty manifest. The Layers lists will be populated later.
562
+ // Return partial manifest. The Layers lists will be populated later.
564
563
return & ociManifestBuilder {
565
564
i : i ,
566
565
// The default layer media type assumes no compression.
567
- mediaType : v1 .MediaTypeImageLayer ,
568
- oimage : oimage ,
566
+ layerMediaType : v1 .MediaTypeImageLayer ,
567
+ oimage : oimage ,
569
568
omanifest : v1.Manifest {
570
569
Versioned : specs.Versioned {
571
570
SchemaVersion : 2 ,
@@ -582,7 +581,7 @@ func newOCIManifestBuilder(i *containerImageRef) (manifestBuilder, error) {
582
581
583
582
func (mb * ociManifestBuilder ) addLayer (layerBlobSum digest.Digest , layerBlobSize int64 , diffID digest.Digest ) {
584
583
olayerDescriptor := v1.Descriptor {
585
- MediaType : mb .mediaType ,
584
+ MediaType : mb .layerMediaType ,
586
585
Digest : layerBlobSum ,
587
586
Size : layerBlobSize ,
588
587
}
@@ -616,12 +615,12 @@ func (mb *ociManifestBuilder) computeLayerMIMEType(what string, layerCompression
616
615
logrus .Debugf ("compressing %s with unknown compressor(?)" , what )
617
616
}
618
617
}
619
- mb .mediaType = omediaType
618
+ mb .layerMediaType = omediaType
620
619
return nil
621
620
}
622
621
623
622
func (mb * ociManifestBuilder ) buildHistory (extraImageContentDiff string , extraImageContentDiffDigest digest.Digest ) error {
624
- // Build history notes in the image configurations .
623
+ // Build history notes in the image configuration .
625
624
appendHistory := func (history []v1.History , empty bool ) {
626
625
for i := range history {
627
626
var created * time.Time
@@ -808,12 +807,12 @@ func (i *containerImageRef) NewImageSource(_ context.Context, _ *types.SystemCon
808
807
var mb manifestBuilder
809
808
switch i .preferredManifestType {
810
809
case v1 .MediaTypeImageManifest :
811
- mb , err = newOCIManifestBuilder (i )
810
+ mb , err = i . newOCIManifestBuilder ()
812
811
if err != nil {
813
812
return nil , err
814
813
}
815
814
case manifest .DockerV2Schema2MediaType :
816
- mb , err = newDockerSchema2ManifestBuilder (i )
815
+ mb , err = i . newDockerSchema2ManifestBuilder ()
817
816
if err != nil {
818
817
return nil , err
819
818
}
@@ -1025,8 +1024,6 @@ func (i *containerImageRef) NewImageSource(_ context.Context, _ *types.SystemCon
1025
1024
if err = os .Rename (filepath .Join (path , "layer" ), finalBlobName ); err != nil {
1026
1025
return nil , fmt .Errorf ("storing %s to file while renaming %q to %q: %w" , what , filepath .Join (path , "layer" ), finalBlobName , err )
1027
1026
}
1028
- // Add a note in the manifest about the layer. The blobs are identified by their possibly-
1029
- // compressed blob digests.
1030
1027
mb .addLayer (destHasher .Digest (), size , srcHasher .Digest ())
1031
1028
}
1032
1029
0 commit comments