Skip to content

Commit 8008e9c

Browse files
committed
Review feedback
Signed-off-by: Aaron Lehmann <[email protected]>
1 parent 4807e62 commit 8008e9c

File tree

1 file changed

+30
-33
lines changed

1 file changed

+30
-33
lines changed

image.go

+30-33
Original file line numberDiff line numberDiff line change
@@ -275,22 +275,24 @@ func (i *containerImageRef) extractRootfs(opts ExtractRootfsOptions) (io.ReadClo
275275
}
276276

277277
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.
278280
addLayer(layerBlobSum digest.Digest, layerBlobSize int64, diffID digest.Digest)
279281
computeLayerMIMEType(what string, layerCompression archive.Compression) error
280282
buildHistory(extraImageContentDiff string, extraImageContentDiffDigest digest.Digest) error
281283
manifestAndConfig() ([]byte, []byte, error)
282284
}
283285

284286
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
289291
}
290292

291293
// Build fresh copies of the container configuration structures so that we can edit them
292294
// 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) {
294296
created := time.Now().UTC()
295297
if i.created != nil {
296298
created = *i.created
@@ -343,11 +345,11 @@ func newDockerSchema2ManifestBuilder(i *containerImageRef) (manifestBuilder, err
343345
dimage.Config.ExposedPorts = nil
344346
}
345347

346-
// Build empty manifest. The Layers lists will be populated later.
348+
// Return partial manifest. The Layers lists will be populated later.
347349
return &dockerSchema2ManifestBuilder{
348-
i: i,
349-
mediaType: docker.V2S2MediaTypeUncompressedLayer,
350-
dimage: dimage,
350+
i: i,
351+
layerMediaType: docker.V2S2MediaTypeUncompressedLayer,
352+
dimage: dimage,
351353
dmanifest: docker.V2S2Manifest{
352354
V2Versioned: docker.V2Versioned{
353355
SchemaVersion: 2,
@@ -363,7 +365,7 @@ func newDockerSchema2ManifestBuilder(i *containerImageRef) (manifestBuilder, err
363365

364366
func (mb *dockerSchema2ManifestBuilder) addLayer(layerBlobSum digest.Digest, layerBlobSize int64, diffID digest.Digest) {
365367
dlayerDescriptor := docker.V2S2Descriptor{
366-
MediaType: mb.mediaType,
368+
MediaType: mb.layerMediaType,
367369
Digest: layerBlobSum,
368370
Size: layerBlobSize,
369371
}
@@ -397,24 +399,21 @@ func (mb *dockerSchema2ManifestBuilder) computeLayerMIMEType(what string, layerC
397399
logrus.Debugf("compressing %s with unknown compressor(?)", what)
398400
}
399401
}
400-
mb.mediaType = dmediaType
402+
mb.layerMediaType = dmediaType
401403
return nil
402404
}
403405

404406
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.
406408
appendHistory := func(history []v1.History, empty bool) {
407409
for i := range history {
408-
var created *time.Time
410+
var created time.Time
409411
if history[i].Created != nil {
410412
copiedTimestamp := *history[i].Created
411-
created = &copiedTimestamp
412-
}
413-
if created == nil {
414-
created = &time.Time{}
413+
created = copiedTimestamp
415414
}
416415
dnews := docker.V2S2History{
417-
Created: *created,
416+
Created: created,
418417
CreatedBy: history[i].CreatedBy,
419418
Author: history[i].Author,
420419
Comment: history[i].Comment,
@@ -513,15 +512,15 @@ func (mb *dockerSchema2ManifestBuilder) manifestAndConfig() ([]byte, []byte, err
513512
}
514513

515514
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
520519
}
521520

522521
// Build fresh copies of the container configuration structures so that we can edit them
523522
// without making unintended changes to the original Builder (OCI manifest).
524-
func newOCIManifestBuilder(i *containerImageRef) (manifestBuilder, error) {
523+
func (i *containerImageRef) newOCIManifestBuilder() (manifestBuilder, error) {
525524
created := time.Now().UTC()
526525
if i.created != nil {
527526
created = *i.created
@@ -560,12 +559,12 @@ func newOCIManifestBuilder(i *containerImageRef) (manifestBuilder, error) {
560559
oimage.Config.ExposedPorts = nil
561560
}
562561

563-
// Build empty manifest. The Layers lists will be populated later.
562+
// Return partial manifest. The Layers lists will be populated later.
564563
return &ociManifestBuilder{
565564
i: i,
566565
// The default layer media type assumes no compression.
567-
mediaType: v1.MediaTypeImageLayer,
568-
oimage: oimage,
566+
layerMediaType: v1.MediaTypeImageLayer,
567+
oimage: oimage,
569568
omanifest: v1.Manifest{
570569
Versioned: specs.Versioned{
571570
SchemaVersion: 2,
@@ -582,7 +581,7 @@ func newOCIManifestBuilder(i *containerImageRef) (manifestBuilder, error) {
582581

583582
func (mb *ociManifestBuilder) addLayer(layerBlobSum digest.Digest, layerBlobSize int64, diffID digest.Digest) {
584583
olayerDescriptor := v1.Descriptor{
585-
MediaType: mb.mediaType,
584+
MediaType: mb.layerMediaType,
586585
Digest: layerBlobSum,
587586
Size: layerBlobSize,
588587
}
@@ -616,12 +615,12 @@ func (mb *ociManifestBuilder) computeLayerMIMEType(what string, layerCompression
616615
logrus.Debugf("compressing %s with unknown compressor(?)", what)
617616
}
618617
}
619-
mb.mediaType = omediaType
618+
mb.layerMediaType = omediaType
620619
return nil
621620
}
622621

623622
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.
625624
appendHistory := func(history []v1.History, empty bool) {
626625
for i := range history {
627626
var created *time.Time
@@ -808,12 +807,12 @@ func (i *containerImageRef) NewImageSource(_ context.Context, _ *types.SystemCon
808807
var mb manifestBuilder
809808
switch i.preferredManifestType {
810809
case v1.MediaTypeImageManifest:
811-
mb, err = newOCIManifestBuilder(i)
810+
mb, err = i.newOCIManifestBuilder()
812811
if err != nil {
813812
return nil, err
814813
}
815814
case manifest.DockerV2Schema2MediaType:
816-
mb, err = newDockerSchema2ManifestBuilder(i)
815+
mb, err = i.newDockerSchema2ManifestBuilder()
817816
if err != nil {
818817
return nil, err
819818
}
@@ -1025,8 +1024,6 @@ func (i *containerImageRef) NewImageSource(_ context.Context, _ *types.SystemCon
10251024
if err = os.Rename(filepath.Join(path, "layer"), finalBlobName); err != nil {
10261025
return nil, fmt.Errorf("storing %s to file while renaming %q to %q: %w", what, filepath.Join(path, "layer"), finalBlobName, err)
10271026
}
1028-
// Add a note in the manifest about the layer. The blobs are identified by their possibly-
1029-
// compressed blob digests.
10301027
mb.addLayer(destHasher.Digest(), size, srcHasher.Digest())
10311028
}
10321029

0 commit comments

Comments
 (0)