Skip to content

Commit

Permalink
Use local image if input image is a manifest list
Browse files Browse the repository at this point in the history
If run&create image returns error: image contains manifest list, not a runnable image, find the local image that has digest matching the digest from the list and use the image from local storage for the command.

Signed-off-by: Qi Wang <[email protected]>
  • Loading branch information
QiWang19 committed Sep 30, 2020
1 parent 2ee415b commit d24ec64
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
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)
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
}
}
}
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())
})
})

0 comments on commit d24ec64

Please sign in to comment.