-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use local image if input image is a manifest list #7798
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ import ( | |
"github.com/containers/podman/v2/pkg/specgen" | ||
spec "github.com/opencontainers/runtime-spec/specs-go" | ||
"github.com/pkg/errors" | ||
"github.com/sirupsen/logrus" | ||
"golang.org/x/sys/unix" | ||
) | ||
|
||
|
@@ -33,7 +34,43 @@ func CompleteSpec(ctx context.Context, r *libpod.Runtime, s *specgen.SpecGenerat | |
|
||
_, mediaType, err := newImage.Manifest(ctx) | ||
if err != nil { | ||
return nil, err | ||
if errors.Cause(err) != image.ErrImageIsBareList { | ||
return nil, err | ||
} | ||
// if err is not runnable image | ||
// use the local store image with repo@digest matches with the list, if exists | ||
manifestByte, manifestType, err := newImage.GetManifest(ctx, nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
list, err := manifest.ListFromBlob(manifestByte, manifestType) | ||
if err != nil { | ||
return nil, err | ||
} | ||
images, err := r.ImageRuntime().GetImages() | ||
if err != nil { | ||
return nil, err | ||
} | ||
findLocal := false | ||
listDigest, err := list.ChooseInstance(r.SystemContext()) | ||
if err != nil { | ||
return nil, err | ||
} | ||
for _, img := range images { | ||
for _, imageDigest := range img.Digests() { | ||
if imageDigest == listDigest { | ||
newImage = img | ||
s.Image = img.ID() | ||
mediaType = manifestType | ||
findLocal = true | ||
logrus.Debug("image contains manifest list, using image from local storage") | ||
break | ||
} | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will match any local image which is also in the list, so it solves the problem when only one of them is present. If I've pulled more than one using the repository name and their respective digests, this will choose the first one in the list, when the one for the current architecture (if one is present) could be listed later in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed. |
||
if !findLocal { | ||
return nil, image.ErrImageIsBareList | ||
} | ||
} | ||
|
||
if s.HealthConfig == nil && mediaType == manifest.DockerV2Schema2MediaType { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you have to set this mediaType somewhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mediaType will be used to check if its a manifest.DockerV2Schema2MediaType
https://github.com/containers/podman/pull/7798/files#diff-5a91791543058d94a51dab8d8294ca7cR75
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But if the newImage.Manifest(ctx) check fails, the nediaType is never set.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, good catch. If we do find a suitable image and update
newImage
to point to it, we need to make sure thatmediaType
is updated to the value that correctly describes its manifest.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If newImage.Manifest(ctx) fails, use the mediaType of the local image.