summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
Diffstat (limited to 'cmd')
-rw-r--r--cmd/podman/commit.go5
-rw-r--r--cmd/podman/service.go112
-rw-r--r--cmd/podman/tree.go97
-rw-r--r--cmd/podman/varlink/io.podman.varlink10
4 files changed, 90 insertions, 134 deletions
diff --git a/cmd/podman/commit.go b/cmd/podman/commit.go
index b4d249c66..7c35a4832 100644
--- a/cmd/podman/commit.go
+++ b/cmd/podman/commit.go
@@ -15,7 +15,7 @@ var (
commitDescription = `Create an image from a container's changes. Optionally tag the image created, set the author with the --author flag, set the commit message with the --message flag, and make changes to the instructions with the --change flag.`
_commitCommand = &cobra.Command{
- Use: "commit [flags] CONTAINER IMAGE",
+ Use: "commit [flags] CONTAINER [IMAGE]",
Short: "Create new image based on the changed container",
Long: commitDescription,
RunE: func(cmd *cobra.Command, args []string) error {
@@ -26,7 +26,8 @@ var (
},
Example: `podman commit -q --message "committing container to image" reverent_golick image-committed
podman commit -q --author "firstName lastName" reverent_golick image-committed
- podman commit -q --pause=false containerID image-committed`,
+ podman commit -q --pause=false containerID image-committed
+ podman commit containerID`,
}
// ChangeCmds is the list of valid Changes commands to passed to the Commit call
diff --git a/cmd/podman/service.go b/cmd/podman/service.go
index 4978b5d51..3e0ff927f 100644
--- a/cmd/podman/service.go
+++ b/cmd/podman/service.go
@@ -17,6 +17,7 @@ import (
"github.com/containers/libpod/pkg/adapter"
api "github.com/containers/libpod/pkg/api/server"
"github.com/containers/libpod/pkg/rootless"
+ "github.com/containers/libpod/pkg/systemd"
"github.com/containers/libpod/pkg/util"
"github.com/containers/libpod/pkg/varlinkapi"
"github.com/containers/libpod/version"
@@ -50,21 +51,52 @@ func init() {
serviceCommand.SetHelpTemplate(HelpTemplate())
serviceCommand.SetUsageTemplate(UsageTemplate())
flags := serviceCommand.Flags()
- flags.Int64VarP(&serviceCommand.Timeout, "timeout", "t", 1000, "Time until the service session expires in milliseconds. Use 0 to disable the timeout")
+ flags.Int64VarP(&serviceCommand.Timeout, "timeout", "t", 5, "Time until the service session expires in seconds. Use 0 to disable the timeout")
flags.BoolVar(&serviceCommand.Varlink, "varlink", false, "Use legacy varlink service instead of REST")
}
func serviceCmd(c *cliconfig.ServiceValues) error {
- // For V2, default to the REST socket
- apiURI := adapter.DefaultAPIAddress
+ apiURI, err := resolveApiURI(c)
+ if err != nil {
+ return err
+ }
+
+ // Create a single runtime api consumption
+ runtime, err := libpodruntime.GetRuntimeDisableFDs(getContext(), &c.PodmanCommand)
+ if err != nil {
+ return errors.Wrapf(err, "error creating libpod runtime")
+ }
+ defer func() {
+ if err := runtime.Shutdown(false); err != nil {
+ fmt.Fprintf(os.Stderr, "Failed to shutdown libpod runtime: %v", err)
+ }
+ }()
+
+ timeout := time.Duration(c.Timeout) * time.Second
if c.Varlink {
- apiURI = adapter.DefaultVarlinkAddress
+ return runVarlink(runtime, apiURI, timeout, c)
}
+ return runREST(runtime, apiURI, timeout)
+}
+
+func resolveApiURI(c *cliconfig.ServiceValues) (string, error) {
+ var apiURI string
- if rootless.IsRootless() {
+ // When determining _*THE*_ listening endpoint --
+ // 1) User input wins always
+ // 2) systemd socket activation
+ // 3) rootless honors XDG_RUNTIME_DIR
+ // 4) if varlink -- adapter.DefaultVarlinkAddress
+ // 5) lastly adapter.DefaultAPIAddress
+
+ if len(c.InputArgs) > 0 {
+ apiURI = c.InputArgs[0]
+ } else if ok := systemd.SocketActivated(); ok {
+ apiURI = ""
+ } else if rootless.IsRootless() {
xdg, err := util.GetRuntimeDir()
if err != nil {
- return err
+ return "", err
}
socketName := "podman.sock"
if c.Varlink {
@@ -74,53 +106,59 @@ func serviceCmd(c *cliconfig.ServiceValues) error {
if _, err := os.Stat(filepath.Dir(socketDir)); err != nil {
if os.IsNotExist(err) {
if err := os.Mkdir(filepath.Dir(socketDir), 0755); err != nil {
- return err
+ return "", err
}
} else {
- return err
+ return "", err
}
}
- apiURI = fmt.Sprintf("unix:%s", socketDir)
- }
-
- if len(c.InputArgs) > 0 {
- apiURI = c.InputArgs[0]
+ apiURI = "unix:" + socketDir
+ } else if c.Varlink {
+ apiURI = adapter.DefaultVarlinkAddress
+ } else {
+ // For V2, default to the REST socket
+ apiURI = adapter.DefaultAPIAddress
}
- logrus.Infof("using API endpoint: %s", apiURI)
-
- // Create a single runtime api consumption
- runtime, err := libpodruntime.GetRuntimeDisableFDs(getContext(), &c.PodmanCommand)
- if err != nil {
- return errors.Wrapf(err, "error creating libpod runtime")
+ if "" == apiURI {
+ logrus.Info("using systemd socket activation to determine API endpoint")
+ } else {
+ logrus.Infof("using API endpoint: %s", apiURI)
}
- defer runtime.DeferredShutdown(false)
-
- timeout := time.Duration(c.Timeout) * time.Millisecond
- if c.Varlink {
- return runVarlink(runtime, apiURI, timeout, c)
- }
- return runREST(runtime, apiURI, timeout)
+ return apiURI, nil
}
func runREST(r *libpod.Runtime, uri string, timeout time.Duration) error {
logrus.Warn("This function is EXPERIMENTAL")
fmt.Println("This function is EXPERIMENTAL.")
- fields := strings.Split(uri, ":")
- if len(fields) == 1 {
- return errors.Errorf("%s is an invalid socket destination", uri)
- }
- address := strings.Join(fields[1:], ":")
- l, err := net.Listen(fields[0], address)
- if err != nil {
- return errors.Wrapf(err, "unable to create socket %s", uri)
+
+ var listener *net.Listener
+ if uri != "" {
+ fields := strings.Split(uri, ":")
+ if len(fields) == 1 {
+ return errors.Errorf("%s is an invalid socket destination", uri)
+ }
+ address := strings.Join(fields[1:], ":")
+ l, err := net.Listen(fields[0], address)
+ if err != nil {
+ return errors.Wrapf(err, "unable to create socket %s", uri)
+ }
+ defer l.Close()
+ listener = &l
}
- defer l.Close()
- server, err := api.NewServerWithSettings(r, timeout, &l)
+ server, err := api.NewServerWithSettings(r, timeout, listener)
if err != nil {
return err
}
- return server.Serve()
+ defer func() {
+ if err := server.Shutdown(); err != nil {
+ fmt.Fprintf(os.Stderr, "Error when stopping service: %s", err)
+ }
+ }()
+
+ err = server.Serve()
+ logrus.Debugf("%d/%d Active connections/Total connections\n", server.ActiveConnections, server.TotalConnections)
+ return err
}
func runVarlink(r *libpod.Runtime, uri string, timeout time.Duration, c *cliconfig.ServiceValues) error {
diff --git a/cmd/podman/tree.go b/cmd/podman/tree.go
index 69b42639d..28c770f0c 100644
--- a/cmd/podman/tree.go
+++ b/cmd/podman/tree.go
@@ -1,23 +1,14 @@
package main
import (
- "context"
"fmt"
"github.com/containers/libpod/cmd/podman/cliconfig"
- "github.com/containers/libpod/libpod/image"
"github.com/containers/libpod/pkg/adapter"
- "github.com/docker/go-units"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)
-const (
- middleItem = "├── "
- continueItem = "│ "
- lastItem = "└── "
-)
-
var (
treeCommand cliconfig.TreeValues
@@ -56,95 +47,11 @@ func treeCmd(c *cliconfig.TreeValues) error {
return errors.Wrapf(err, "error creating libpod runtime")
}
defer runtime.DeferredShutdown(false)
- imageInfo, layerInfoMap, img, err := runtime.Tree(c.InputArgs[0])
- if err != nil {
- return err
- }
- return printTree(imageInfo, layerInfoMap, img, c.WhatRequires)
-}
-func printTree(imageInfo *image.InfoImage, layerInfoMap map[string]*image.LayerInfo, img *adapter.ContainerImage, whatRequires bool) error {
- size, err := img.Size(context.Background())
+ tree, err := runtime.ImageTree(c.InputArgs[0], c.WhatRequires)
if err != nil {
return err
}
-
- fmt.Printf("Image ID: %s\n", imageInfo.ID[:12])
- fmt.Printf("Tags:\t %s\n", imageInfo.Tags)
- fmt.Printf("Size:\t %v\n", units.HumanSizeWithPrecision(float64(*size), 4))
- if img.TopLayer() != "" {
- fmt.Printf("Image Layers\n")
- } else {
- fmt.Printf("No Image Layers\n")
- }
-
- if !whatRequires {
- // fill imageInfo with layers associated with image.
- // the layers will be filled such that
- // (Start)RootLayer->...intermediate Parent Layer(s)-> TopLayer(End)
- // Build output from imageInfo into buffer
- printImageHierarchy(imageInfo)
-
- } else {
- // fill imageInfo with layers associated with image.
- // the layers will be filled such that
- // (Start)TopLayer->...intermediate Child Layer(s)-> Child TopLayer(End)
- // (Forks)... intermediate Child Layer(s) -> Child Top Layer(End)
- return printImageChildren(layerInfoMap, img.TopLayer(), "", true)
- }
- return nil
-}
-
-// Stores all children layers which are created using given Image.
-// Layers are stored as follows
-// (Start)TopLayer->...intermediate Child Layer(s)-> Child TopLayer(End)
-// (Forks)... intermediate Child Layer(s) -> Child Top Layer(End)
-func printImageChildren(layerMap map[string]*image.LayerInfo, layerID string, prefix string, last bool) error {
- if layerID == "" {
- return nil
- }
- ll, ok := layerMap[layerID]
- if !ok {
- return fmt.Errorf("lookup error: layerid %s, not found", layerID)
- }
- fmt.Print(prefix)
-
- //initialize intend with middleItem to reduce middleItem checks.
- intend := middleItem
- if !last {
- // add continueItem i.e. '|' for next iteration prefix
- prefix += continueItem
- } else if len(ll.ChildID) > 1 || len(ll.ChildID) == 0 {
- // The above condition ensure, alignment happens for node, which has more then 1 children.
- // If node is last in printing hierarchy, it should not be printed as middleItem i.e. ├──
- intend = lastItem
- prefix += " "
- }
-
- var tags string
- if len(ll.RepoTags) > 0 {
- tags = fmt.Sprintf(" Top Layer of: %s", ll.RepoTags)
- }
- fmt.Printf("%sID: %s Size: %7v%s\n", intend, ll.ID[:12], units.HumanSizeWithPrecision(float64(ll.Size), 4), tags)
- for count, childID := range ll.ChildID {
- if err := printImageChildren(layerMap, childID, prefix, count == len(ll.ChildID)-1); err != nil {
- return err
- }
- }
+ fmt.Print(tree)
return nil
}
-
-// prints the layers info of image
-func printImageHierarchy(imageInfo *image.InfoImage) {
- for count, l := range imageInfo.Layers {
- var tags string
- intend := middleItem
- if len(l.RepoTags) > 0 {
- tags = fmt.Sprintf(" Top Layer of: %s", l.RepoTags)
- }
- if count == len(imageInfo.Layers)-1 {
- intend = lastItem
- }
- fmt.Printf("%s ID: %s Size: %7v%s\n", intend, l.ID[:12], units.HumanSizeWithPrecision(float64(l.Size), 4), tags)
- }
-}
diff --git a/cmd/podman/varlink/io.podman.varlink b/cmd/podman/varlink/io.podman.varlink
index a0227c48c..e9792fa8f 100644
--- a/cmd/podman/varlink/io.podman.varlink
+++ b/cmd/podman/varlink/io.podman.varlink
@@ -1188,6 +1188,16 @@ method GetPodsByStatus(statuses: []string) -> (pods: []string)
# ~~~
method ImageExists(name: string) -> (exists: int)
+# ImageTree returns the image tree for the provided image name or ID
+# #### Example
+# ~~~
+# $ varlink call -m unix:/run/podman/io.podman/io.podman.ImageTree '{"name": "alpine"}'
+# {
+# "tree": "Image ID: e7d92cdc71fe\nTags: [docker.io/library/alpine:latest]\nSize: 5.861MB\nImage Layers\n└── ID: 5216338b40a7 Size: 5.857MB Top Layer of: [docker.io/library/alpine:latest]\n"
+# }
+# ~~~
+method ImageTree(name: string, whatRequires: bool) -> (tree: string)
+
# ContainerExists takes a full or partial container ID or name and returns an int as to
# whether the container exists in local storage. A result of 0 means the container does
# exists; whereas a result of 1 means it could not be found.