MCPcopy Index your code
hub / github.com/docker/cli / buildPutManifestRequest

Function buildPutManifestRequest

cli/command/manifest/push.go:187–246  ·  view source on GitHub ↗
(imageManifest types.ImageManifest, targetRef reference.Named)

Source from the content-addressed store, hash-verified

185}
186
187func buildPutManifestRequest(imageManifest types.ImageManifest, targetRef reference.Named) (mountRequest, error) {
188 refWithoutTag, err := reference.WithName(targetRef.Name())
189 if err != nil {
190 return mountRequest{}, err
191 }
192 mountRef, err := reference.WithDigest(refWithoutTag, imageManifest.Descriptor.Digest)
193 if err != nil {
194 return mountRequest{}, err
195 }
196
197 // Attempt to reconstruct indentation of the manifest to ensure sha parity
198 // with the registry - if we haven't preserved the raw content.
199 //
200 // This is necessary because our previous internal storage format did not
201 // preserve whitespace. If we don't have the newer format present, we can
202 // attempt the reconstruction like before, but explicitly error if the
203 // reconstruction failed!
204 switch {
205 case imageManifest.SchemaV2Manifest != nil:
206 dt := imageManifest.Raw
207 if len(dt) == 0 {
208 dt, err = json.MarshalIndent(imageManifest.SchemaV2Manifest, "", " ")
209 if err != nil {
210 return mountRequest{}, err
211 }
212 }
213
214 dig := imageManifest.Descriptor.Digest
215 if dig2 := dig.Algorithm().FromBytes(dt); dig != dig2 {
216 return mountRequest{}, fmt.Errorf("internal digest mismatch for %s: expected %s, got %s", imageManifest.Ref, dig, dig2)
217 }
218
219 var manifest schema2.DeserializedManifest
220 if err = manifest.UnmarshalJSON(dt); err != nil {
221 return mountRequest{}, err
222 }
223 imageManifest.SchemaV2Manifest = &manifest
224 case imageManifest.OCIManifest != nil:
225 dt := imageManifest.Raw
226 if len(dt) == 0 {
227 dt, err = json.MarshalIndent(imageManifest.OCIManifest, "", " ")
228 if err != nil {
229 return mountRequest{}, err
230 }
231 }
232
233 dig := imageManifest.Descriptor.Digest
234 if dig2 := dig.Algorithm().FromBytes(dt); dig != dig2 {
235 return mountRequest{}, fmt.Errorf("internal digest mismatch for %s: expected %s, got %s", imageManifest.Ref, dig, dig2)
236 }
237
238 var manifest ocischema.DeserializedManifest
239 if err = manifest.UnmarshalJSON(dt); err != nil {
240 return mountRequest{}, err
241 }
242 imageManifest.OCIManifest = &manifest
243 }
244

Callers 1

buildPushRequestFunction · 0.85

Calls 2

NameMethod · 0.45
UnmarshalJSONMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…