Don't throw away the manifest MIME type and guess again

When loading the manifest using a types.Image.Manifest,
we also get a manifest MIME type; don't just throw it away
and then guess as if the data was never available, just use it
directly (now that the loading is close enough for the throwing
away to be noticeable).

[Ultimately, this loads the manifest from a c/image/storage
backend, which calls manifest.GuessMIMEType anyway, so this
does not change behavior right now, but if the c/image/storage
backend ever changed to record MIME types, it would make a
difference.  At the very least, we now run the heuristic once
instead of twice.]

Signed-off-by: Miloslav Trmač <mitr@redhat.com>

Closes: #776
Approved by: rhatdan
This commit is contained in:
Miloslav Trmač 2018-06-12 00:47:48 +02:00 committed by Atomic Bot
parent 6cb7048d90
commit 3e5102046e
1 changed files with 3 additions and 3 deletions

View File

@ -180,7 +180,7 @@ func makeDockerV2S1Image(manifest docker.V2S1Manifest) (docker.V2Image, error) {
func (b *Builder) initConfig(ctx context.Context, img types.Image) error {
if img != nil { // A pre-existing image, as opposed to a "FROM scratch" new one.
rawManifest, _, err := img.Manifest(ctx)
rawManifest, manifestMIMEType, err := img.Manifest(ctx)
if err != nil {
return errors.Wrapf(err, "error reading image manifest for %q", transports.ImageName(img.Reference()))
}
@ -191,7 +191,7 @@ func (b *Builder) initConfig(ctx context.Context, img types.Image) error {
b.Manifest = rawManifest
b.Config = rawConfig
switch mt := manifest.GuessMIMEType(b.Manifest); mt {
switch manifestMIMEType {
case manifest.DockerV2Schema2MediaType:
dimage := docker.V2Image{}
if err := json.Unmarshal(b.Config, &dimage); err != nil {
@ -231,7 +231,7 @@ func (b *Builder) initConfig(ctx context.Context, img types.Image) error {
case "":
return errors.Errorf("can't work with an unrecognized manifest type")
default:
return errors.Errorf("unsupported manifest type %#v", mt)
return errors.Errorf("unsupported manifest type %#v", manifestMIMEType)
}
}