Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions cli/command/manifest/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package manifest

import (
"context"
"encoding/json"
"fmt"
"io"

Expand All @@ -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"
Expand Down Expand Up @@ -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
}

Expand Down
17 changes: 1 addition & 16 deletions cli/command/manifest/testdata/inspect-annotate.golden
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
4 changes: 2 additions & 2 deletions cli/command/manifest/testdata/inspect-manifest-list.golden
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"manifests": [
{
"mediaType": "application/vnd.docker.distribution.manifest.v2+json",
"size": 428,
"size": 528,
"digest": "sha256:7328f6f8b41890597575cbaadc884e7386ae0acc53b747401ebce5cf0d62abcd",
"platform": {
"architecture": "amd64",
Expand All @@ -13,7 +13,7 @@
},
{
"mediaType": "application/vnd.docker.distribution.manifest.v2+json",
"size": 428,
"size": 528,
"digest": "sha256:7328f6f8b41890597575cbaadc884e7386ae0acc53b747401ebce5cf0d62abcd",
"platform": {
"architecture": "amd64",
Expand Down
24 changes: 17 additions & 7 deletions cli/manifest/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}
Expand All @@ -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
}
Expand All @@ -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,
}
}
Expand Down