mirror of
https://github.com/containers/podman.git
synced 2025-06-23 02:18:13 +08:00
Merge pull request #15034 from sstosh/manifest-push-rm
Fix: manifest push --rm removes a correct manifest list
This commit is contained in:
@ -331,7 +331,8 @@ func (ir *ImageEngine) ManifestPush(ctx context.Context, name, destination strin
|
|||||||
}
|
}
|
||||||
|
|
||||||
if opts.Rm {
|
if opts.Rm {
|
||||||
if _, rmErrors := ir.Libpod.LibimageRuntime().RemoveImages(ctx, []string{manifestList.ID()}, nil); len(rmErrors) > 0 {
|
rmOpts := &libimage.RemoveImagesOptions{LookupManifest: true}
|
||||||
|
if _, rmErrors := ir.Libpod.LibimageRuntime().RemoveImages(ctx, []string{manifestList.ID()}, rmOpts); len(rmErrors) > 0 {
|
||||||
return "", fmt.Errorf("error removing manifest after push: %w", rmErrors[0])
|
return "", fmt.Errorf("error removing manifest after push: %w", rmErrors[0])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -110,5 +110,15 @@ func (ir *ImageEngine) ManifestPush(ctx context.Context, name, destination strin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
digest, err := manifests.Push(ir.ClientCtx, name, destination, options)
|
digest, err := manifests.Push(ir.ClientCtx, name, destination, options)
|
||||||
|
if err != nil {
|
||||||
|
return "", fmt.Errorf("error adding to manifest list %s: %w", name, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if opts.Rm {
|
||||||
|
if _, rmErrors := ir.Remove(ctx, []string{name}, entities.ImageRemoveOptions{LookupManifest: true}); len(rmErrors) > 0 {
|
||||||
|
return "", fmt.Errorf("error removing manifest after push: %w", rmErrors[0])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return digest, err
|
return digest, err
|
||||||
}
|
}
|
||||||
|
@ -339,6 +339,16 @@ var _ = Describe("Podman manifest", func() {
|
|||||||
push = podmanTest.Podman([]string{"manifest", "push", "--tls-verify=false", "--creds=podmantest:wrongpasswd", "foo", "localhost:" + registry.Port + "/credstest"})
|
push = podmanTest.Podman([]string{"manifest", "push", "--tls-verify=false", "--creds=podmantest:wrongpasswd", "foo", "localhost:" + registry.Port + "/credstest"})
|
||||||
push.WaitWithDefaultTimeout()
|
push.WaitWithDefaultTimeout()
|
||||||
Expect(push).To(ExitWithError())
|
Expect(push).To(ExitWithError())
|
||||||
|
|
||||||
|
// push --rm after pull image (#15033)
|
||||||
|
push = podmanTest.Podman([]string{"manifest", "push", "--rm", "--tls-verify=false", "--creds=" + registry.User + ":" + registry.Password, "foo", "localhost:" + registry.Port + "/rmtest"})
|
||||||
|
push.WaitWithDefaultTimeout()
|
||||||
|
Expect(push).Should(Exit(0))
|
||||||
|
|
||||||
|
session = podmanTest.Podman([]string{"images", "-q", "foo"})
|
||||||
|
session.WaitWithDefaultTimeout()
|
||||||
|
Expect(session).Should(Exit(0))
|
||||||
|
Expect(podmanTest.NumberOfContainersRunning()).To(Equal(0))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("push with error", func() {
|
It("push with error", func() {
|
||||||
@ -348,8 +358,8 @@ var _ = Describe("Podman manifest", func() {
|
|||||||
Expect(session.ErrorToString()).NotTo(BeEmpty())
|
Expect(session.ErrorToString()).NotTo(BeEmpty())
|
||||||
})
|
})
|
||||||
|
|
||||||
It("push --rm", func() {
|
It("push --rm to local directory", func() {
|
||||||
SkipIfRemote("remote does not support --rm")
|
SkipIfRemote("manifest push to dir not supported in remote mode")
|
||||||
session := podmanTest.Podman([]string{"manifest", "create", "foo"})
|
session := podmanTest.Podman([]string{"manifest", "create", "foo"})
|
||||||
session.WaitWithDefaultTimeout()
|
session.WaitWithDefaultTimeout()
|
||||||
Expect(session).Should(Exit(0))
|
Expect(session).Should(Exit(0))
|
||||||
@ -365,13 +375,35 @@ var _ = Describe("Podman manifest", func() {
|
|||||||
session = podmanTest.Podman([]string{"manifest", "push", "--purge", "foo", "dir:" + dest})
|
session = podmanTest.Podman([]string{"manifest", "push", "--purge", "foo", "dir:" + dest})
|
||||||
session.WaitWithDefaultTimeout()
|
session.WaitWithDefaultTimeout()
|
||||||
Expect(session).Should(Exit(0))
|
Expect(session).Should(Exit(0))
|
||||||
session = podmanTest.Podman([]string{"manifest", "inspect", "foo"})
|
session = podmanTest.Podman([]string{"images", "-q", "foo"})
|
||||||
session.WaitWithDefaultTimeout()
|
session.WaitWithDefaultTimeout()
|
||||||
Expect(session).To(ExitWithError())
|
Expect(session).Should(Exit(0))
|
||||||
|
Expect(podmanTest.NumberOfContainersRunning()).To(Equal(0))
|
||||||
|
|
||||||
session = podmanTest.Podman([]string{"manifest", "rm", "foo1", "foo2"})
|
// push --rm after pull image (#15033)
|
||||||
|
session = podmanTest.Podman([]string{"pull", "quay.io/libpod/testdigest_v2s2"})
|
||||||
session.WaitWithDefaultTimeout()
|
session.WaitWithDefaultTimeout()
|
||||||
Expect(session).To(ExitWithError())
|
Expect(session).Should(Exit(0))
|
||||||
|
|
||||||
|
session = podmanTest.Podman([]string{"manifest", "create", "bar"})
|
||||||
|
session.WaitWithDefaultTimeout()
|
||||||
|
Expect(session).Should(Exit(0))
|
||||||
|
session = podmanTest.Podman([]string{"manifest", "add", "bar", "quay.io/libpod/testdigest_v2s2"})
|
||||||
|
session.WaitWithDefaultTimeout()
|
||||||
|
Expect(session).Should(Exit(0))
|
||||||
|
session = podmanTest.Podman([]string{"manifest", "push", "--rm", "bar", "dir:" + dest})
|
||||||
|
session.WaitWithDefaultTimeout()
|
||||||
|
Expect(session).Should(Exit(0))
|
||||||
|
session = podmanTest.Podman([]string{"images", "-q", "bar"})
|
||||||
|
session.WaitWithDefaultTimeout()
|
||||||
|
Expect(session).Should(Exit(0))
|
||||||
|
Expect(podmanTest.NumberOfContainersRunning()).To(Equal(0))
|
||||||
|
|
||||||
|
session = podmanTest.Podman([]string{"manifest", "rm", "foo", "bar"})
|
||||||
|
session.WaitWithDefaultTimeout()
|
||||||
|
Expect(session).Should(ExitWithError())
|
||||||
|
Expect(session.ErrorToString()).To(ContainSubstring("foo: image not known"))
|
||||||
|
Expect(session.ErrorToString()).To(ContainSubstring("bar: image not known"))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("exists", func() {
|
It("exists", func() {
|
||||||
|
Reference in New Issue
Block a user