From a89f482dcb3428c0297f39474eebd7de15e4792a Mon Sep 17 00:00:00 2001 From: Justin Chadwell Date: Wed, 8 Feb 2023 14:39:55 +0000 Subject: [PATCH] exporter: remove wrappers for oci data types opencontainers/image-spec now contains the MediaType field for all of its structs. With this update, we can avoid manually wrapping the internal data types to present this field. This requires updating the expected digest for source-date-epoch, since the ordering of JSON fields is now slightly different :) Signed-off-by: Justin Chadwell --- exporter/containerimage/writer.go | 70 +++++++++----------------- frontend/dockerfile/dockerfile_test.go | 2 +- 2 files changed, 24 insertions(+), 48 deletions(-) diff --git a/exporter/containerimage/writer.go b/exporter/containerimage/writer.go index 068d86958f8f..0c0aef743abf 100644 --- a/exporter/containerimage/writer.go +++ b/exporter/containerimage/writer.go @@ -178,19 +178,11 @@ func (ic *ImageWriter) Commit(ctx context.Context, inp *exporter.Source, session return nil, err } - idx := struct { - // MediaType is reserved in the OCI spec but - // excluded from go types. - MediaType string `json:"mediaType,omitempty"` - - ocispecs.Index - }{ - MediaType: ocispecs.MediaTypeImageIndex, - Index: ocispecs.Index{ - Annotations: opts.Annotations.Platform(nil).Index, - Versioned: specs.Versioned{ - SchemaVersion: 2, - }, + idx := ocispecs.Index{ + MediaType: ocispecs.MediaTypeImageIndex, + Annotations: opts.Annotations.Platform(nil).Index, + Versioned: specs.Versioned{ + SchemaVersion: 2, }, } @@ -386,24 +378,16 @@ func (ic *ImageWriter) commitDistributionManifest(ctx context.Context, opts *Ima configType = images.MediaTypeDockerSchema2Config } - mfst := struct { - // MediaType is reserved in the OCI spec but - // excluded from go types. - MediaType string `json:"mediaType,omitempty"` - - ocispecs.Manifest - }{ - MediaType: manifestType, - Manifest: ocispecs.Manifest{ - Annotations: annotations.Manifest, - Versioned: specs.Versioned{ - SchemaVersion: 2, - }, - Config: ocispecs.Descriptor{ - Digest: configDigest, - Size: int64(len(config)), - MediaType: configType, - }, + mfst := ocispecs.Manifest{ + MediaType: manifestType, + Annotations: annotations.Manifest, + Versioned: specs.Versioned{ + SchemaVersion: 2, + }, + Config: ocispecs.Descriptor{ + Digest: configDigest, + Size: int64(len(config)), + MediaType: configType, }, } @@ -499,23 +483,15 @@ func (ic *ImageWriter) commitAttestationsManifest(ctx context.Context, opts *Ima MediaType: configType, } - mfst := struct { - // MediaType is reserved in the OCI spec but - // excluded from go types. - MediaType string `json:"mediaType,omitempty"` - - ocispecs.Manifest - }{ + mfst := ocispecs.Manifest{ MediaType: manifestType, - Manifest: ocispecs.Manifest{ - Versioned: specs.Versioned{ - SchemaVersion: 2, - }, - Config: ocispecs.Descriptor{ - Digest: configDigest, - Size: int64(len(config)), - MediaType: configType, - }, + Versioned: specs.Versioned{ + SchemaVersion: 2, + }, + Config: ocispecs.Descriptor{ + Digest: configDigest, + Size: int64(len(config)), + MediaType: configType, }, } diff --git a/frontend/dockerfile/dockerfile_test.go b/frontend/dockerfile/dockerfile_test.go index f9fb61f60851..4e9fe9877ed3 100644 --- a/frontend/dockerfile/dockerfile_test.go +++ b/frontend/dockerfile/dockerfile_test.go @@ -6518,7 +6518,7 @@ FROM scratch COPY --from=0 / / `) - const expectedDigest = "sha256:9e36395384d073e711102b13bd0ba4b779ef6afbaf5cadeb77fe77dba8967d1f" + const expectedDigest = "sha256:23bfe9c494f4b4ae9368d989035c70b3a34aa0bfc991618b3e54dcce2eee4bf8" dir, err := integration.Tmpdir( t,