summaryrefslogtreecommitdiff
path: root/cmd/podmanV2/images
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/podmanV2/images')
-rw-r--r--cmd/podmanV2/images/history.go79
-rw-r--r--cmd/podmanV2/images/image.go33
-rw-r--r--cmd/podmanV2/images/images.go46
-rw-r--r--cmd/podmanV2/images/inspect.go124
-rw-r--r--cmd/podmanV2/images/list.go33
5 files changed, 315 insertions, 0 deletions
diff --git a/cmd/podmanV2/images/history.go b/cmd/podmanV2/images/history.go
new file mode 100644
index 000000000..c75ae6ddc
--- /dev/null
+++ b/cmd/podmanV2/images/history.go
@@ -0,0 +1,79 @@
+package images
+
+import (
+ "context"
+ "fmt"
+ "os"
+ "text/tabwriter"
+ "text/template"
+
+ "github.com/containers/libpod/cmd/podmanV2/registry"
+ "github.com/containers/libpod/cmd/podmanV2/report"
+ "github.com/containers/libpod/pkg/domain/entities"
+ "github.com/pkg/errors"
+ "github.com/spf13/cobra"
+)
+
+var (
+ long = `Displays the history of an image.
+
+ The information can be printed out in an easy to read, or user specified format, and can be truncated.`
+
+ // podman _history_
+ historyCmd = &cobra.Command{
+ Use: "history [flags] IMAGE",
+ Short: "Show history of a specified image",
+ Long: long,
+ Example: "podman history quay.io/fedora/fedora",
+ Args: cobra.ExactArgs(1),
+ PersistentPreRunE: preRunE,
+ RunE: history,
+ }
+)
+
+var cmdFlags = struct {
+ Human bool
+ NoTrunc bool
+ Quiet bool
+ Format string
+}{}
+
+func init() {
+ registry.Commands = append(registry.Commands, registry.CliCommand{
+ Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode},
+ Command: historyCmd,
+ })
+
+ historyCmd.SetHelpTemplate(registry.HelpTemplate())
+ historyCmd.SetUsageTemplate(registry.UsageTemplate())
+ flags := historyCmd.Flags()
+ flags.StringVar(&cmdFlags.Format, "format", "", "Change the output to JSON or a Go template")
+ flags.BoolVarP(&cmdFlags.Human, "human", "H", true, "Display sizes and dates in human readable format")
+ flags.BoolVar(&cmdFlags.NoTrunc, "no-trunc", false, "Do not truncate the output")
+ flags.BoolVar(&cmdFlags.NoTrunc, "notruncate", false, "Do not truncate the output")
+ flags.BoolVarP(&cmdFlags.Quiet, "quiet", "q", false, "Display the numeric IDs only")
+}
+
+func history(cmd *cobra.Command, args []string) error {
+ results, err := registry.ImageEngine().History(context.Background(), args[0], entities.ImageHistoryOptions{})
+ if err != nil {
+ return err
+ }
+
+ row := "{{slice $x.ID 0 12}}\t{{toRFC3339 $x.Created}}\t{{ellipsis $x.CreatedBy 45}}\t{{$x.Size}}\t{{$x.Comment}}\n"
+ if cmdFlags.Human {
+ row = "{{slice $x.ID 0 12}}\t{{toHumanDuration $x.Created}}\t{{ellipsis $x.CreatedBy 45}}\t{{toHumanSize $x.Size}}\t{{$x.Comment}}\n"
+ }
+ format := "{{range $y, $x := . }}" + row + "{{end}}"
+
+ tmpl := template.Must(template.New("report").Funcs(report.PodmanTemplateFuncs()).Parse(format))
+ w := tabwriter.NewWriter(os.Stdout, 8, 2, 2, ' ', 0)
+
+ _, _ = w.Write(report.ReportHeader("id", "created", "created by", "size", "comment"))
+ err = tmpl.Execute(w, results.Layers)
+ if err != nil {
+ fmt.Fprintln(os.Stderr, errors.Wrapf(err, "Failed to print report"))
+ }
+ w.Flush()
+ return nil
+}
diff --git a/cmd/podmanV2/images/image.go b/cmd/podmanV2/images/image.go
new file mode 100644
index 000000000..a15c3e826
--- /dev/null
+++ b/cmd/podmanV2/images/image.go
@@ -0,0 +1,33 @@
+package images
+
+import (
+ "github.com/containers/libpod/cmd/podmanV2/registry"
+ "github.com/containers/libpod/pkg/domain/entities"
+ "github.com/spf13/cobra"
+)
+
+var (
+ // Command: podman _image_
+ imageCmd = &cobra.Command{
+ Use: "image",
+ Short: "Manage images",
+ Long: "Manage images",
+ TraverseChildren: true,
+ PersistentPreRunE: preRunE,
+ RunE: registry.SubCommandExists,
+ }
+)
+
+func init() {
+ registry.Commands = append(registry.Commands, registry.CliCommand{
+ Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode},
+ Command: imageCmd,
+ })
+ imageCmd.SetHelpTemplate(registry.HelpTemplate())
+ imageCmd.SetUsageTemplate(registry.UsageTemplate())
+}
+
+func preRunE(cmd *cobra.Command, args []string) error {
+ _, err := registry.NewImageEngine(cmd, args)
+ return err
+}
diff --git a/cmd/podmanV2/images/images.go b/cmd/podmanV2/images/images.go
new file mode 100644
index 000000000..a1e56396a
--- /dev/null
+++ b/cmd/podmanV2/images/images.go
@@ -0,0 +1,46 @@
+package images
+
+import (
+ "strings"
+
+ "github.com/containers/libpod/cmd/podmanV2/registry"
+ "github.com/containers/libpod/pkg/domain/entities"
+ "github.com/spf13/cobra"
+)
+
+var (
+ // podman _images_
+ imagesCmd = &cobra.Command{
+ Use: strings.Replace(listCmd.Use, "list", "images", 1),
+ Short: listCmd.Short,
+ Long: listCmd.Long,
+ PersistentPreRunE: preRunE,
+ RunE: images,
+ Example: strings.Replace(listCmd.Example, "podman image list", "podman images", -1),
+ }
+
+ imagesOpts = entities.ImageListOptions{}
+)
+
+func init() {
+ registry.Commands = append(registry.Commands, registry.CliCommand{
+ Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode},
+ Command: imagesCmd,
+ })
+ imagesCmd.SetHelpTemplate(registry.HelpTemplate())
+ imagesCmd.SetUsageTemplate(registry.UsageTemplate())
+
+ flags := imagesCmd.Flags()
+ flags.BoolVarP(&imagesOpts.All, "all", "a", false, "Show all images (default hides intermediate images)")
+ flags.BoolVar(&imagesOpts.Digests, "digests", false, "Show digests")
+ flags.StringSliceVarP(&imagesOpts.Filter, "filter", "f", []string{}, "Filter output based on conditions provided (default [])")
+ flags.StringVar(&imagesOpts.Format, "format", "", "Change the output format to JSON or a Go template")
+ flags.BoolVarP(&imagesOpts.Noheading, "noheading", "n", false, "Do not print column headings")
+ // TODO Need to learn how to deal with second name being a string instead of a char.
+ // This needs to be "no-trunc, notruncate"
+ flags.BoolVar(&imagesOpts.NoTrunc, "no-trunc", false, "Do not truncate output")
+ flags.BoolVar(&imagesOpts.NoTrunc, "notruncate", false, "Do not truncate output")
+ flags.BoolVarP(&imagesOpts.Quiet, "quiet", "q", false, "Display only image IDs")
+ flags.StringVar(&imagesOpts.Sort, "sort", "created", "Sort by created, id, repository, size, or tag")
+ flags.BoolVarP(&imagesOpts.History, "history", "", false, "Display the image name history")
+}
diff --git a/cmd/podmanV2/images/inspect.go b/cmd/podmanV2/images/inspect.go
new file mode 100644
index 000000000..9c44cea35
--- /dev/null
+++ b/cmd/podmanV2/images/inspect.go
@@ -0,0 +1,124 @@
+package images
+
+import (
+ "strings"
+
+ "github.com/containers/buildah/pkg/formats"
+ "github.com/containers/libpod/cmd/podmanV2/registry"
+ "github.com/containers/libpod/pkg/domain/entities"
+ "github.com/containers/libpod/pkg/util"
+ "github.com/pkg/errors"
+ "github.com/spf13/cobra"
+)
+
+var (
+ inspectOpts = entities.ImageInspectOptions{}
+
+ // Command: podman image _inspect_
+ inspectCmd = &cobra.Command{
+ Use: "inspect [flags] IMAGE",
+ Short: "Display the configuration of an image",
+ Long: `Displays the low-level information on an image identified by name or ID.`,
+ PreRunE: populateEngines,
+ RunE: imageInspect,
+ Example: `podman image inspect alpine`,
+ }
+
+ containerEngine entities.ContainerEngine
+)
+
+// Inspect is unique in that it needs both an ImageEngine and a ContainerEngine
+func populateEngines(cmd *cobra.Command, args []string) (err error) {
+ // Populate registry.ImageEngine
+ err = preRunE(cmd, args)
+ if err != nil {
+ return
+ }
+
+ // Populate registry.ContainerEngine
+ containerEngine, err = registry.NewContainerEngine(cmd, args)
+ return
+}
+
+func init() {
+ registry.Commands = append(registry.Commands, registry.CliCommand{
+ Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode},
+ Command: inspectCmd,
+ Parent: imageCmd,
+ })
+
+ flags := inspectCmd.Flags()
+ flags.BoolVarP(&inspectOpts.Latest, "latest", "l", false, "Act on the latest container podman is aware of")
+ flags.BoolVarP(&inspectOpts.Size, "size", "s", false, "Display total file size")
+ flags.StringVarP(&inspectOpts.Format, "format", "f", "", "Change the output format to a Go template")
+
+ if registry.GlobalFlags.EngineMode == entities.ABIMode {
+ // TODO: This is the same as V1. We could skip creating the flag altogether in V2...
+ _ = flags.MarkHidden("latest")
+ }
+}
+
+const (
+ inspectTypeContainer = "container"
+ inspectTypeImage = "image"
+ inspectAll = "all"
+)
+
+func imageInspect(cmd *cobra.Command, args []string) error {
+ inspectType := inspectTypeImage
+ latestContainer := inspectOpts.Latest
+
+ if len(args) == 0 && !latestContainer {
+ return errors.Errorf("container or image name must be specified: podman inspect [options [...]] name")
+ }
+
+ if len(args) > 0 && latestContainer {
+ return errors.Errorf("you cannot provide additional arguments with --latest")
+ }
+
+ if !util.StringInSlice(inspectType, []string{inspectTypeContainer, inspectTypeImage, inspectAll}) {
+ return errors.Errorf("the only recognized types are %q, %q, and %q", inspectTypeContainer, inspectTypeImage, inspectAll)
+ }
+
+ outputFormat := inspectOpts.Format
+ if strings.Contains(outputFormat, "{{.Id}}") {
+ outputFormat = strings.Replace(outputFormat, "{{.Id}}", formats.IDString, -1)
+ }
+ // These fields were renamed, so we need to provide backward compat for
+ // the old names.
+ if strings.Contains(outputFormat, ".Src") {
+ outputFormat = strings.Replace(outputFormat, ".Src", ".Source", -1)
+ }
+ if strings.Contains(outputFormat, ".Dst") {
+ outputFormat = strings.Replace(outputFormat, ".Dst", ".Destination", -1)
+ }
+ if strings.Contains(outputFormat, ".ImageID") {
+ outputFormat = strings.Replace(outputFormat, ".ImageID", ".Image", -1)
+ }
+ _ = outputFormat
+ // if latestContainer {
+ // lc, err := ctnrRuntime.GetLatestContainer()
+ // if err != nil {
+ // return err
+ // }
+ // args = append(args, lc.ID())
+ // inspectType = inspectTypeContainer
+ // }
+
+ // inspectedObjects, iterateErr := iterateInput(getContext(), c.Size, args, runtime, inspectType)
+ // if iterateErr != nil {
+ // return iterateErr
+ // }
+ //
+ // var out formats.Writer
+ // if outputFormat != "" && outputFormat != formats.JSONString {
+ // // template
+ // out = formats.StdoutTemplateArray{Output: inspectedObjects, Template: outputFormat}
+ // } else {
+ // // default is json output
+ // out = formats.JSONStructArray{Output: inspectedObjects}
+ // }
+ //
+ // return out.Out()
+ return nil
+}
diff --git a/cmd/podmanV2/images/list.go b/cmd/podmanV2/images/list.go
new file mode 100644
index 000000000..cfdfaaed2
--- /dev/null
+++ b/cmd/podmanV2/images/list.go
@@ -0,0 +1,33 @@
+package images
+
+import (
+ "github.com/containers/libpod/cmd/podmanV2/registry"
+ "github.com/containers/libpod/pkg/domain/entities"
+ "github.com/spf13/cobra"
+)
+
+var (
+ // Command: podman image _list_
+ listCmd = &cobra.Command{
+ Use: "list [flag] [IMAGE]",
+ Aliases: []string{"ls"},
+ Short: "List images in local storage",
+ Long: "Lists images previously pulled to the system or created on the system.",
+ RunE: images,
+ Example: `podman image list --format json
+ podman image list --sort repository --format "table {{.ID}} {{.Repository}} {{.Tag}}"
+ podman image list --filter dangling=true`,
+ }
+)
+
+func init() {
+ registry.Commands = append(registry.Commands, registry.CliCommand{
+ Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode},
+ Command: listCmd,
+ Parent: imageCmd,
+ })
+}
+
+func images(cmd *cobra.Command, args []string) error {
+ return nil
+}