diff --git a/cli/command/manifest/push.go b/cli/command/manifest/push.go index 0d752371c5b9..830f7d84c2f5 100644 --- a/cli/command/manifest/push.go +++ b/cli/command/manifest/push.go @@ -2,7 +2,6 @@ package manifest import ( "context" - "encoding/json" "fmt" "io" @@ -11,7 +10,6 @@ import ( "github.com/docker/cli/cli/manifest/types" registryclient "github.com/docker/cli/cli/registry/client" "github.com/docker/distribution/manifest/manifestlist" - "github.com/docker/distribution/manifest/schema2" "github.com/docker/distribution/reference" "github.com/docker/docker/registry" "github.com/pkg/errors" @@ -211,19 +209,6 @@ func buildPutManifestRequest(imageManifest types.ImageManifest, targetRef refere return mountRequest{}, err } - // This indentation has to be added to ensure sha parity with the registry - v2ManifestBytes, err := json.MarshalIndent(imageManifest.SchemaV2Manifest, "", " ") - if err != nil { - return mountRequest{}, err - } - // indent only the DeserializedManifest portion of this, in order to maintain parity with the registry - // and not alter the sha - var v2Manifest schema2.DeserializedManifest - if err = v2Manifest.UnmarshalJSON(v2ManifestBytes); err != nil { - return mountRequest{}, err - } - imageManifest.SchemaV2Manifest = &v2Manifest - return mountRequest{ref: mountRef, manifest: imageManifest}, err } diff --git a/cli/command/manifest/testdata/inspect-annotate.golden b/cli/command/manifest/testdata/inspect-annotate.golden index d39438c447e1..f5e3f6a42dc8 100644 --- a/cli/command/manifest/testdata/inspect-annotate.golden +++ b/cli/command/manifest/testdata/inspect-annotate.golden @@ -1,22 +1,7 @@ { "Ref": "example.com/alpine:3.0", "Digest": "sha256:7328f6f8b41890597575cbaadc884e7386ae0acc53b747401ebce5cf0d62abcd", - "SchemaV2Manifest": { - "schemaVersion": 2, - "mediaType": "application/vnd.docker.distribution.manifest.v2+json", - "config": { - "mediaType": "application/vnd.docker.container.image.v1+json", - "size": 1520, - "digest": "sha256:7328f6f8b41890597575cbaadc884e7386ae0acc53b747401ebce5cf0d624560" - }, - "layers": [ - { - "mediaType": "application/vnd.docker.image.rootfs.diff.tar.gzip", - "size": 1990402, - "digest": "sha256:88286f41530e93dffd4b964e1db22ce4939fffa4a4c665dab8591fbab03d4926" - } - ] - }, + "SchemaV2Manifest": "ewogICAic2NoZW1hVmVyc2lvbiI6IDIsCiAgICJtZWRpYVR5cGUiOiAiYXBwbGljYXRpb24vdm5kLmRvY2tlci5kaXN0cmlidXRpb24ubWFuaWZlc3QudjIranNvbiIsCiAgICJjb25maWciOiB7CiAgICAgICJtZWRpYVR5cGUiOiAiYXBwbGljYXRpb24vdm5kLmRvY2tlci5jb250YWluZXIuaW1hZ2UudjEranNvbiIsCiAgICAgICJzaXplIjogMTUyMCwKICAgICAgImRpZ2VzdCI6ICJzaGEyNTY6NzMyOGY2ZjhiNDE4OTA1OTc1NzVjYmFhZGM4ODRlNzM4NmFlMGFjYzUzYjc0NzQwMWViY2U1Y2YwZDYyNDU2MCIKICAgfSwKICAgImxheWVycyI6IFsKICAgICAgewogICAgICAgICAibWVkaWFUeXBlIjogImFwcGxpY2F0aW9uL3ZuZC5kb2NrZXIuaW1hZ2Uucm9vdGZzLmRpZmYudGFyLmd6aXAiLAogICAgICAgICAic2l6ZSI6IDE5OTA0MDIsCiAgICAgICAgICJkaWdlc3QiOiAic2hhMjU2Ojg4Mjg2ZjQxNTMwZTkzZGZmZDRiOTY0ZTFkYjIyY2U0OTM5ZmZmYTRhNGM2NjVkYWI4NTkxZmJhYjAzZDQ5MjYiCiAgICAgIH0KICAgXQp9", "Platform": { "architecture": "arm", "os": "freebsd", diff --git a/cli/command/manifest/testdata/inspect-manifest-list.golden b/cli/command/manifest/testdata/inspect-manifest-list.golden index 95f8c46722e3..058006b39483 100644 --- a/cli/command/manifest/testdata/inspect-manifest-list.golden +++ b/cli/command/manifest/testdata/inspect-manifest-list.golden @@ -4,7 +4,7 @@ "manifests": [ { "mediaType": "application/vnd.docker.distribution.manifest.v2+json", - "size": 428, + "size": 528, "digest": "sha256:7328f6f8b41890597575cbaadc884e7386ae0acc53b747401ebce5cf0d62abcd", "platform": { "architecture": "amd64", @@ -13,7 +13,7 @@ }, { "mediaType": "application/vnd.docker.distribution.manifest.v2+json", - "size": 428, + "size": 528, "digest": "sha256:7328f6f8b41890597575cbaadc884e7386ae0acc53b747401ebce5cf0d62abcd", "platform": { "architecture": "amd64", diff --git a/cli/manifest/types/types.go b/cli/manifest/types/types.go index f618fd2b0311..8c7c3dff164e 100644 --- a/cli/manifest/types/types.go +++ b/cli/manifest/types/types.go @@ -15,14 +15,22 @@ import ( type ImageManifest struct { Ref *SerializableNamed Digest digest.Digest - SchemaV2Manifest *schema2.DeserializedManifest `json:",omitempty"` + SchemaV2Manifest []byte `json:",omitempty"` Platform manifestlist.PlatformSpec } +func (i ImageManifest) manifest() *schema2.DeserializedManifest { + var dm schema2.DeserializedManifest + if err := json.Unmarshal(i.SchemaV2Manifest, &dm); err != nil { + panic(err) + } + return &dm +} + // Blobs returns the digests for all the blobs referenced by this manifest func (i ImageManifest) Blobs() []digest.Digest { digests := []digest.Digest{} - for _, descriptor := range i.SchemaV2Manifest.References() { + for _, descriptor := range i.manifest().References() { digests = append(digests, descriptor.Digest) } return digests @@ -31,8 +39,9 @@ func (i ImageManifest) Blobs() []digest.Digest { // Payload returns the media type and bytes for the manifest func (i ImageManifest) Payload() (string, []byte, error) { switch { - case i.SchemaV2Manifest != nil: - return i.SchemaV2Manifest.Payload() + case len(i.SchemaV2Manifest) > 0: + media, _, err := i.manifest().Payload() + return media, i.SchemaV2Manifest, err default: return "", nil, errors.Errorf("%s has no payload", i.Ref) } @@ -42,8 +51,8 @@ func (i ImageManifest) Payload() (string, []byte, error) { // the underlying manifest. func (i ImageManifest) References() []distribution.Descriptor { switch { - case i.SchemaV2Manifest != nil: - return i.SchemaV2Manifest.References() + case len(i.SchemaV2Manifest) > 0: + return i.manifest().References() default: return nil } @@ -58,10 +67,11 @@ func NewImageManifest(ref reference.Named, digest digest.Digest, img Image, mani OSVersion: img.OSVersion, OSFeatures: img.OSFeatures, } + _, raw, _ := manifest.Payload() return ImageManifest{ Ref: &SerializableNamed{Named: ref}, Digest: digest, - SchemaV2Manifest: manifest, + SchemaV2Manifest: raw, Platform: platform, } }