From 18566f66f34ef781aa16221116a7b8b552343f0e Mon Sep 17 00:00:00 2001 From: Nalin Dahyabhai Date: Mon, 29 Nov 2021 10:14:47 -0500 Subject: [PATCH] image: set MediaType in OCI manifests In image-spec 1.0.2, the MediaType field is now available in OCI manifests, so set it. Update the imgtype helper to output the MediaType field as-is from OCI image manifests instead of just always supplying the expected value. Signed-off-by: Nalin Dahyabhai --- go.mod | 2 +- go.sum | 2 ++ image.go | 1 + internal/source/create.go | 1 + pkg/blobcache/blobcache_test.go | 1 + tests/imgtype/imgtype.go | 2 +- .../github.com/opencontainers/image-spec/specs-go/v1/index.go | 3 +++ .../opencontainers/image-spec/specs-go/v1/manifest.go | 3 +++ .../github.com/opencontainers/image-spec/specs-go/version.go | 2 +- vendor/modules.txt | 2 +- 10 files changed, 15 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index cb7d3620f1f..3aced1dd43f 100644 --- a/go.mod +++ b/go.mod @@ -22,7 +22,7 @@ require ( github.com/onsi/ginkgo v1.16.5 github.com/onsi/gomega v1.17.0 github.com/opencontainers/go-digest v1.0.0 - github.com/opencontainers/image-spec v1.0.2-0.20210819154149-5ad6f50d6283 + github.com/opencontainers/image-spec v1.0.2-0.20211123152302-43a7dee1ec31 github.com/opencontainers/runc v1.0.2 github.com/opencontainers/runtime-spec v1.0.3-0.20210326190908-1c3f411f0417 github.com/opencontainers/runtime-tools v0.9.0 diff --git a/go.sum b/go.sum index 4085576ae3e..81d4a0a2b04 100644 --- a/go.sum +++ b/go.sum @@ -686,6 +686,8 @@ github.com/opencontainers/image-spec v1.0.0/go.mod h1:BtxoFyWECRxE4U/7sNtV5W15zM github.com/opencontainers/image-spec v1.0.1/go.mod h1:BtxoFyWECRxE4U/7sNtV5W15zMzWCbyJoFRP3s7yZA0= github.com/opencontainers/image-spec v1.0.2-0.20210819154149-5ad6f50d6283 h1:TVzvdjOalkJBNkbpPVMAr4KV9QRf2IjfxdyxwAK78Gs= github.com/opencontainers/image-spec v1.0.2-0.20210819154149-5ad6f50d6283/go.mod h1:BtxoFyWECRxE4U/7sNtV5W15zMzWCbyJoFRP3s7yZA0= +github.com/opencontainers/image-spec v1.0.2-0.20211123152302-43a7dee1ec31 h1:Wh4aR2I6JFwySre9m3iHJYuMnvUFE/HT6qAXozRWi/E= +github.com/opencontainers/image-spec v1.0.2-0.20211123152302-43a7dee1ec31/go.mod h1:BtxoFyWECRxE4U/7sNtV5W15zMzWCbyJoFRP3s7yZA0= github.com/opencontainers/runc v0.0.0-20190115041553-12f6a991201f/go.mod h1:qT5XzbpPznkRYVz/mWwUaVBUv2rmF59PVA73FjuZG0U= github.com/opencontainers/runc v0.1.1/go.mod h1:qT5XzbpPznkRYVz/mWwUaVBUv2rmF59PVA73FjuZG0U= github.com/opencontainers/runc v1.0.0-rc8.0.20190926000215-3e425f80a8c9/go.mod h1:qT5XzbpPznkRYVz/mWwUaVBUv2rmF59PVA73FjuZG0U= diff --git a/image.go b/image.go index ed49111c4d7..e859de183db 100644 --- a/image.go +++ b/image.go @@ -239,6 +239,7 @@ func (i *containerImageRef) createConfigsAndManifests() (v1.Image, v1.Manifest, Versioned: specs.Versioned{ SchemaVersion: 2, }, + MediaType: v1.MediaTypeImageManifest, Config: v1.Descriptor{ MediaType: v1.MediaTypeImageConfig, }, diff --git a/internal/source/create.go b/internal/source/create.go index 0a92f1c9a04..7adbf2d3bfa 100644 --- a/internal/source/create.go +++ b/internal/source/create.go @@ -54,6 +54,7 @@ func Create(ctx context.Context, sourcePath string, options CreateOptions) error // Create and write the manifest. manifest := specV1.Manifest{ Versioned: spec.Versioned{SchemaVersion: 2}, + MediaType: specV1.MediaTypeImageManifest, Config: specV1.Descriptor{ MediaType: MediaTypeSourceImageConfig, Digest: configBlob.Digest, diff --git a/pkg/blobcache/blobcache_test.go b/pkg/blobcache/blobcache_test.go index 75ffdd4aa4f..2393350c377 100644 --- a/pkg/blobcache/blobcache_test.go +++ b/pkg/blobcache/blobcache_test.go @@ -102,6 +102,7 @@ func TestBlobCache(t *testing.T) { Versioned: specs.Versioned{ SchemaVersion: 2, }, + MediaType: v1.MediaTypeImageManifest, Config: v1.Descriptor{ MediaType: v1.MediaTypeImageConfig, Digest: configInfo.Digest, diff --git a/tests/imgtype/imgtype.go b/tests/imgtype/imgtype.go index 82af79572b9..f80087513ce 100644 --- a/tests/imgtype/imgtype.go +++ b/tests/imgtype/imgtype.go @@ -159,7 +159,7 @@ func main() { errors = true continue } - manifestType = v1.MediaTypeImageManifest + manifestType = oManifest.MediaType configType = oManifest.Config.MediaType case define.Dockerv2ImageManifest: err = json.Unmarshal(manifest, &dManifest) diff --git a/vendor/github.com/opencontainers/image-spec/specs-go/v1/index.go b/vendor/github.com/opencontainers/image-spec/specs-go/v1/index.go index 4e6c4b23623..82da6c6a898 100644 --- a/vendor/github.com/opencontainers/image-spec/specs-go/v1/index.go +++ b/vendor/github.com/opencontainers/image-spec/specs-go/v1/index.go @@ -21,6 +21,9 @@ import "github.com/opencontainers/image-spec/specs-go" type Index struct { specs.Versioned + // MediaType specificies the type of this document data structure e.g. `application/vnd.oci.image.index.v1+json` + MediaType string `json:"mediaType,omitempty"` + // Manifests references platform specific manifests. Manifests []Descriptor `json:"manifests"` diff --git a/vendor/github.com/opencontainers/image-spec/specs-go/v1/manifest.go b/vendor/github.com/opencontainers/image-spec/specs-go/v1/manifest.go index 7ff32c40ba3..d72d15ce4bb 100644 --- a/vendor/github.com/opencontainers/image-spec/specs-go/v1/manifest.go +++ b/vendor/github.com/opencontainers/image-spec/specs-go/v1/manifest.go @@ -20,6 +20,9 @@ import "github.com/opencontainers/image-spec/specs-go" type Manifest struct { specs.Versioned + // MediaType specificies the type of this document data structure e.g. `application/vnd.oci.image.manifest.v1+json` + MediaType string `json:"mediaType,omitempty"` + // Config references a configuration object for a container, by digest. // The referenced configuration object is a JSON blob that the runtime uses to set up the container. Config Descriptor `json:"config"` diff --git a/vendor/github.com/opencontainers/image-spec/specs-go/version.go b/vendor/github.com/opencontainers/image-spec/specs-go/version.go index 58f1095ab08..31f99cf645c 100644 --- a/vendor/github.com/opencontainers/image-spec/specs-go/version.go +++ b/vendor/github.com/opencontainers/image-spec/specs-go/version.go @@ -22,7 +22,7 @@ const ( // VersionMinor is for functionality in a backwards-compatible manner VersionMinor = 0 // VersionPatch is for backwards-compatible bug fixes - VersionPatch = 1 + VersionPatch = 2 // VersionDev indicates development branch. Releases will be empty string. VersionDev = "-dev" diff --git a/vendor/modules.txt b/vendor/modules.txt index 80a494e26e9..172ae4b40a8 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -384,7 +384,7 @@ github.com/onsi/gomega/matchers/support/goraph/util github.com/onsi/gomega/types # github.com/opencontainers/go-digest v1.0.0 github.com/opencontainers/go-digest -# github.com/opencontainers/image-spec v1.0.2-0.20210819154149-5ad6f50d6283 +# github.com/opencontainers/image-spec v1.0.2-0.20211123152302-43a7dee1ec31 github.com/opencontainers/image-spec/specs-go github.com/opencontainers/image-spec/specs-go/v1 # github.com/opencontainers/runc v1.0.2