summaryrefslogtreecommitdiff
path: root/cmd/podmanV2/images
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/podmanV2/images')
-rw-r--r--cmd/podmanV2/images/exists.go40
-rw-r--r--cmd/podmanV2/images/history.go123
-rw-r--r--cmd/podmanV2/images/image.go35
-rw-r--r--cmd/podmanV2/images/images.go33
-rw-r--r--cmd/podmanV2/images/import.go87
-rw-r--r--cmd/podmanV2/images/inspect.go109
-rw-r--r--cmd/podmanV2/images/list.go243
-rw-r--r--cmd/podmanV2/images/load.go61
-rw-r--r--cmd/podmanV2/images/prune.go86
-rw-r--r--cmd/podmanV2/images/pull.go140
-rw-r--r--cmd/podmanV2/images/rm.go70
-rw-r--r--cmd/podmanV2/images/rmi.go30
-rw-r--r--cmd/podmanV2/images/tag.go34
-rw-r--r--cmd/podmanV2/images/untag.go33
14 files changed, 0 insertions, 1124 deletions
diff --git a/cmd/podmanV2/images/exists.go b/cmd/podmanV2/images/exists.go
deleted file mode 100644
index d35d6825e..000000000
--- a/cmd/podmanV2/images/exists.go
+++ /dev/null
@@ -1,40 +0,0 @@
-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.`,
- Args: cobra.ExactArgs(1),
- RunE: exists,
- Example: `podman image exists ID
- podman image exists IMAGE && podman pull IMAGE`,
- }
-)
-
-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
-}
diff --git a/cmd/podmanV2/images/history.go b/cmd/podmanV2/images/history.go
deleted file mode 100644
index f6f15e2f2..000000000
--- a/cmd/podmanV2/images/history.go
+++ /dev/null
@@ -1,123 +0,0 @@
-package images
-
-import (
- "context"
- "fmt"
- "os"
- "strings"
- "text/tabwriter"
- "text/template"
- "time"
-
- "github.com/containers/libpod/cmd/podmanV2/registry"
- "github.com/containers/libpod/cmd/podmanV2/report"
- "github.com/containers/libpod/pkg/domain/entities"
- jsoniter "github.com/json-iterator/go"
- "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,
- }
-
- opts = 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(&opts.format, "format", "", "Change the output to JSON or a Go template")
- flags.BoolVarP(&opts.human, "human", "H", false, "Display sizes and dates in human readable format")
- flags.BoolVar(&opts.noTrunc, "no-trunc", false, "Do not truncate the output")
- flags.BoolVar(&opts.noTrunc, "notruncate", false, "Do not truncate the output")
- flags.BoolVarP(&opts.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
- }
-
- if opts.format == "json" {
- var err error
- if len(results.Layers) == 0 {
- _, err = fmt.Fprintf(os.Stdout, "[]\n")
- } else {
- // ah-hoc change to "Created": type and format
- type layer struct {
- entities.ImageHistoryLayer
- Created string `json:"Created"`
- }
-
- layers := make([]layer, len(results.Layers))
- for i, l := range results.Layers {
- layers[i].ImageHistoryLayer = l
- layers[i].Created = time.Unix(l.Created, 0).Format(time.RFC3339)
- }
- json := jsoniter.ConfigCompatibleWithStandardLibrary
- enc := json.NewEncoder(os.Stdout)
- err = enc.Encode(layers)
- }
- return err
- }
-
- // Defaults
- hdr := "ID\tCREATED\tCREATED BY\tSIZE\tCOMMENT\n"
- row := "{{slice .ID 0 12}}\t{{humanDuration .Created}}\t{{ellipsis .CreatedBy 45}}\t{{.Size}}\t{{.Comment}}\n"
-
- if len(opts.format) > 0 {
- hdr = ""
- row = opts.format
- if !strings.HasSuffix(opts.format, "\n") {
- row += "\n"
- }
- } else {
- switch {
- case opts.human:
- row = "{{slice .ID 0 12}}\t{{humanDuration .Created}}\t{{ellipsis .CreatedBy 45}}\t{{humanSize .Size}}\t{{.Comment}}\n"
- case opts.noTrunc:
- row = "{{.ID}}\t{{humanDuration .Created}}\t{{.CreatedBy}}\t{{humanSize .Size}}\t{{.Comment}}\n"
- case opts.quiet:
- hdr = ""
- row = "{{.ID}}\n"
- }
- }
- format := hdr + "{{range . }}" + 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
deleted file mode 100644
index 9fc7b21d1..000000000
--- a/cmd/podmanV2/images/image.go
+++ /dev/null
@@ -1,35 +0,0 @@
-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 {
- if _, err := registry.NewImageEngine(cmd, args); err != nil {
- return err
- }
- return nil
-}
diff --git a/cmd/podmanV2/images/images.go b/cmd/podmanV2/images/images.go
deleted file mode 100644
index d00f0996e..000000000
--- a/cmd/podmanV2/images/images.go
+++ /dev/null
@@ -1,33 +0,0 @@
-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_ Alias for podman image _list_
- imagesCmd = &cobra.Command{
- Use: strings.Replace(listCmd.Use, "list", "images", 1),
- Args: listCmd.Args,
- Short: listCmd.Short,
- Long: listCmd.Long,
- PreRunE: preRunE,
- RunE: listCmd.RunE,
- Example: strings.Replace(listCmd.Example, "podman image list", "podman images", -1),
- }
-)
-
-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())
-
- imageListFlagSet(imagesCmd.Flags())
-}
diff --git a/cmd/podmanV2/images/import.go b/cmd/podmanV2/images/import.go
deleted file mode 100644
index 09a15585f..000000000
--- a/cmd/podmanV2/images/import.go
+++ /dev/null
@@ -1,87 +0,0 @@
-package images
-
-import (
- "context"
- "fmt"
-
- "github.com/containers/libpod/cmd/podmanV2/parse"
- "github.com/containers/libpod/cmd/podmanV2/registry"
- "github.com/containers/libpod/pkg/domain/entities"
- "github.com/hashicorp/go-multierror"
- "github.com/pkg/errors"
- "github.com/spf13/cobra"
-)
-
-var (
- importDescription = `Create a container image from the contents of the specified tarball (.tar, .tar.gz, .tgz, .bzip, .tar.xz, .txz).
-
- Note remote tar balls can be specified, via web address.
- Optionally tag the image. You can specify the instructions using the --change option.`
- importCommand = &cobra.Command{
- Use: "import [flags] PATH [REFERENCE]",
- Short: "Import a tarball to create a filesystem image",
- Long: importDescription,
- RunE: importCon,
- PersistentPreRunE: preRunE,
- Example: `podman import http://example.com/ctr.tar url-image
- cat ctr.tar | podman -q import --message "importing the ctr.tar tarball" - image-imported
- cat ctr.tar | podman import -`,
- }
-)
-
-var (
- importOpts entities.ImageImportOptions
-)
-
-func init() {
- registry.Commands = append(registry.Commands, registry.CliCommand{
- Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode},
- Command: importCommand,
- })
-
- importCommand.SetHelpTemplate(registry.HelpTemplate())
- importCommand.SetUsageTemplate(registry.UsageTemplate())
- flags := importCommand.Flags()
- flags.StringArrayVarP(&importOpts.Changes, "change", "c", []string{}, "Apply the following possible instructions to the created image (default []): CMD | ENTRYPOINT | ENV | EXPOSE | LABEL | STOPSIGNAL | USER | VOLUME | WORKDIR")
- flags.StringVarP(&importOpts.Message, "message", "m", "", "Set commit message for imported image")
- flags.BoolVarP(&importOpts.Quiet, "quiet", "q", false, "Suppress output")
-}
-
-func importCon(cmd *cobra.Command, args []string) error {
- var (
- source string
- reference string
- )
- switch len(args) {
- case 0:
- return errors.Errorf("need to give the path to the tarball, or must specify a tarball of '-' for stdin")
- case 1:
- source = args[0]
- case 2:
- source = args[0]
- // TODO when save is merged, we need to process reference
- // like it is done in there or we end up with docker.io prepends
- // instead of the localhost ones
- reference = args[1]
- default:
- return errors.Errorf("too many arguments. Usage TARBALL [REFERENCE]")
- }
- errFileName := parse.ValidateFileName(source)
- errURL := parse.ValidURL(source)
- if errURL == nil {
- importOpts.SourceIsURL = true
- }
- if errFileName != nil && errURL != nil {
- return multierror.Append(errFileName, errURL)
- }
-
- importOpts.Source = source
- importOpts.Reference = reference
-
- response, err := registry.ImageEngine().Import(context.Background(), importOpts)
- if err != nil {
- return err
- }
- fmt.Println(response.Id)
- return nil
-}
diff --git a/cmd/podmanV2/images/inspect.go b/cmd/podmanV2/images/inspect.go
deleted file mode 100644
index d7f6b0ee1..000000000
--- a/cmd/podmanV2/images/inspect.go
+++ /dev/null
@@ -1,109 +0,0 @@
-package images
-
-import (
- "context"
- "encoding/json"
- "fmt"
- "os"
- "strings"
- "text/tabwriter"
- "text/template"
-
- "github.com/containers/buildah/pkg/formats"
- "github.com/containers/libpod/cmd/podmanV2/common"
- "github.com/containers/libpod/cmd/podmanV2/registry"
- "github.com/containers/libpod/pkg/domain/entities"
- "github.com/pkg/errors"
- "github.com/spf13/cobra"
-)
-
-var (
- // 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.`,
- RunE: inspect,
- Example: `podman image inspect alpine`,
- }
- inspectOpts *entities.InspectOptions
-)
-
-func init() {
- registry.Commands = append(registry.Commands, registry.CliCommand{
- Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode},
- Command: inspectCmd,
- Parent: imageCmd,
- })
- inspectOpts = common.AddInspectFlagSet(inspectCmd)
-}
-
-func inspect(cmd *cobra.Command, args []string) error {
- 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")
- }
-
- results, err := registry.ImageEngine().Inspect(context.Background(), args, *inspectOpts)
- if err != nil {
- return err
- }
-
- if len(results.Images) > 0 {
- if inspectOpts.Format == "" {
- buf, err := json.MarshalIndent(results.Images, "", " ")
- if err != nil {
- return err
- }
- fmt.Println(string(buf))
-
- for id, e := range results.Errors {
- fmt.Fprintf(os.Stderr, "%s: %s\n", id, e.Error())
- }
- return nil
- }
-
- row := inspectFormat(inspectOpts.Format)
- format := "{{range . }}" + row + "{{end}}"
- tmpl, err := template.New("inspect").Parse(format)
- if err != nil {
- return err
- }
-
- w := tabwriter.NewWriter(os.Stdout, 8, 2, 2, ' ', 0)
- defer func() { _ = w.Flush() }()
- err = tmpl.Execute(w, results)
- if err != nil {
- return err
- }
- }
-
- for id, e := range results.Errors {
- fmt.Fprintf(os.Stderr, "%s: %s\n", id, e.Error())
- }
- return nil
-}
-
-func inspectFormat(row string) string {
- r := strings.NewReplacer("{{.Id}}", formats.IDString,
- ".Src", ".Source",
- ".Dst", ".Destination",
- ".ImageID", ".Image",
- )
- row = r.Replace(row)
-
- if !strings.HasSuffix(row, "\n") {
- row += "\n"
- }
- return row
-}
-
-func Inspect(cmd *cobra.Command, args []string, options *entities.InspectOptions) error {
- inspectOpts = options
- return inspect(cmd, args)
-}
diff --git a/cmd/podmanV2/images/list.go b/cmd/podmanV2/images/list.go
deleted file mode 100644
index 2d6cb3596..000000000
--- a/cmd/podmanV2/images/list.go
+++ /dev/null
@@ -1,243 +0,0 @@
-package images
-
-import (
- "errors"
- "fmt"
- "os"
- "sort"
- "strings"
- "text/tabwriter"
- "text/template"
- "time"
-
- "github.com/containers/libpod/cmd/podmanV2/registry"
- "github.com/containers/libpod/cmd/podmanV2/report"
- "github.com/containers/libpod/pkg/domain/entities"
- jsoniter "github.com/json-iterator/go"
- "github.com/spf13/cobra"
- "github.com/spf13/pflag"
-)
-
-type listFlagType struct {
- format string
- history bool
- noHeading bool
- noTrunc bool
- quiet bool
- sort string
- readOnly bool
- digests bool
-}
-
-var (
- // Command: podman image _list_
- listCmd = &cobra.Command{
- Use: "list [flag] [IMAGE]",
- Aliases: []string{"ls"},
- Args: cobra.MaximumNArgs(1),
- 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`,
- }
-
- // Options to pull data
- listOptions = entities.ImageListOptions{}
-
- // Options for presenting data
- listFlag = listFlagType{}
-
- sortFields = entities.NewStringSet(
- "created",
- "id",
- "repository",
- "size",
- "tag")
-)
-
-func init() {
- registry.Commands = append(registry.Commands, registry.CliCommand{
- Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode},
- Command: listCmd,
- Parent: imageCmd,
- })
- imageListFlagSet(listCmd.Flags())
-}
-
-func imageListFlagSet(flags *pflag.FlagSet) {
- flags.BoolVarP(&listOptions.All, "all", "a", false, "Show all images (default hides intermediate images)")
- flags.StringSliceVarP(&listOptions.Filter, "filter", "f", []string{}, "Filter output based on conditions provided (default [])")
- flags.StringVar(&listFlag.format, "format", "", "Change the output format to JSON or a Go template")
- flags.BoolVar(&listFlag.digests, "digests", false, "Show digests")
- flags.BoolVarP(&listFlag.noHeading, "noheading", "n", false, "Do not print column headings")
- flags.BoolVar(&listFlag.noTrunc, "no-trunc", false, "Do not truncate output")
- flags.BoolVar(&listFlag.noTrunc, "notruncate", false, "Do not truncate output")
- flags.BoolVarP(&listFlag.quiet, "quiet", "q", false, "Display only image IDs")
- flags.StringVar(&listFlag.sort, "sort", "created", "Sort by "+sortFields.String())
- flags.BoolVarP(&listFlag.history, "history", "", false, "Display the image name history")
-}
-
-func images(cmd *cobra.Command, args []string) error {
- if len(listOptions.Filter) > 0 && len(args) > 0 {
- return errors.New("cannot specify an image and a filter(s)")
- }
-
- if len(listOptions.Filter) < 1 && len(args) > 0 {
- listOptions.Filter = append(listOptions.Filter, "reference="+args[0])
- }
-
- if cmd.Flag("sort").Changed && !sortFields.Contains(listFlag.sort) {
- return fmt.Errorf("\"%s\" is not a valid field for sorting. Choose from: %s",
- listFlag.sort, sortFields.String())
- }
-
- summaries, err := registry.ImageEngine().List(registry.GetContext(), listOptions)
- if err != nil {
- return err
- }
-
- imageS := summaries
- sort.Slice(imageS, sortFunc(listFlag.sort, imageS))
-
- if cmd.Flag("format").Changed && listFlag.format == "json" {
- return writeJSON(imageS)
- } else {
- return writeTemplate(imageS, err)
- }
-}
-
-func writeJSON(imageS []*entities.ImageSummary) error {
- type image struct {
- entities.ImageSummary
- Created string
- }
-
- imgs := make([]image, 0, len(imageS))
- for _, e := range imageS {
- var h image
- h.ImageSummary = *e
- h.Created = time.Unix(e.Created, 0).Format(time.RFC3339)
- h.RepoTags = nil
-
- imgs = append(imgs, h)
- }
-
- json := jsoniter.ConfigCompatibleWithStandardLibrary
- enc := json.NewEncoder(os.Stdout)
- return enc.Encode(imgs)
-}
-
-func writeTemplate(imageS []*entities.ImageSummary, err error) error {
- type image struct {
- entities.ImageSummary
- Repository string `json:"repository,omitempty"`
- Tag string `json:"tag,omitempty"`
- }
-
- imgs := make([]image, 0, len(imageS))
- for _, e := range imageS {
- for _, tag := range e.RepoTags {
- var h image
- h.ImageSummary = *e
- h.Repository, h.Tag = tokenRepoTag(tag)
- imgs = append(imgs, h)
- }
- if e.IsReadOnly() {
- listFlag.readOnly = true
- }
- }
-
- hdr, row := imageListFormat(listFlag)
- format := hdr + "{{range . }}" + row + "{{end}}"
-
- tmpl := template.Must(template.New("list").Funcs(report.PodmanTemplateFuncs()).Parse(format))
- w := tabwriter.NewWriter(os.Stdout, 8, 2, 2, ' ', 0)
- defer w.Flush()
- return tmpl.Execute(w, imgs)
-}
-
-func tokenRepoTag(tag string) (string, string) {
- tokens := strings.SplitN(tag, ":", 2)
- switch len(tokens) {
- case 0:
- return tag, ""
- case 1:
- return tokens[0], ""
- case 2:
- return tokens[0], tokens[1]
- default:
- return "<N/A>", ""
- }
-}
-
-func sortFunc(key string, data []*entities.ImageSummary) func(i, j int) bool {
- switch key {
- case "id":
- return func(i, j int) bool {
- return data[i].ID < data[j].ID
- }
- case "repository":
- return func(i, j int) bool {
- return data[i].RepoTags[0] < data[j].RepoTags[0]
- }
- case "size":
- return func(i, j int) bool {
- return data[i].Size < data[j].Size
- }
- case "tag":
- return func(i, j int) bool {
- return data[i].RepoTags[0] < data[j].RepoTags[0]
- }
- default:
- // case "created":
- return func(i, j int) bool {
- return data[i].Created >= data[j].Created
- }
- }
-}
-
-func imageListFormat(flags listFlagType) (string, string) {
- if flags.quiet {
- return "", "{{slice .ID 0 12}}\n"
- }
-
- // Defaults
- hdr := "REPOSITORY\tTAG"
- row := "{{.Repository}}\t{{if .Tag}}{{.Tag}}{{else}}<none>{{end}}"
-
- if flags.digests {
- hdr += "\tDIGEST"
- row += "\t{{.Digest}}"
- }
-
- hdr += "\tIMAGE ID"
- if flags.noTrunc {
- row += "\tsha256:{{.ID}}"
- } else {
- row += "\t{{slice .ID 0 12}}"
- }
-
- hdr += "\tCREATED\tSIZE"
- row += "\t{{humanDuration .Created}}\t{{humanSize .Size}}"
-
- if flags.history {
- hdr += "\tHISTORY"
- row += "\t{{if .History}}{{join .History \", \"}}{{else}}<none>{{end}}"
- }
-
- if flags.readOnly {
- hdr += "\tReadOnly"
- row += "\t{{.ReadOnly}}"
- }
-
- if flags.noHeading {
- hdr = ""
- } else {
- hdr += "\n"
- }
-
- row += "\n"
- return hdr, row
-}
diff --git a/cmd/podmanV2/images/load.go b/cmd/podmanV2/images/load.go
deleted file mode 100644
index f60dc4908..000000000
--- a/cmd/podmanV2/images/load.go
+++ /dev/null
@@ -1,61 +0,0 @@
-package images
-
-import (
- "context"
- "fmt"
-
- "github.com/containers/libpod/cmd/podmanV2/registry"
- "github.com/containers/libpod/libpod/image"
- "github.com/containers/libpod/pkg/domain/entities"
- "github.com/spf13/cobra"
-)
-
-var (
- loadDescription = "Loads an image from a locally stored archive (tar file) into container storage."
- loadCommand = &cobra.Command{
- Use: "load [flags] [NAME[:TAG]]",
- Short: "Load an image from container archive",
- Long: loadDescription,
- RunE: load,
- Args: cobra.MaximumNArgs(1),
- PersistentPreRunE: preRunE,
- }
-)
-
-var (
- loadOpts entities.ImageLoadOptions
-)
-
-func init() {
- registry.Commands = append(registry.Commands, registry.CliCommand{
- Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode},
- Command: loadCommand,
- })
-
- loadCommand.SetHelpTemplate(registry.HelpTemplate())
- loadCommand.SetUsageTemplate(registry.UsageTemplate())
- flags := loadCommand.Flags()
- flags.StringVarP(&loadOpts.Input, "input", "i", "", "Read from specified archive file (default: stdin)")
- flags.BoolVarP(&loadOpts.Quiet, "quiet", "q", false, "Suppress the output")
- flags.StringVar(&loadOpts.SignaturePolicy, "signature-policy", "", "Pathname of signature policy file")
- if registry.IsRemote() {
- _ = flags.MarkHidden("signature-policy")
- }
-
-}
-
-func load(cmd *cobra.Command, args []string) error {
- if len(args) > 0 {
- repo, err := image.NormalizedTag(args[0])
- if err != nil {
- return err
- }
- loadOpts.Name = repo.Name()
- }
- response, err := registry.ImageEngine().Load(context.Background(), loadOpts)
- if err != nil {
- return err
- }
- fmt.Println("Loaded image: " + response.Name)
- return nil
-}
diff --git a/cmd/podmanV2/images/prune.go b/cmd/podmanV2/images/prune.go
deleted file mode 100644
index 6577c458e..000000000
--- a/cmd/podmanV2/images/prune.go
+++ /dev/null
@@ -1,86 +0,0 @@
-package images
-
-import (
- "bufio"
- "fmt"
- "os"
- "strings"
-
- "github.com/containers/libpod/cmd/podmanV2/registry"
- "github.com/containers/libpod/pkg/domain/entities"
- "github.com/pkg/errors"
- "github.com/spf13/cobra"
-)
-
-var (
- pruneDescription = `Removes all unnamed images from local storage.
-
- If an image is not being used by a container, it will be removed from the system.`
- pruneCmd = &cobra.Command{
- Use: "prune",
- Args: cobra.NoArgs,
- Short: "Remove unused images",
- Long: pruneDescription,
- RunE: prune,
- Example: `podman image prune`,
- }
-
- pruneOpts = entities.ImagePruneOptions{}
- force bool
- filter = []string{}
-)
-
-func init() {
- registry.Commands = append(registry.Commands, registry.CliCommand{
- Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode},
- Command: pruneCmd,
- Parent: imageCmd,
- })
-
- flags := pruneCmd.Flags()
- flags.BoolVarP(&pruneOpts.All, "all", "a", false, "Remove all unused images, not just dangling ones")
- flags.BoolVarP(&force, "force", "f", false, "Do not prompt for confirmation")
- flags.StringArrayVar(&filter, "filter", []string{}, "Provide filter values (e.g. 'label=<key>=<value>')")
-
-}
-
-func prune(cmd *cobra.Command, args []string) error {
- if !force {
- reader := bufio.NewReader(os.Stdin)
- fmt.Printf(`
-WARNING! This will remove all dangling images.
-Are you sure you want to continue? [y/N] `)
- answer, err := reader.ReadString('\n')
- if err != nil {
- return errors.Wrapf(err, "error reading input")
- }
- if strings.ToLower(answer)[0] != 'y' {
- return nil
- }
- }
-
- // TODO Remove once filter refactor is finished and url.Values rules :)
- for _, f := range filter {
- t := strings.SplitN(f, "=", 2)
- pruneOpts.Filters.Add(t[0], t[1])
- }
-
- results, err := registry.ImageEngine().Prune(registry.GetContext(), pruneOpts)
- if err != nil {
- return err
- }
-
- for _, i := range results.Report.Id {
- fmt.Println(i)
- }
-
- for _, e := range results.Report.Err {
- fmt.Fprint(os.Stderr, e.Error()+"\n")
- }
-
- if results.Size > 0 {
- fmt.Fprintf(os.Stdout, "Size: %d\n", results.Size)
- }
-
- return nil
-}
diff --git a/cmd/podmanV2/images/pull.go b/cmd/podmanV2/images/pull.go
deleted file mode 100644
index c7e325409..000000000
--- a/cmd/podmanV2/images/pull.go
+++ /dev/null
@@ -1,140 +0,0 @@
-package images
-
-import (
- "fmt"
-
- buildahcli "github.com/containers/buildah/pkg/cli"
- "github.com/containers/image/v5/types"
- "github.com/containers/libpod/cmd/podmanV2/registry"
- "github.com/containers/libpod/pkg/domain/entities"
- "github.com/opentracing/opentracing-go"
- "github.com/pkg/errors"
- "github.com/spf13/cobra"
- "github.com/spf13/pflag"
-)
-
-// pullOptionsWrapper wraps entities.ImagePullOptions and prevents leaking
-// CLI-only fields into the API types.
-type pullOptionsWrapper struct {
- entities.ImagePullOptions
- TLSVerifyCLI bool // CLI only
-}
-
-var (
- pullOptions = pullOptionsWrapper{}
- pullDescription = `Pulls an image from a registry and stores it locally.
-
- An image can be pulled by tag or digest. If a tag is not specified, the image with the 'latest' tag is pulled.`
-
- // Command: podman pull
- pullCmd = &cobra.Command{
- Use: "pull [flags] IMAGE",
- Short: "Pull an image from a registry",
- Long: pullDescription,
- PreRunE: preRunE,
- RunE: imagePull,
- Example: `podman pull imageName
- podman pull fedora:latest`,
- }
-
- // Command: podman image pull
- // It's basically a clone of `pullCmd` with the exception of being a
- // child of the images command.
- imagesPullCmd = &cobra.Command{
- Use: pullCmd.Use,
- Short: pullCmd.Short,
- Long: pullCmd.Long,
- PreRunE: pullCmd.PreRunE,
- RunE: pullCmd.RunE,
- Example: `podman image pull imageName
- podman image pull fedora:latest`,
- }
-)
-
-func init() {
- // pull
- registry.Commands = append(registry.Commands, registry.CliCommand{
- Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode},
- Command: pullCmd,
- })
-
- pullCmd.SetHelpTemplate(registry.HelpTemplate())
- pullCmd.SetUsageTemplate(registry.UsageTemplate())
-
- flags := pullCmd.Flags()
- pullFlags(flags)
-
- // images pull
- registry.Commands = append(registry.Commands, registry.CliCommand{
- Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode},
- Command: imagesPullCmd,
- Parent: imageCmd,
- })
-
- imagesPullCmd.SetHelpTemplate(registry.HelpTemplate())
- imagesPullCmd.SetUsageTemplate(registry.UsageTemplate())
- imagesPullFlags := imagesPullCmd.Flags()
- pullFlags(imagesPullFlags)
-}
-
-// pullFlags set the flags for the pull command.
-func pullFlags(flags *pflag.FlagSet) {
- flags.BoolVar(&pullOptions.AllTags, "all-tags", false, "All tagged images in the repository will be pulled")
- flags.StringVar(&pullOptions.Authfile, "authfile", buildahcli.GetDefaultAuthFile(), "Path of the authentication file. Use REGISTRY_AUTH_FILE environment variable to override")
- flags.StringVar(&pullOptions.CertDir, "cert-dir", "", "`Pathname` of a directory containing TLS certificates and keys")
- flags.StringVar(&pullOptions.Credentials, "creds", "", "`Credentials` (USERNAME:PASSWORD) to use for authenticating to a registry")
- flags.StringVar(&pullOptions.OverrideArch, "override-arch", "", "Use `ARCH` instead of the architecture of the machine for choosing images")
- flags.StringVar(&pullOptions.OverrideOS, "override-os", "", "Use `OS` instead of the running OS for choosing images")
- flags.BoolVarP(&pullOptions.Quiet, "quiet", "q", false, "Suppress output information when pulling images")
- flags.StringVar(&pullOptions.SignaturePolicy, "signature-policy", "", "`Pathname` of signature policy file (not usually used)")
- flags.BoolVar(&pullOptions.TLSVerifyCLI, "tls-verify", true, "Require HTTPS and verify certificates when contacting registries")
-
- if registry.IsRemote() {
- _ = flags.MarkHidden("authfile")
- _ = flags.MarkHidden("cert-dir")
- _ = flags.MarkHidden("signature-policy")
- _ = flags.MarkHidden("tls-verify")
- }
-}
-
-// imagePull is implement the command for pulling images.
-func imagePull(cmd *cobra.Command, args []string) error {
- // Sanity check input.
- if len(args) == 0 {
- return errors.Errorf("an image name must be specified")
- }
- if len(args) > 1 {
- return errors.Errorf("too many arguments. Requires exactly 1")
- }
-
- // Start tracing if requested.
- if cmd.Flags().Changed("trace") {
- span, _ := opentracing.StartSpanFromContext(registry.GetContext(), "pullCmd")
- defer span.Finish()
- }
-
- pullOptsAPI := pullOptions.ImagePullOptions
- // TLS verification in c/image is controlled via a `types.OptionalBool`
- // which allows for distinguishing among set-true, set-false, unspecified
- // which is important to implement a sane way of dealing with defaults of
- // boolean CLI flags.
- if cmd.Flags().Changed("tls-verify") {
- pullOptsAPI.TLSVerify = types.NewOptionalBool(pullOptions.TLSVerifyCLI)
- }
-
- // Let's do all the remaining Yoga in the API to prevent us from
- // scattering logic across (too) many parts of the code.
- pullReport, err := registry.ImageEngine().Pull(registry.GetContext(), args[0], pullOptsAPI)
- if err != nil {
- return err
- }
-
- if len(pullReport.Images) > 1 {
- fmt.Println("Pulled Images:")
- }
- for _, img := range pullReport.Images {
- fmt.Println(img)
- }
-
- return nil
-}
diff --git a/cmd/podmanV2/images/rm.go b/cmd/podmanV2/images/rm.go
deleted file mode 100644
index bb5880de3..000000000
--- a/cmd/podmanV2/images/rm.go
+++ /dev/null
@@ -1,70 +0,0 @@
-package images
-
-import (
- "fmt"
- "os"
-
- "github.com/containers/libpod/cmd/podmanV2/registry"
- "github.com/containers/libpod/pkg/domain/entities"
- "github.com/pkg/errors"
- "github.com/spf13/cobra"
-)
-
-var (
- rmDescription = "Removes one or more previously pulled or locally created images."
- rmCmd = &cobra.Command{
- Use: "rm [flags] IMAGE [IMAGE...]",
- Short: "Removes one or more images from local storage",
- Long: rmDescription,
- PreRunE: preRunE,
- RunE: rm,
- Example: `podman image rm imageID
- podman image rm --force alpine
- podman image rm c4dfb1609ee2 93fd78260bd1 c0ed59d05ff7`,
- }
-
- imageOpts = entities.ImageDeleteOptions{}
-)
-
-func init() {
- registry.Commands = append(registry.Commands, registry.CliCommand{
- Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode},
- Command: rmCmd,
- Parent: imageCmd,
- })
-
- flags := rmCmd.Flags()
- flags.BoolVarP(&imageOpts.All, "all", "a", false, "Remove all images")
- flags.BoolVarP(&imageOpts.Force, "force", "f", false, "Force Removal of the image")
-}
-
-func rm(cmd *cobra.Command, args []string) error {
-
- if len(args) < 1 && !imageOpts.All {
- return errors.Errorf("image name or ID must be specified")
- }
- if len(args) > 0 && imageOpts.All {
- return errors.Errorf("when using the --all switch, you may not pass any images names or IDs")
- }
-
- report, err := registry.ImageEngine().Delete(registry.GetContext(), args, imageOpts)
- if err != nil {
- switch {
- case report != nil && report.ImageNotFound != nil:
- fmt.Fprintln(os.Stderr, err.Error())
- registry.SetExitCode(2)
- case report != nil && report.ImageInUse != nil:
- fmt.Fprintln(os.Stderr, err.Error())
- default:
- return err
- }
- }
-
- for _, u := range report.Untagged {
- fmt.Println("Untagged: " + u)
- }
- for _, d := range report.Deleted {
- fmt.Println("Deleted: " + d)
- }
- return nil
-}
diff --git a/cmd/podmanV2/images/rmi.go b/cmd/podmanV2/images/rmi.go
deleted file mode 100644
index 7f9297bc9..000000000
--- a/cmd/podmanV2/images/rmi.go
+++ /dev/null
@@ -1,30 +0,0 @@
-package images
-
-import (
- "strings"
-
- "github.com/containers/libpod/cmd/podmanV2/registry"
- "github.com/containers/libpod/pkg/domain/entities"
- "github.com/spf13/cobra"
-)
-
-var (
- rmiCmd = &cobra.Command{
- Use: strings.Replace(rmCmd.Use, "rm ", "rmi ", 1),
- Args: rmCmd.Args,
- Short: rmCmd.Short,
- Long: rmCmd.Long,
- PreRunE: rmCmd.PreRunE,
- RunE: rmCmd.RunE,
- Example: strings.Replace(rmCmd.Example, "podman image rm", "podman rmi", -1),
- }
-)
-
-func init() {
- registry.Commands = append(registry.Commands, registry.CliCommand{
- Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode},
- Command: rmiCmd,
- })
- rmiCmd.SetHelpTemplate(registry.HelpTemplate())
- rmiCmd.SetUsageTemplate(registry.UsageTemplate())
-}
diff --git a/cmd/podmanV2/images/tag.go b/cmd/podmanV2/images/tag.go
deleted file mode 100644
index f66fe7857..000000000
--- a/cmd/podmanV2/images/tag.go
+++ /dev/null
@@ -1,34 +0,0 @@
-package images
-
-import (
- "github.com/containers/libpod/cmd/podmanV2/registry"
- "github.com/containers/libpod/pkg/domain/entities"
- "github.com/spf13/cobra"
-)
-
-var (
- tagDescription = "Adds one or more additional names to locally-stored image."
- tagCommand = &cobra.Command{
- Use: "tag [flags] IMAGE TARGET_NAME [TARGET_NAME...]",
- Short: "Add an additional name to a local image",
- Long: tagDescription,
- RunE: tag,
- Args: cobra.MinimumNArgs(2),
- Example: `podman tag 0e3bbc2 fedora:latest
- podman tag imageID:latest myNewImage:newTag
- podman tag httpd myregistryhost:5000/fedora/httpd:v2`,
- }
-)
-
-func init() {
- registry.Commands = append(registry.Commands, registry.CliCommand{
- Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode},
- Command: tagCommand,
- })
- tagCommand.SetHelpTemplate(registry.HelpTemplate())
- tagCommand.SetUsageTemplate(registry.UsageTemplate())
-}
-
-func tag(cmd *cobra.Command, args []string) error {
- return registry.ImageEngine().Tag(registry.GetContext(), args[0], args[1:], entities.ImageTagOptions{})
-}
diff --git a/cmd/podmanV2/images/untag.go b/cmd/podmanV2/images/untag.go
deleted file mode 100644
index c84827bb3..000000000
--- a/cmd/podmanV2/images/untag.go
+++ /dev/null
@@ -1,33 +0,0 @@
-package images
-
-import (
- "github.com/containers/libpod/cmd/podmanV2/registry"
- "github.com/containers/libpod/pkg/domain/entities"
- "github.com/spf13/cobra"
-)
-
-var (
- untagCommand = &cobra.Command{
- Use: "untag [flags] IMAGE [NAME...]",
- Short: "Remove a name from a local image",
- Long: "Removes one or more names from a locally-stored image.",
- RunE: untag,
- Args: cobra.MinimumNArgs(1),
- Example: `podman untag 0e3bbc2
- podman untag imageID:latest otherImageName:latest
- podman untag httpd myregistryhost:5000/fedora/httpd:v2`,
- }
-)
-
-func init() {
- registry.Commands = append(registry.Commands, registry.CliCommand{
- Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode},
- Command: untagCommand,
- })
- untagCommand.SetHelpTemplate(registry.HelpTemplate())
- untagCommand.SetUsageTemplate(registry.UsageTemplate())
-}
-
-func untag(cmd *cobra.Command, args []string) error {
- return registry.ImageEngine().Untag(registry.GetContext(), args[0], args[1:], entities.ImageUntagOptions{})
-}