Skip to content

Commit 67b9617

Browse files
committed
manifest: save raw manifest content on download
This prevents us needing to attempt to reconstruct the exact indentation registry side, which is not canonical - so may differ. Signed-off-by: Justin Chadwell <me@jedevc.com>
1 parent 285e137 commit 67b9617

4 files changed

Lines changed: 29 additions & 9 deletions

File tree

cli/command/manifest/push.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -219,17 +219,20 @@ func buildPutManifestRequest(imageManifest types.ImageManifest, targetRef refere
219219
}
220220

221221
// Attempt to reconstruct indentation of the manifest to ensure sha parity
222-
// with the registry.
222+
// with the registry - if we haven't preserved the raw content.
223223
//
224224
// This is necessary because our previous internal storage format did not
225225
// preserve whitespace. If we don't have the newer format present, we can
226226
// attempt the reconstruction like before, but explicitly error if the
227227
// reconstruction failed!
228228
switch {
229229
case imageManifest.SchemaV2Manifest != nil:
230-
dt, err := json.MarshalIndent(imageManifest.SchemaV2Manifest, "", " ")
231-
if err != nil {
232-
return mountRequest{}, err
230+
dt := imageManifest.Raw
231+
if len(dt) == 0 {
232+
dt, err = json.MarshalIndent(imageManifest.SchemaV2Manifest, "", " ")
233+
if err != nil {
234+
return mountRequest{}, err
235+
}
233236
}
234237

235238
dig := imageManifest.Descriptor.Digest
@@ -243,9 +246,12 @@ func buildPutManifestRequest(imageManifest types.ImageManifest, targetRef refere
243246
}
244247
imageManifest.SchemaV2Manifest = &manifest
245248
case imageManifest.OCIManifest != nil:
246-
dt, err := json.MarshalIndent(imageManifest.OCIManifest, "", " ")
247-
if err != nil {
248-
return mountRequest{}, err
249+
dt := imageManifest.Raw
250+
if len(dt) == 0 {
251+
dt, err = json.MarshalIndent(imageManifest.OCIManifest, "", " ")
252+
if err != nil {
253+
return mountRequest{}, err
254+
}
249255
}
250256

251257
dig := imageManifest.Descriptor.Digest

cli/command/manifest/testdata/inspect-annotate.golden

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"variant": "v7"
1515
}
1616
},
17+
"Raw": "ewogICAic2NoZW1hVmVyc2lvbiI6IDIsCiAgICJtZWRpYVR5cGUiOiAiYXBwbGljYXRpb24vdm5kLmRvY2tlci5kaXN0cmlidXRpb24ubWFuaWZlc3QudjIranNvbiIsCiAgICJjb25maWciOiB7CiAgICAgICJtZWRpYVR5cGUiOiAiYXBwbGljYXRpb24vdm5kLmRvY2tlci5jb250YWluZXIuaW1hZ2UudjEranNvbiIsCiAgICAgICJzaXplIjogMTUyMCwKICAgICAgImRpZ2VzdCI6ICJzaGEyNTY6NzMyOGY2ZjhiNDE4OTA1OTc1NzVjYmFhZGM4ODRlNzM4NmFlMGFjYzUzYjc0NzQwMWViY2U1Y2YwZDYyNDU2MCIKICAgfSwKICAgImxheWVycyI6IFsKICAgICAgewogICAgICAgICAibWVkaWFUeXBlIjogImFwcGxpY2F0aW9uL3ZuZC5kb2NrZXIuaW1hZ2Uucm9vdGZzLmRpZmYudGFyLmd6aXAiLAogICAgICAgICAic2l6ZSI6IDE5OTA0MDIsCiAgICAgICAgICJkaWdlc3QiOiAic2hhMjU2Ojg4Mjg2ZjQxNTMwZTkzZGZmZDRiOTY0ZTFkYjIyY2U0OTM5ZmZmYTRhNGM2NjVkYWI4NTkxZmJhYjAzZDQ5MjYiCiAgICAgIH0KICAgXQp9",
1718
"SchemaV2Manifest": {
1819
"schemaVersion": 2,
1920
"mediaType": "application/vnd.docker.distribution.manifest.v2+json",

cli/command/manifest/util.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ func getManifest(ctx context.Context, dockerCli command.Cli, listRef, namedRef r
7676
return dockerCli.RegistryClient(insecure).GetManifest(ctx, namedRef)
7777
case err != nil:
7878
return types.ImageManifest{}, err
79+
case len(data.Raw) == 0:
80+
return dockerCli.RegistryClient(insecure).GetManifest(ctx, namedRef)
7981
default:
8082
return data, nil
8183
}

cli/manifest/types/types.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ import (
1717
type ImageManifest struct {
1818
Ref *SerializableNamed
1919
Descriptor ocispec.Descriptor
20-
21-
// TODO: Deprecate this and store manifest blobs
20+
Raw []byte `json:",omitempty"`
2221

2322
// SchemaV2Manifest is used for inspection
2423
SchemaV2Manifest *schema2.DeserializedManifest `json:",omitempty"`
@@ -99,19 +98,31 @@ func (i ImageManifest) References() []distribution.Descriptor {
9998
// NewImageManifest returns a new ImageManifest object. The values for Platform
10099
// are initialized from those in the image
101100
func NewImageManifest(ref reference.Named, desc ocispec.Descriptor, manifest *schema2.DeserializedManifest) ImageManifest {
101+
raw, err := manifest.MarshalJSON()
102+
if err != nil {
103+
raw = nil
104+
}
105+
102106
return ImageManifest{
103107
Ref: &SerializableNamed{Named: ref},
104108
Descriptor: desc,
109+
Raw: raw,
105110
SchemaV2Manifest: manifest,
106111
}
107112
}
108113

109114
// NewOCIImageManifest returns a new ImageManifest object. The values for
110115
// Platform are initialized from those in the image
111116
func NewOCIImageManifest(ref reference.Named, desc ocispec.Descriptor, manifest *ocischema.DeserializedManifest) ImageManifest {
117+
raw, err := manifest.MarshalJSON()
118+
if err != nil {
119+
raw = nil
120+
}
121+
112122
return ImageManifest{
113123
Ref: &SerializableNamed{Named: ref},
114124
Descriptor: desc,
125+
Raw: raw,
115126
OCIManifest: manifest,
116127
}
117128
}

0 commit comments

Comments
 (0)