Skip to content
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

Merged
merged 1 commit into from
Sep 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 38 additions & 1 deletion pkg/specgen/generate/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -33,7 +34,43 @@ func CompleteSpec(ctx context.Context, r *libpod.Runtime, s *specgen.SpecGenerat

_, mediaType, err := newImage.Manifest(ctx)
Copy link
Member

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?

Copy link
Contributor Author

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

Copy link
Member

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.

Copy link
Member

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 that mediaType is updated to the value that correctly describes its manifest.

Copy link
Contributor Author

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.

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
}
}
}
Copy link
Member

@nalind nalind Sep 28, 2020

Choose a reason for hiding this comment

The 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 images. Instead of checking for any of the values returned by list.Instances(), can we use list.ChooseInstance() to select the one that would be correct for the current architecture, and only accept an image that matches the digest it returns?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 {
Expand Down
17 changes: 17 additions & 0 deletions test/e2e/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -609,4 +609,21 @@ var _ = Describe("Podman create", func() {
Expect(session.ExitCode()).ToNot(BeZero())
})

It("create use local store image if input image contains a manifest list", func() {
session := podmanTest.Podman([]string{"pull", BB})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(BeZero())

session = podmanTest.Podman([]string{"manifest", "create", "mylist"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))

session = podmanTest.Podman([]string{"manifest", "add", "--all", "mylist", BB})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(BeZero())

session = podmanTest.Podman([]string{"create", "mylist"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(BeZero())
})
})