mirror of https://github.com/containers/podman.git
V2 podman image
* Exists() Signed-off-by: Jhon Honce <jhonce@redhat.com>
This commit is contained in:
parent
ff0124aee1
commit
36a4cc864d
|
@ -0,0 +1,40 @@
|
||||||
|
package images
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/containers/libpod/cmd/podmanV2/registry"
|
||||||
|
"github.com/containers/libpod/pkg/domain/entities"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
existsCmd = &cobra.Command{
|
||||||
|
Use: "exists IMAGE",
|
||||||
|
Short: "Check if an image exists in local storage",
|
||||||
|
Long: `If the named image exists in local storage, podman image exists exits with 0, otherwise the exit code will be 1.`,
|
||||||
|
Example: `podman image exists ID
|
||||||
|
podman image exists IMAGE && podman pull IMAGE`,
|
||||||
|
Args: cobra.ExactArgs(1),
|
||||||
|
RunE: exists,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
registry.Commands = append(registry.Commands, registry.CliCommand{
|
||||||
|
Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode},
|
||||||
|
Command: existsCmd,
|
||||||
|
Parent: imageCmd,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func exists(cmd *cobra.Command, args []string) error {
|
||||||
|
found, err := registry.ImageEngine().Exists(registry.GetContext(), args[0])
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if !found.Value {
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
|
@ -6,6 +6,7 @@ import (
|
||||||
|
|
||||||
type ImageEngine interface {
|
type ImageEngine interface {
|
||||||
Delete(ctx context.Context, nameOrId string, opts ImageDeleteOptions) (*ImageDeleteReport, error)
|
Delete(ctx context.Context, nameOrId string, opts ImageDeleteOptions) (*ImageDeleteReport, error)
|
||||||
|
Exists(ctx context.Context, nameOrId string) (*BoolReport, error)
|
||||||
History(ctx context.Context, nameOrId string, opts ImageHistoryOptions) (*ImageHistoryReport, error)
|
History(ctx context.Context, nameOrId string, opts ImageHistoryOptions) (*ImageHistoryReport, error)
|
||||||
List(ctx context.Context, opts ImageListOptions) ([]*ImageSummary, error)
|
List(ctx context.Context, opts ImageListOptions) ([]*ImageSummary, error)
|
||||||
Prune(ctx context.Context, opts ImagePruneOptions) (*ImagePruneReport, error)
|
Prune(ctx context.Context, opts ImagePruneOptions) (*ImagePruneReport, error)
|
||||||
|
|
|
@ -10,6 +10,13 @@ import (
|
||||||
"github.com/containers/libpod/pkg/domain/utils"
|
"github.com/containers/libpod/pkg/domain/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func (ir *ImageEngine) Exists(_ context.Context, nameOrId string) (*entities.BoolReport, error) {
|
||||||
|
if _, err := ir.Libpod.ImageRuntime().NewFromLocal(nameOrId); err != nil {
|
||||||
|
return &entities.BoolReport{}, nil
|
||||||
|
}
|
||||||
|
return &entities.BoolReport{Value: true}, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (ir *ImageEngine) Delete(ctx context.Context, nameOrId string, opts entities.ImageDeleteOptions) (*entities.ImageDeleteReport, error) {
|
func (ir *ImageEngine) Delete(ctx context.Context, nameOrId string, opts entities.ImageDeleteOptions) (*entities.ImageDeleteReport, error) {
|
||||||
image, err := ir.Libpod.ImageRuntime().NewFromLocal(nameOrId)
|
image, err := ir.Libpod.ImageRuntime().NewFromLocal(nameOrId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -9,6 +9,11 @@ import (
|
||||||
"github.com/containers/libpod/pkg/domain/utils"
|
"github.com/containers/libpod/pkg/domain/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func (ir *ImageEngine) Exists(_ context.Context, nameOrId string) (*entities.BoolReport, error) {
|
||||||
|
found, err := images.Exists(ir.ClientCxt, nameOrId)
|
||||||
|
return &entities.BoolReport{Value: found}, err
|
||||||
|
}
|
||||||
|
|
||||||
func (ir *ImageEngine) Delete(ctx context.Context, nameOrId string, opts entities.ImageDeleteOptions) (*entities.ImageDeleteReport, error) {
|
func (ir *ImageEngine) Delete(ctx context.Context, nameOrId string, opts entities.ImageDeleteOptions) (*entities.ImageDeleteReport, error) {
|
||||||
results, err := images.Remove(ir.ClientCxt, nameOrId, &opts.Force)
|
results, err := images.Remove(ir.ClientCxt, nameOrId, &opts.Force)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue