mirror of
https://github.com/containers/podman.git
synced 2025-08-06 19:44:14 +08:00
Merge pull request #2156 from baude/remotermi
podman remote client -- add rmi
This commit is contained in:
@ -4,8 +4,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/containers/libpod/cmd/podman/libpodruntime"
|
"github.com/containers/libpod/libpod/adapter"
|
||||||
"github.com/containers/libpod/libpod/image"
|
|
||||||
"github.com/containers/storage"
|
"github.com/containers/storage"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
@ -58,11 +57,11 @@ func rmiCmd(c *cli.Context) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
removeAll := c.Bool("all")
|
removeAll := c.Bool("all")
|
||||||
runtime, err := libpodruntime.GetRuntime(c)
|
runtime, err := adapter.GetRuntime(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "could not get runtime")
|
return errors.Wrapf(err, "could not get runtime")
|
||||||
}
|
}
|
||||||
defer runtime.Shutdown(false)
|
defer runtime.Runtime.Shutdown(false)
|
||||||
|
|
||||||
args := c.Args()
|
args := c.Args()
|
||||||
if len(args) == 0 && !removeAll {
|
if len(args) == 0 && !removeAll {
|
||||||
@ -74,7 +73,7 @@ func rmiCmd(c *cli.Context) error {
|
|||||||
|
|
||||||
images := args[:]
|
images := args[:]
|
||||||
|
|
||||||
removeImage := func(img *image.Image) {
|
removeImage := func(img *adapter.ContainerImage) {
|
||||||
deleted = true
|
deleted = true
|
||||||
msg, deleteErr = runtime.RemoveImage(ctx, img, c.Bool("force"))
|
msg, deleteErr = runtime.RemoveImage(ctx, img, c.Bool("force"))
|
||||||
if deleteErr != nil {
|
if deleteErr != nil {
|
||||||
@ -91,8 +90,8 @@ func rmiCmd(c *cli.Context) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if removeAll {
|
if removeAll {
|
||||||
var imagesToDelete []*image.Image
|
var imagesToDelete []*adapter.ContainerImage
|
||||||
imagesToDelete, err = runtime.ImageRuntime().GetImages()
|
imagesToDelete, err = runtime.GetImages()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "unable to query local images")
|
return errors.Wrapf(err, "unable to query local images")
|
||||||
}
|
}
|
||||||
@ -112,7 +111,7 @@ func rmiCmd(c *cli.Context) error {
|
|||||||
removeImage(i)
|
removeImage(i)
|
||||||
}
|
}
|
||||||
lastNumberofImages = len(imagesToDelete)
|
lastNumberofImages = len(imagesToDelete)
|
||||||
imagesToDelete, err = runtime.ImageRuntime().GetImages()
|
imagesToDelete, err = runtime.GetImages()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -130,7 +129,7 @@ func rmiCmd(c *cli.Context) error {
|
|||||||
// See https://github.com/containers/libpod/issues/930 as
|
// See https://github.com/containers/libpod/issues/930 as
|
||||||
// an exemplary inconsistency issue.
|
// an exemplary inconsistency issue.
|
||||||
for _, i := range images {
|
for _, i := range images {
|
||||||
newImage, err := runtime.ImageRuntime().NewFromLocal(i)
|
newImage, err := runtime.NewImageFromLocal(i)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintln(os.Stderr, err)
|
fmt.Fprintln(os.Stderr, err)
|
||||||
continue
|
continue
|
||||||
|
@ -80,3 +80,8 @@ func (r *LocalRuntime) New(ctx context.Context, name, signaturePolicyPath, authf
|
|||||||
}
|
}
|
||||||
return &ContainerImage{img}, nil
|
return &ContainerImage{img}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RemoveImage calls into local storage and removes an image
|
||||||
|
func (r *LocalRuntime) RemoveImage(ctx context.Context, img *ContainerImage, force bool) (string, error) {
|
||||||
|
return r.Runtime.RemoveImage(ctx, img.Image, force)
|
||||||
|
}
|
||||||
|
@ -216,3 +216,8 @@ func (ci *ContainerImage) TagImage(tag string) error {
|
|||||||
func (r RemoteRuntime) RemoveImage(force bool) error {
|
func (r RemoteRuntime) RemoveImage(force bool) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RemoveImage calls varlink to remove an image
|
||||||
|
func (r *LocalRuntime) RemoveImage(ctx context.Context, img *ContainerImage, force bool) (string, error) {
|
||||||
|
return iopodman.RemoveImage().Call(r.Conn, img.InputName, force)
|
||||||
|
}
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
// +build !remoteclient
|
|
||||||
|
|
||||||
package integration
|
package integration
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@ -51,6 +49,7 @@ var _ = Describe("Podman image|container exists", func() {
|
|||||||
Expect(session.ExitCode()).To(Equal(1))
|
Expect(session.ExitCode()).To(Equal(1))
|
||||||
})
|
})
|
||||||
It("podman container exists in local storage by name", func() {
|
It("podman container exists in local storage by name", func() {
|
||||||
|
SkipIfRemote()
|
||||||
setup := podmanTest.RunTopContainer("foobar")
|
setup := podmanTest.RunTopContainer("foobar")
|
||||||
setup.WaitWithDefaultTimeout()
|
setup.WaitWithDefaultTimeout()
|
||||||
Expect(setup.ExitCode()).To(Equal(0))
|
Expect(setup.ExitCode()).To(Equal(0))
|
||||||
@ -60,6 +59,7 @@ var _ = Describe("Podman image|container exists", func() {
|
|||||||
Expect(session.ExitCode()).To(Equal(0))
|
Expect(session.ExitCode()).To(Equal(0))
|
||||||
})
|
})
|
||||||
It("podman container exists in local storage by container ID", func() {
|
It("podman container exists in local storage by container ID", func() {
|
||||||
|
SkipIfRemote()
|
||||||
setup := podmanTest.RunTopContainer("")
|
setup := podmanTest.RunTopContainer("")
|
||||||
setup.WaitWithDefaultTimeout()
|
setup.WaitWithDefaultTimeout()
|
||||||
Expect(setup.ExitCode()).To(Equal(0))
|
Expect(setup.ExitCode()).To(Equal(0))
|
||||||
@ -70,6 +70,7 @@ var _ = Describe("Podman image|container exists", func() {
|
|||||||
Expect(session.ExitCode()).To(Equal(0))
|
Expect(session.ExitCode()).To(Equal(0))
|
||||||
})
|
})
|
||||||
It("podman container exists in local storage by short container ID", func() {
|
It("podman container exists in local storage by short container ID", func() {
|
||||||
|
SkipIfRemote()
|
||||||
setup := podmanTest.RunTopContainer("")
|
setup := podmanTest.RunTopContainer("")
|
||||||
setup.WaitWithDefaultTimeout()
|
setup.WaitWithDefaultTimeout()
|
||||||
Expect(setup.ExitCode()).To(Equal(0))
|
Expect(setup.ExitCode()).To(Equal(0))
|
||||||
@ -80,12 +81,14 @@ var _ = Describe("Podman image|container exists", func() {
|
|||||||
Expect(session.ExitCode()).To(Equal(0))
|
Expect(session.ExitCode()).To(Equal(0))
|
||||||
})
|
})
|
||||||
It("podman container does not exist in local storage", func() {
|
It("podman container does not exist in local storage", func() {
|
||||||
|
SkipIfRemote()
|
||||||
session := podmanTest.Podman([]string{"container", "exists", "foobar"})
|
session := podmanTest.Podman([]string{"container", "exists", "foobar"})
|
||||||
session.WaitWithDefaultTimeout()
|
session.WaitWithDefaultTimeout()
|
||||||
Expect(session.ExitCode()).To(Equal(1))
|
Expect(session.ExitCode()).To(Equal(1))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("podman pod exists in local storage by name", func() {
|
It("podman pod exists in local storage by name", func() {
|
||||||
|
SkipIfRemote()
|
||||||
setup, rc, _ := podmanTest.CreatePod("foobar")
|
setup, rc, _ := podmanTest.CreatePod("foobar")
|
||||||
setup.WaitWithDefaultTimeout()
|
setup.WaitWithDefaultTimeout()
|
||||||
Expect(rc).To(Equal(0))
|
Expect(rc).To(Equal(0))
|
||||||
@ -95,6 +98,7 @@ var _ = Describe("Podman image|container exists", func() {
|
|||||||
Expect(session.ExitCode()).To(Equal(0))
|
Expect(session.ExitCode()).To(Equal(0))
|
||||||
})
|
})
|
||||||
It("podman pod exists in local storage by container ID", func() {
|
It("podman pod exists in local storage by container ID", func() {
|
||||||
|
SkipIfRemote()
|
||||||
setup, rc, podID := podmanTest.CreatePod("")
|
setup, rc, podID := podmanTest.CreatePod("")
|
||||||
setup.WaitWithDefaultTimeout()
|
setup.WaitWithDefaultTimeout()
|
||||||
Expect(rc).To(Equal(0))
|
Expect(rc).To(Equal(0))
|
||||||
@ -104,6 +108,7 @@ var _ = Describe("Podman image|container exists", func() {
|
|||||||
Expect(session.ExitCode()).To(Equal(0))
|
Expect(session.ExitCode()).To(Equal(0))
|
||||||
})
|
})
|
||||||
It("podman pod exists in local storage by short container ID", func() {
|
It("podman pod exists in local storage by short container ID", func() {
|
||||||
|
SkipIfRemote()
|
||||||
setup, rc, podID := podmanTest.CreatePod("")
|
setup, rc, podID := podmanTest.CreatePod("")
|
||||||
setup.WaitWithDefaultTimeout()
|
setup.WaitWithDefaultTimeout()
|
||||||
Expect(rc).To(Equal(0))
|
Expect(rc).To(Equal(0))
|
||||||
@ -113,6 +118,7 @@ var _ = Describe("Podman image|container exists", func() {
|
|||||||
Expect(session.ExitCode()).To(Equal(0))
|
Expect(session.ExitCode()).To(Equal(0))
|
||||||
})
|
})
|
||||||
It("podman pod does not exist in local storage", func() {
|
It("podman pod does not exist in local storage", func() {
|
||||||
|
SkipIfRemote()
|
||||||
session := podmanTest.Podman([]string{"pod", "exists", "foobar"})
|
session := podmanTest.Podman([]string{"pod", "exists", "foobar"})
|
||||||
session.WaitWithDefaultTimeout()
|
session.WaitWithDefaultTimeout()
|
||||||
Expect(session.ExitCode()).To(Equal(1))
|
Expect(session.ExitCode()).To(Equal(1))
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"github.com/containers/libpod/libpod"
|
"github.com/containers/libpod/libpod"
|
||||||
"github.com/containers/libpod/pkg/inspect"
|
"github.com/containers/libpod/pkg/inspect"
|
||||||
|
"github.com/onsi/ginkgo"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
@ -13,13 +14,16 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func SkipIfRemote() {
|
||||||
|
ginkgo.Skip("This function is not enabled for remote podman")
|
||||||
|
}
|
||||||
|
|
||||||
// Cleanup cleans up the temporary store
|
// Cleanup cleans up the temporary store
|
||||||
func (p *PodmanTestIntegration) Cleanup() {
|
func (p *PodmanTestIntegration) Cleanup() {
|
||||||
p.StopVarlink()
|
p.StopVarlink()
|
||||||
// TODO
|
// TODO
|
||||||
// Stop all containers
|
// Stop all containers
|
||||||
// Rm all containers
|
// Rm all containers
|
||||||
// Rm all images
|
|
||||||
|
|
||||||
if err := os.RemoveAll(p.TempDir); err != nil {
|
if err := os.RemoveAll(p.TempDir); err != nil {
|
||||||
fmt.Printf("%q\n", err)
|
fmt.Printf("%q\n", err)
|
||||||
|
@ -19,6 +19,8 @@ import (
|
|||||||
"github.com/onsi/gomega/gexec"
|
"github.com/onsi/gomega/gexec"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func SkipIfRemote() {}
|
||||||
|
|
||||||
// Podman is the exec call to podman on the filesystem
|
// Podman is the exec call to podman on the filesystem
|
||||||
func (p *PodmanTestIntegration) Podman(args []string) *PodmanSessionIntegration {
|
func (p *PodmanTestIntegration) Podman(args []string) *PodmanSessionIntegration {
|
||||||
podmanSession := p.PodmanBase(args)
|
podmanSession := p.PodmanBase(args)
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
// +build !remoteclient
|
|
||||||
|
|
||||||
package integration
|
package integration
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@ -113,6 +111,7 @@ var _ = Describe("Podman rmi", func() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
It("podman rmi image that is a parent of another image", func() {
|
It("podman rmi image that is a parent of another image", func() {
|
||||||
|
SkipIfRemote()
|
||||||
session := podmanTest.Podman([]string{"rmi", "-fa"})
|
session := podmanTest.Podman([]string{"rmi", "-fa"})
|
||||||
session.WaitWithDefaultTimeout()
|
session.WaitWithDefaultTimeout()
|
||||||
Expect(session.ExitCode()).To(Equal(0))
|
Expect(session.ExitCode()).To(Equal(0))
|
||||||
@ -150,6 +149,7 @@ var _ = Describe("Podman rmi", func() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
It("podman rmi image that is created from another named imaged", func() {
|
It("podman rmi image that is created from another named imaged", func() {
|
||||||
|
SkipIfRemote()
|
||||||
session := podmanTest.Podman([]string{"rmi", "-fa"})
|
session := podmanTest.Podman([]string{"rmi", "-fa"})
|
||||||
session.WaitWithDefaultTimeout()
|
session.WaitWithDefaultTimeout()
|
||||||
Expect(session.ExitCode()).To(Equal(0))
|
Expect(session.ExitCode()).To(Equal(0))
|
||||||
@ -185,6 +185,7 @@ var _ = Describe("Podman rmi", func() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
It("podman rmi with cached images", func() {
|
It("podman rmi with cached images", func() {
|
||||||
|
SkipIfRemote()
|
||||||
session := podmanTest.Podman([]string{"rmi", "-fa"})
|
session := podmanTest.Podman([]string{"rmi", "-fa"})
|
||||||
session.WaitWithDefaultTimeout()
|
session.WaitWithDefaultTimeout()
|
||||||
Expect(session.ExitCode()).To(Equal(0))
|
Expect(session.ExitCode()).To(Equal(0))
|
||||||
@ -254,6 +255,7 @@ var _ = Describe("Podman rmi", func() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
It("podman rmi -a with parent|child images", func() {
|
It("podman rmi -a with parent|child images", func() {
|
||||||
|
SkipIfRemote()
|
||||||
dockerfile := `FROM docker.io/library/alpine:latest AS base
|
dockerfile := `FROM docker.io/library/alpine:latest AS base
|
||||||
RUN touch /1
|
RUN touch /1
|
||||||
ENV LOCAL=/1
|
ENV LOCAL=/1
|
||||||
|
Reference in New Issue
Block a user