Skip to content

Commit ebaaefe

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 b1bb913 commit ebaaefe

File tree

3 files changed

+28
-9
lines changed

3 files changed

+28
-9
lines changed

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 neccessary 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/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,17 +98,29 @@ 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
func NewOCIImageManifest(ref reference.Named, desc ocispec.Descriptor, manifest *ocischema.DeserializedManifest) ImageManifest {
115+
raw, err := manifest.MarshalJSON()
116+
if err != nil {
117+
raw = nil
118+
}
119+
110120
return ImageManifest{
111121
Ref: &SerializableNamed{Named: ref},
112122
Descriptor: desc,
123+
Raw: raw,
113124
OCIManifest: manifest,
114125
}
115126
}

0 commit comments

Comments
 (0)