mirror of
https://github.com/containers/podman.git
synced 2025-06-27 13:38:49 +08:00
varlink images
implement varlink image functions for working with libpod with the exception of a couple due to incompletions on the libpod side of things (build). also, created a first pass at a libpodpy package which will stand as a client to working with libpod's varlink methods using python. Signed-off-by: baude <bbaude@redhat.com> Closes: #669 Approved by: baude
This commit is contained in:
6
Makefile
6
Makefile
@ -247,10 +247,10 @@ install.tools: .install.gitvalidation .install.gometalinter .install.md2man
|
||||
make all install; \
|
||||
fi
|
||||
|
||||
varlink_generate: .gopathok cmd/podman/ioprojectatomicpodman/ioprojectatomicpodman.go
|
||||
varlink_generate: .gopathok cmd/podman/varlink/ioprojectatomicpodman.go
|
||||
|
||||
cmd/podman/ioprojectatomicpodman/ioprojectatomicpodman.go: cmd/podman/ioprojectatomicpodman/io.projectatomic.podman.varlink
|
||||
$(GO) generate ./cmd/podman/ioprojectatomicpodman/...
|
||||
cmd/podman/varlink/ioprojectatomicpodman.go: cmd/podman/varlink/io.projectatomic.podman.varlink
|
||||
$(GO) generate ./cmd/podman/varlink/...
|
||||
|
||||
validate: gofmt .gitvalidation
|
||||
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"os"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/projectatomic/libpod/cmd/podman/libpodruntime"
|
||||
"github.com/projectatomic/libpod/libpod"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
@ -45,7 +46,7 @@ func attachCmd(c *cli.Context) error {
|
||||
return errors.Errorf("attach requires the name or id of one running container or the latest flag")
|
||||
}
|
||||
|
||||
runtime, err := getRuntime(c)
|
||||
runtime, err := libpodruntime.GetRuntime(c)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "error creating libpod runtime")
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/projectatomic/libpod/cmd/podman/libpodruntime"
|
||||
"github.com/projectatomic/libpod/libpod"
|
||||
"github.com/projectatomic/libpod/libpod/buildah"
|
||||
"github.com/projectatomic/libpod/libpod/image"
|
||||
@ -55,7 +56,7 @@ func commitCmd(c *cli.Context) error {
|
||||
if err := validateFlags(c, commitFlags); err != nil {
|
||||
return err
|
||||
}
|
||||
runtime, err := getRuntime(c)
|
||||
runtime, err := libpodruntime.GetRuntime(c)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not get runtime")
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ import (
|
||||
"github.com/docker/go-units"
|
||||
"github.com/opencontainers/selinux/go-selinux/label"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/projectatomic/libpod/cmd/podman/libpodruntime"
|
||||
"github.com/projectatomic/libpod/libpod"
|
||||
"github.com/projectatomic/libpod/libpod/image"
|
||||
"github.com/projectatomic/libpod/pkg/inspect"
|
||||
@ -173,7 +174,7 @@ func createCmd(c *cli.Context) error {
|
||||
return errors.Errorf("image name or ID is required")
|
||||
}
|
||||
|
||||
runtime, err := getRuntime(c)
|
||||
runtime, err := libpodruntime.GetRuntime(c)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "error creating libpod runtime")
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
"github.com/containers/storage/pkg/archive"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/projectatomic/libpod/cmd/podman/formats"
|
||||
"github.com/projectatomic/libpod/cmd/podman/libpodruntime"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
@ -82,7 +83,7 @@ func diffCmd(c *cli.Context) error {
|
||||
return errors.Errorf("container, image, or layer name must be specified: podman diff [options [...]] ID-NAME")
|
||||
}
|
||||
|
||||
runtime, err := getRuntime(c)
|
||||
runtime, err := libpodruntime.GetRuntime(c)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not get runtime")
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/projectatomic/libpod/cmd/podman/libpodruntime"
|
||||
"github.com/projectatomic/libpod/libpod"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
@ -66,7 +67,7 @@ func execCmd(c *cli.Context) error {
|
||||
argStart = 0
|
||||
}
|
||||
cmd := args[argStart:]
|
||||
runtime, err := getRuntime(c)
|
||||
runtime, err := libpodruntime.GetRuntime(c)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "error creating libpod runtime")
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"os"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/projectatomic/libpod/cmd/podman/libpodruntime"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
@ -34,7 +35,7 @@ func exportCmd(c *cli.Context) error {
|
||||
return err
|
||||
}
|
||||
|
||||
runtime, err := getRuntime(c)
|
||||
runtime, err := libpodruntime.GetRuntime(c)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not get runtime")
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ import (
|
||||
"github.com/opencontainers/image-spec/specs-go/v1"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/projectatomic/libpod/cmd/podman/formats"
|
||||
"github.com/projectatomic/libpod/cmd/podman/libpodruntime"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
@ -83,7 +84,7 @@ func historyCmd(c *cli.Context) error {
|
||||
return err
|
||||
}
|
||||
|
||||
runtime, err := getRuntime(c)
|
||||
runtime, err := libpodruntime.GetRuntime(c)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not get runtime")
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ import (
|
||||
digest "github.com/opencontainers/go-digest"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/projectatomic/libpod/cmd/podman/formats"
|
||||
"github.com/projectatomic/libpod/cmd/podman/libpodruntime"
|
||||
"github.com/projectatomic/libpod/libpod"
|
||||
"github.com/projectatomic/libpod/libpod/image"
|
||||
"github.com/urfave/cli"
|
||||
@ -90,7 +91,7 @@ func imagesCmd(c *cli.Context) error {
|
||||
return err
|
||||
}
|
||||
|
||||
runtime, err := getRuntime(c)
|
||||
runtime, err := libpodruntime.GetRuntime(c)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "Could not get runtime")
|
||||
}
|
||||
|
@ -7,11 +7,12 @@ import (
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/opencontainers/image-spec/specs-go/v1"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/projectatomic/libpod/cmd/podman/libpodruntime"
|
||||
"github.com/projectatomic/libpod/libpod/image"
|
||||
"github.com/projectatomic/libpod/pkg/util"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
@ -49,7 +50,7 @@ func importCmd(c *cli.Context) error {
|
||||
return err
|
||||
}
|
||||
|
||||
runtime, err := getRuntime(c)
|
||||
runtime, err := libpodruntime.GetRuntime(c)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not get runtime")
|
||||
}
|
||||
@ -76,7 +77,7 @@ func importCmd(c *cli.Context) error {
|
||||
|
||||
changes := v1.ImageConfig{}
|
||||
if c.IsSet("change") {
|
||||
changes, err = getImageConfig(c.StringSlice("change"))
|
||||
changes, err = util.GetImageConfig(c.StringSlice("change"))
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "error adding config changes to image %q", source)
|
||||
}
|
||||
@ -138,68 +139,3 @@ func downloadFromURL(source string) (string, error) {
|
||||
|
||||
return outFile.Name(), nil
|
||||
}
|
||||
|
||||
// getImageConfig converts the --change flag values in the format "CMD=/bin/bash USER=example"
|
||||
// to a type v1.ImageConfig
|
||||
func getImageConfig(changes []string) (v1.ImageConfig, error) {
|
||||
// USER=value | EXPOSE=value | ENV=value | ENTRYPOINT=value |
|
||||
// CMD=value | VOLUME=value | WORKDIR=value | LABEL=key=value | STOPSIGNAL=value
|
||||
|
||||
var (
|
||||
user string
|
||||
env []string
|
||||
entrypoint []string
|
||||
cmd []string
|
||||
workingDir string
|
||||
stopSignal string
|
||||
)
|
||||
|
||||
exposedPorts := make(map[string]struct{})
|
||||
volumes := make(map[string]struct{})
|
||||
labels := make(map[string]string)
|
||||
|
||||
for _, ch := range changes {
|
||||
pair := strings.Split(ch, "=")
|
||||
if len(pair) == 1 {
|
||||
return v1.ImageConfig{}, errors.Errorf("no value given for instruction %q", ch)
|
||||
}
|
||||
switch pair[0] {
|
||||
case "USER":
|
||||
user = pair[1]
|
||||
case "EXPOSE":
|
||||
var st struct{}
|
||||
exposedPorts[pair[1]] = st
|
||||
case "ENV":
|
||||
env = append(env, pair[1])
|
||||
case "ENTRYPOINT":
|
||||
entrypoint = append(entrypoint, pair[1])
|
||||
case "CMD":
|
||||
cmd = append(cmd, pair[1])
|
||||
case "VOLUME":
|
||||
var st struct{}
|
||||
volumes[pair[1]] = st
|
||||
case "WORKDIR":
|
||||
workingDir = pair[1]
|
||||
case "LABEL":
|
||||
if len(pair) == 3 {
|
||||
labels[pair[1]] = pair[2]
|
||||
} else {
|
||||
labels[pair[1]] = ""
|
||||
}
|
||||
case "STOPSIGNAL":
|
||||
stopSignal = pair[1]
|
||||
}
|
||||
}
|
||||
|
||||
return v1.ImageConfig{
|
||||
User: user,
|
||||
ExposedPorts: exposedPorts,
|
||||
Env: env,
|
||||
Entrypoint: entrypoint,
|
||||
Cmd: cmd,
|
||||
Volumes: volumes,
|
||||
WorkingDir: workingDir,
|
||||
Labels: labels,
|
||||
StopSignal: stopSignal,
|
||||
}, nil
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/projectatomic/libpod/cmd/podman/formats"
|
||||
"github.com/projectatomic/libpod/cmd/podman/libpodruntime"
|
||||
"github.com/projectatomic/libpod/libpod"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
@ -37,7 +38,7 @@ func infoCmd(c *cli.Context) error {
|
||||
}
|
||||
info := map[string]interface{}{}
|
||||
|
||||
runtime, err := getRuntime(c)
|
||||
runtime, err := libpodruntime.GetRuntime(c)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not get runtime")
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import (
|
||||
specs "github.com/opencontainers/runtime-spec/specs-go"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/projectatomic/libpod/cmd/podman/formats"
|
||||
"github.com/projectatomic/libpod/cmd/podman/libpodruntime"
|
||||
"github.com/projectatomic/libpod/libpod"
|
||||
"github.com/projectatomic/libpod/pkg/inspect"
|
||||
"github.com/projectatomic/libpod/pkg/util"
|
||||
@ -64,7 +65,7 @@ func inspectCmd(c *cli.Context) error {
|
||||
return err
|
||||
}
|
||||
|
||||
runtime, err := getRuntime(c)
|
||||
runtime, err := libpodruntime.GetRuntime(c)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "error creating libpod runtime")
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import (
|
||||
"fmt"
|
||||
"github.com/docker/docker/pkg/signal"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/projectatomic/libpod/cmd/podman/libpodruntime"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
@ -44,7 +45,7 @@ func killCmd(c *cli.Context) error {
|
||||
return err
|
||||
}
|
||||
|
||||
runtime, err := getRuntime(c)
|
||||
runtime, err := libpodruntime.GetRuntime(c)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not get runtime")
|
||||
}
|
||||
|
59
cmd/podman/libpodruntime/runtime.go
Normal file
59
cmd/podman/libpodruntime/runtime.go
Normal file
@ -0,0 +1,59 @@
|
||||
package libpodruntime
|
||||
|
||||
import (
|
||||
"github.com/containers/storage"
|
||||
"github.com/projectatomic/libpod/libpod"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
// GetRuntime generates a new libpod runtime configured by command line options
|
||||
func GetRuntime(c *cli.Context) (*libpod.Runtime, error) {
|
||||
options := []libpod.RuntimeOption{}
|
||||
|
||||
if c.GlobalIsSet("root") || c.GlobalIsSet("runroot") ||
|
||||
c.GlobalIsSet("storage-opt") || c.GlobalIsSet("storage-driver") {
|
||||
storageOpts := storage.DefaultStoreOptions
|
||||
|
||||
if c.GlobalIsSet("root") {
|
||||
storageOpts.GraphRoot = c.GlobalString("root")
|
||||
}
|
||||
if c.GlobalIsSet("runroot") {
|
||||
storageOpts.RunRoot = c.GlobalString("runroot")
|
||||
}
|
||||
if c.GlobalIsSet("storage-driver") {
|
||||
storageOpts.GraphDriverName = c.GlobalString("storage-driver")
|
||||
}
|
||||
if c.GlobalIsSet("storage-opt") {
|
||||
storageOpts.GraphDriverOptions = c.GlobalStringSlice("storage-opt")
|
||||
}
|
||||
|
||||
options = append(options, libpod.WithStorageConfig(storageOpts))
|
||||
}
|
||||
|
||||
// TODO CLI flags for image config?
|
||||
// TODO CLI flag for signature policy?
|
||||
|
||||
if c.GlobalIsSet("runtime") {
|
||||
options = append(options, libpod.WithOCIRuntime(c.GlobalString("runtime")))
|
||||
}
|
||||
|
||||
if c.GlobalIsSet("conmon") {
|
||||
options = append(options, libpod.WithConmonPath(c.GlobalString("conmon")))
|
||||
}
|
||||
|
||||
// TODO flag to set CGroup manager?
|
||||
// TODO flag to set libpod static dir?
|
||||
// TODO flag to set libpod tmp dir?
|
||||
|
||||
if c.GlobalIsSet("cni-config-dir") {
|
||||
options = append(options, libpod.WithCNIConfigDir(c.GlobalString("cni-config-dir")))
|
||||
}
|
||||
if c.GlobalIsSet("default-mounts-file") {
|
||||
options = append(options, libpod.WithDefaultMountsFile(c.GlobalString("default-mounts-file")))
|
||||
}
|
||||
options = append(options, libpod.WithHooksDir(c.GlobalString("hooks-dir-path")))
|
||||
|
||||
// TODO flag to set CNI plugins dir?
|
||||
|
||||
return libpod.NewRuntime(options...)
|
||||
}
|
@ -7,6 +7,7 @@ import (
|
||||
"os"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/projectatomic/libpod/cmd/podman/libpodruntime"
|
||||
"github.com/projectatomic/libpod/libpod"
|
||||
libpodImage "github.com/projectatomic/libpod/libpod/image"
|
||||
"github.com/urfave/cli"
|
||||
@ -56,7 +57,7 @@ func loadCmd(c *cli.Context) error {
|
||||
return err
|
||||
}
|
||||
|
||||
runtime, err := getRuntime(c)
|
||||
runtime, err := libpodruntime.GetRuntime(c)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not get runtime")
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ import (
|
||||
|
||||
"bufio"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/projectatomic/libpod/cmd/podman/libpodruntime"
|
||||
"github.com/projectatomic/libpod/libpod"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/urfave/cli"
|
||||
@ -67,7 +68,7 @@ func logsCmd(c *cli.Context) error {
|
||||
return err
|
||||
}
|
||||
|
||||
runtime, err := getRuntime(c)
|
||||
runtime, err := libpodruntime.GetRuntime(c)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not get runtime")
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
|
||||
"github.com/pkg/errors"
|
||||
of "github.com/projectatomic/libpod/cmd/podman/formats"
|
||||
"github.com/projectatomic/libpod/cmd/podman/libpodruntime"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
@ -50,7 +51,7 @@ func mountCmd(c *cli.Context) error {
|
||||
return err
|
||||
}
|
||||
|
||||
runtime, err := getRuntime(c)
|
||||
runtime, err := libpodruntime.GetRuntime(c)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not get runtime")
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"os"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/projectatomic/libpod/cmd/podman/libpodruntime"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
@ -24,7 +25,7 @@ var (
|
||||
)
|
||||
|
||||
func pauseCmd(c *cli.Context) error {
|
||||
runtime, err := getRuntime(c)
|
||||
runtime, err := libpodruntime.GetRuntime(c)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not get runtime")
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/projectatomic/libpod/cmd/podman/libpodruntime"
|
||||
"github.com/projectatomic/libpod/libpod"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
@ -88,7 +89,7 @@ func portCmd(c *cli.Context) error {
|
||||
}
|
||||
}
|
||||
|
||||
runtime, err := getRuntime(c)
|
||||
runtime, err := libpodruntime.GetRuntime(c)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not get runtime")
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ import (
|
||||
specs "github.com/opencontainers/runtime-spec/specs-go"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/projectatomic/libpod/cmd/podman/formats"
|
||||
"github.com/projectatomic/libpod/cmd/podman/libpodruntime"
|
||||
"github.com/projectatomic/libpod/libpod"
|
||||
"github.com/projectatomic/libpod/pkg/util"
|
||||
"github.com/sirupsen/logrus"
|
||||
@ -154,7 +155,7 @@ func psCmd(c *cli.Context) error {
|
||||
return errors.Wrapf(err, "error with flags passed")
|
||||
}
|
||||
|
||||
runtime, err := getRuntime(c)
|
||||
runtime, err := libpodruntime.GetRuntime(c)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "error creating libpod runtime")
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import (
|
||||
|
||||
"github.com/containers/image/types"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/projectatomic/libpod/cmd/podman/libpodruntime"
|
||||
image2 "github.com/projectatomic/libpod/libpod/image"
|
||||
"github.com/projectatomic/libpod/pkg/util"
|
||||
"github.com/sirupsen/logrus"
|
||||
@ -59,7 +60,7 @@ var (
|
||||
// to copy an image from a registry to a local machine
|
||||
func pullCmd(c *cli.Context) error {
|
||||
forceSecure := false
|
||||
runtime, err := getRuntime(c)
|
||||
runtime, err := libpodruntime.GetRuntime(c)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not get runtime")
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ import (
|
||||
"github.com/containers/image/types"
|
||||
imgspecv1 "github.com/opencontainers/image-spec/specs-go/v1"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/projectatomic/libpod/cmd/podman/libpodruntime"
|
||||
"github.com/projectatomic/libpod/libpod"
|
||||
"github.com/projectatomic/libpod/libpod/image"
|
||||
"github.com/projectatomic/libpod/pkg/util"
|
||||
@ -117,7 +118,7 @@ func pushCmd(c *cli.Context) error {
|
||||
registryCreds = creds
|
||||
}
|
||||
|
||||
runtime, err := getRuntime(c)
|
||||
runtime, err := libpodruntime.GetRuntime(c)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not create runtime")
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"os"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/projectatomic/libpod/cmd/podman/libpodruntime"
|
||||
"github.com/projectatomic/libpod/libpod"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
@ -41,7 +42,7 @@ func restartCmd(c *cli.Context) error {
|
||||
return err
|
||||
}
|
||||
|
||||
runtime, err := getRuntime(c)
|
||||
runtime, err := libpodruntime.GetRuntime(c)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "error creating libpod runtime")
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"os"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/projectatomic/libpod/cmd/podman/libpodruntime"
|
||||
"github.com/projectatomic/libpod/libpod"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
@ -40,7 +41,7 @@ func rmCmd(c *cli.Context) error {
|
||||
return err
|
||||
}
|
||||
|
||||
runtime, err := getRuntime(c)
|
||||
runtime, err := libpodruntime.GetRuntime(c)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not get runtime")
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
|
||||
"github.com/containers/storage"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/projectatomic/libpod/cmd/podman/libpodruntime"
|
||||
"github.com/projectatomic/libpod/libpod/image"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
@ -38,7 +39,7 @@ func rmiCmd(c *cli.Context) error {
|
||||
return err
|
||||
}
|
||||
removeAll := c.Bool("all")
|
||||
runtime, err := getRuntime(c)
|
||||
runtime, err := libpodruntime.GetRuntime(c)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not get runtime")
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/projectatomic/libpod/cmd/podman/libpodruntime"
|
||||
"github.com/projectatomic/libpod/libpod"
|
||||
"github.com/projectatomic/libpod/libpod/image"
|
||||
"github.com/sirupsen/logrus"
|
||||
@ -49,7 +50,7 @@ func runCmd(c *cli.Context) error {
|
||||
}
|
||||
}
|
||||
|
||||
runtime, err := getRuntime(c)
|
||||
runtime, err := libpodruntime.GetRuntime(c)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "error creating libpod runtime")
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import (
|
||||
"github.com/containers/image/manifest"
|
||||
imgspecv1 "github.com/opencontainers/image-spec/specs-go/v1"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/projectatomic/libpod/cmd/podman/libpodruntime"
|
||||
"github.com/projectatomic/libpod/libpod"
|
||||
libpodImage "github.com/projectatomic/libpod/libpod/image"
|
||||
"github.com/sirupsen/logrus"
|
||||
@ -64,7 +65,7 @@ func saveCmd(c *cli.Context) error {
|
||||
return err
|
||||
}
|
||||
|
||||
runtime, err := getRuntime(c)
|
||||
runtime, err := libpodruntime.GetRuntime(c)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not create runtime")
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ import (
|
||||
"github.com/containers/image/docker"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/projectatomic/libpod/cmd/podman/formats"
|
||||
"github.com/projectatomic/libpod/cmd/podman/libpodruntime"
|
||||
"github.com/projectatomic/libpod/libpod/common"
|
||||
sysreg "github.com/projectatomic/libpod/pkg/registries"
|
||||
"github.com/sirupsen/logrus"
|
||||
@ -92,7 +93,7 @@ func searchCmd(c *cli.Context) error {
|
||||
return err
|
||||
}
|
||||
|
||||
runtime, err := getRuntime(c)
|
||||
runtime, err := libpodruntime.GetRuntime(c)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not get runtime")
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"os"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/projectatomic/libpod/cmd/podman/libpodruntime"
|
||||
"github.com/projectatomic/libpod/libpod"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/urfave/cli"
|
||||
@ -67,7 +68,7 @@ func startCmd(c *cli.Context) error {
|
||||
return errors.Wrapf(libpod.ErrInvalidArg, "you cannot use sig-proxy without --attach")
|
||||
}
|
||||
|
||||
runtime, err := getRuntime(c)
|
||||
runtime, err := libpodruntime.GetRuntime(c)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "error creating libpod runtime")
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ import (
|
||||
"github.com/docker/go-units"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/projectatomic/libpod/cmd/podman/formats"
|
||||
"github.com/projectatomic/libpod/cmd/podman/libpodruntime"
|
||||
"github.com/projectatomic/libpod/libpod"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
@ -78,7 +79,7 @@ func statsCmd(c *cli.Context) error {
|
||||
return errors.Errorf("--all, --latest and containers cannot be used together")
|
||||
}
|
||||
|
||||
runtime, err := getRuntime(c)
|
||||
runtime, err := libpodruntime.GetRuntime(c)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not get runtime")
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"os"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/projectatomic/libpod/cmd/podman/libpodruntime"
|
||||
"github.com/projectatomic/libpod/libpod"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
@ -54,7 +55,7 @@ func stopCmd(c *cli.Context) error {
|
||||
return err
|
||||
}
|
||||
|
||||
runtime, err := getRuntime(c)
|
||||
runtime, err := libpodruntime.GetRuntime(c)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not get runtime")
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"github.com/pkg/errors"
|
||||
"github.com/projectatomic/libpod/cmd/podman/libpodruntime"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
@ -21,7 +22,7 @@ func tagCmd(c *cli.Context) error {
|
||||
if len(args) < 2 {
|
||||
return errors.Errorf("image name and at least one new name must be specified")
|
||||
}
|
||||
runtime, err := getRuntime(c)
|
||||
runtime, err := libpodruntime.GetRuntime(c)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not create runtime")
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/projectatomic/libpod/cmd/podman/libpodruntime"
|
||||
"github.com/projectatomic/libpod/libpod"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
@ -42,7 +43,7 @@ func topCmd(c *cli.Context) error {
|
||||
return err
|
||||
}
|
||||
|
||||
runtime, err := getRuntime(c)
|
||||
runtime, err := libpodruntime.GetRuntime(c)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "error creating libpod runtime")
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"github.com/pkg/errors"
|
||||
"github.com/projectatomic/libpod/cmd/podman/libpodruntime"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
@ -17,7 +18,7 @@ var (
|
||||
)
|
||||
|
||||
func umountCmd(c *cli.Context) error {
|
||||
runtime, err := getRuntime(c)
|
||||
runtime, err := libpodruntime.GetRuntime(c)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not get runtime")
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"os"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/projectatomic/libpod/cmd/podman/libpodruntime"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
@ -24,7 +25,7 @@ var (
|
||||
)
|
||||
|
||||
func unpauseCmd(c *cli.Context) error {
|
||||
runtime, err := getRuntime(c)
|
||||
runtime, err := libpodruntime.GetRuntime(c)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not get runtime")
|
||||
}
|
||||
|
@ -5,69 +5,15 @@ import (
|
||||
"os"
|
||||
gosignal "os/signal"
|
||||
|
||||
"github.com/containers/storage"
|
||||
"github.com/docker/docker/pkg/signal"
|
||||
"github.com/docker/docker/pkg/term"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/projectatomic/libpod/libpod"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/urfave/cli"
|
||||
"golang.org/x/crypto/ssh/terminal"
|
||||
"k8s.io/client-go/tools/remotecommand"
|
||||
)
|
||||
|
||||
// Generate a new libpod runtime configured by command line options
|
||||
func getRuntime(c *cli.Context) (*libpod.Runtime, error) {
|
||||
options := []libpod.RuntimeOption{}
|
||||
|
||||
if c.GlobalIsSet("root") || c.GlobalIsSet("runroot") ||
|
||||
c.GlobalIsSet("storage-opt") || c.GlobalIsSet("storage-driver") {
|
||||
storageOpts := storage.DefaultStoreOptions
|
||||
|
||||
if c.GlobalIsSet("root") {
|
||||
storageOpts.GraphRoot = c.GlobalString("root")
|
||||
}
|
||||
if c.GlobalIsSet("runroot") {
|
||||
storageOpts.RunRoot = c.GlobalString("runroot")
|
||||
}
|
||||
if c.GlobalIsSet("storage-driver") {
|
||||
storageOpts.GraphDriverName = c.GlobalString("storage-driver")
|
||||
}
|
||||
if c.GlobalIsSet("storage-opt") {
|
||||
storageOpts.GraphDriverOptions = c.GlobalStringSlice("storage-opt")
|
||||
}
|
||||
|
||||
options = append(options, libpod.WithStorageConfig(storageOpts))
|
||||
}
|
||||
|
||||
// TODO CLI flags for image config?
|
||||
// TODO CLI flag for signature policy?
|
||||
|
||||
if c.GlobalIsSet("runtime") {
|
||||
options = append(options, libpod.WithOCIRuntime(c.GlobalString("runtime")))
|
||||
}
|
||||
|
||||
if c.GlobalIsSet("conmon") {
|
||||
options = append(options, libpod.WithConmonPath(c.GlobalString("conmon")))
|
||||
}
|
||||
|
||||
// TODO flag to set CGroup manager?
|
||||
// TODO flag to set libpod static dir?
|
||||
// TODO flag to set libpod tmp dir?
|
||||
|
||||
if c.GlobalIsSet("cni-config-dir") {
|
||||
options = append(options, libpod.WithCNIConfigDir(c.GlobalString("cni-config-dir")))
|
||||
}
|
||||
if c.GlobalIsSet("default-mounts-file") {
|
||||
options = append(options, libpod.WithDefaultMountsFile(c.GlobalString("default-mounts-file")))
|
||||
}
|
||||
options = append(options, libpod.WithHooksDir(c.GlobalString("hooks-dir-path")))
|
||||
|
||||
// TODO flag to set CNI plugins dir?
|
||||
|
||||
return libpod.NewRuntime(options...)
|
||||
}
|
||||
|
||||
// Attach to a container
|
||||
func attachCtr(ctr *libpod.Container, stdout, stderr, stdin *os.File, detachKeys string, sigProxy bool) error {
|
||||
resize := make(chan remotecommand.TerminalSize)
|
||||
|
@ -2,7 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"github.com/pkg/errors"
|
||||
"github.com/projectatomic/libpod/cmd/podman/ioprojectatomicpodman"
|
||||
ioprojectatomicpodman "github.com/projectatomic/libpod/cmd/podman/varlink"
|
||||
"github.com/projectatomic/libpod/pkg/varlinkapi"
|
||||
"github.com/projectatomic/libpod/version"
|
||||
"github.com/urfave/cli"
|
||||
@ -32,7 +32,7 @@ func varlinkCmd(c *cli.Context) error {
|
||||
return errors.Errorf("you must provide a varlink URI")
|
||||
}
|
||||
|
||||
var varlinkInterfaces = []*ioprojectatomicpodman.VarlinkInterface{varlinkapi.VarlinkLibpod}
|
||||
var varlinkInterfaces = []*ioprojectatomicpodman.VarlinkInterface{varlinkapi.New(c)}
|
||||
// Register varlink service. The metadata can be retrieved with:
|
||||
// $ varlink info [varlink address URI]
|
||||
service, err := varlink.NewService(
|
||||
|
@ -1,6 +1,8 @@
|
||||
# Podman Service Interface
|
||||
interface io.projectatomic.podman
|
||||
|
||||
|
||||
# Version is the structure returned by GetVersion
|
||||
type Version (
|
||||
version: string,
|
||||
go_version: string,
|
||||
@ -17,6 +19,40 @@ type StringResponse (
|
||||
message: string
|
||||
)
|
||||
|
||||
# ImageInList describes the structure that is returned in
|
||||
# ListImages.
|
||||
type ImageInList (
|
||||
id: string,
|
||||
parentId: string,
|
||||
repoTags: []string,
|
||||
repoDigests: []string,
|
||||
created: string,
|
||||
size: int,
|
||||
virtualSize: int,
|
||||
containers: int,
|
||||
labels: [string]string
|
||||
)
|
||||
|
||||
# ImageHistory describes the returned structure from ImageHistory.
|
||||
type ImageHistory (
|
||||
id: string,
|
||||
created: string,
|
||||
createdBy: string,
|
||||
tags: []string,
|
||||
size: int,
|
||||
comment: string
|
||||
)
|
||||
|
||||
# ImageSearch is the returned structure for SearchImage. It is returned
|
||||
# in arrary form.
|
||||
type ImageSearch (
|
||||
description: string,
|
||||
is_official: bool,
|
||||
is_automated: bool,
|
||||
name: string,
|
||||
star_count: int
|
||||
)
|
||||
|
||||
# System
|
||||
method Ping() -> (ping: StringResponse)
|
||||
method GetVersion() -> (version: Version)
|
||||
@ -45,21 +81,24 @@ method RemoveContainer() -> (notimplemented: NotImplemented)
|
||||
method DeleteStoppedContainers() -> (notimplemented: NotImplemented)
|
||||
|
||||
# Images
|
||||
method ListImages() -> (notimplemented: NotImplemented)
|
||||
method ListImages() -> (images: []ImageInList)
|
||||
method BuildImage() -> (notimplemented: NotImplemented)
|
||||
method CreateImage() -> (notimplemented: NotImplemented)
|
||||
method InspectImage() -> (notimplemented: NotImplemented)
|
||||
method HistoryImage() -> (notimplemented: NotImplemented)
|
||||
method PushImage() -> (notimplemented: NotImplemented)
|
||||
method TagImage() -> (notimplemented: NotImplemented)
|
||||
method RemoveImage() -> (notimplemented: NotImplemented)
|
||||
method SearchImage() -> (notimplemented: NotImplemented)
|
||||
method DeleteUnusedImages() -> (notimplemented: NotImplemented)
|
||||
method InspectImage(name: string) -> (image: string)
|
||||
method HistoryImage(name: string) -> (history: []ImageHistory)
|
||||
method PushImage(name: string, tag: string, tlsverify: bool) -> ()
|
||||
method TagImage(name: string, tagged: string) -> ()
|
||||
method RemoveImage(name: string, force: bool) -> ()
|
||||
method SearchImage(name: string, limit: int) -> (images: []ImageSearch)
|
||||
method DeleteUnusedImages() -> (images: []string)
|
||||
method CreateFromContainer() -> (notimplemented: NotImplemented)
|
||||
method ImportImage() -> (notimplemented: NotImplemented)
|
||||
method ExportImage() -> (notimplemented: NotImplemented)
|
||||
method PullImage() -> (notimplemented: NotImplemented)
|
||||
method ImportImage(source: string, reference: string, message: string, changes: []string) -> (id: string)
|
||||
method ExportImage(name: string, destination: string, compress: bool) -> ()
|
||||
method PullImage(name: string) -> (id: string)
|
||||
|
||||
|
||||
# Something failed
|
||||
error ActionFailed (reason: string)
|
||||
error ImageNotFound (imagename: string)
|
||||
error ErrorOccurred (reason: string)
|
||||
error RuntimeError (reason: string)
|
File diff suppressed because it is too large
Load Diff
@ -5,6 +5,7 @@ import (
|
||||
"os"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/projectatomic/libpod/cmd/podman/libpodruntime"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
@ -31,7 +32,7 @@ func waitCmd(c *cli.Context) error {
|
||||
return errors.Errorf("you must provide at least one container name or id")
|
||||
}
|
||||
|
||||
runtime, err := getRuntime(c)
|
||||
runtime, err := libpodruntime.GetRuntime(c)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "error creating libpod runtime")
|
||||
}
|
||||
|
4
contrib/libpodpy/__init__.py
Normal file
4
contrib/libpodpy/__init__.py
Normal file
@ -0,0 +1,4 @@
|
||||
|
||||
|
||||
#__version__ = version
|
||||
__title__ = 'libpod'
|
45
contrib/libpodpy/client.py
Normal file
45
contrib/libpodpy/client.py
Normal file
@ -0,0 +1,45 @@
|
||||
|
||||
from varlink import Client
|
||||
from libpodpy.images import Images
|
||||
from libpodpy.system import System
|
||||
from libpodpy.containers import Containers
|
||||
|
||||
class LibpodClient(object):
|
||||
|
||||
|
||||
"""
|
||||
A client for communicating with a Docker server.
|
||||
|
||||
Example:
|
||||
|
||||
>>> from libpodpy import client
|
||||
>>> c = client.LibpodClient("unix:/run/podman/io.projectatomic.podman")
|
||||
|
||||
Args:
|
||||
Requires the varlink URI for libpod
|
||||
"""
|
||||
|
||||
def __init__(self, varlink_uri):
|
||||
c = Client(address=varlink_uri)
|
||||
self.conn = c.open("io.projectatomic.podman")
|
||||
|
||||
@property
|
||||
def images(self):
|
||||
"""
|
||||
An object for managing images through libpod
|
||||
"""
|
||||
return Images(self.conn)
|
||||
|
||||
@property
|
||||
def system(self):
|
||||
"""
|
||||
An object for system related calls through libpod
|
||||
"""
|
||||
return System(self.conn)
|
||||
|
||||
@property
|
||||
def containers(self):
|
||||
"""
|
||||
An object for managing containers through libpod
|
||||
"""
|
||||
return Containers(self.conn)
|
8
contrib/libpodpy/containers.py
Normal file
8
contrib/libpodpy/containers.py
Normal file
@ -0,0 +1,8 @@
|
||||
|
||||
class Containers(object):
|
||||
|
||||
def __init__(self, client):
|
||||
self.client = client
|
||||
|
||||
def List(self):
|
||||
pass
|
15
contrib/libpodpy/images.py
Normal file
15
contrib/libpodpy/images.py
Normal file
@ -0,0 +1,15 @@
|
||||
|
||||
class Images(object):
|
||||
"""
|
||||
The Images class deals with image related functions for libpod.
|
||||
"""
|
||||
|
||||
def __init__(self, client):
|
||||
self.client = client
|
||||
|
||||
def List(self):
|
||||
"""
|
||||
Lists all images in the libpod image store
|
||||
return: a list of ImageList objects
|
||||
"""
|
||||
return self.client.ListImages()
|
10
contrib/libpodpy/system.py
Normal file
10
contrib/libpodpy/system.py
Normal file
@ -0,0 +1,10 @@
|
||||
|
||||
class System(object):
|
||||
def __init__(self, client):
|
||||
self.client = client
|
||||
|
||||
def Ping(self):
|
||||
return self.client.Ping()
|
||||
|
||||
def Version(self):
|
||||
return self.client.GetVersion()
|
@ -274,6 +274,15 @@ func (i *Image) Names() []string {
|
||||
return i.image.Names
|
||||
}
|
||||
|
||||
// RepoDigests returns a string array of repodigests associated with the image
|
||||
func (i *Image) RepoDigests() []string {
|
||||
var repoDigests []string
|
||||
for _, name := range i.Names() {
|
||||
repoDigests = append(repoDigests, strings.SplitN(name, ":", 2)[0]+"@"+i.Digest().String())
|
||||
}
|
||||
return repoDigests
|
||||
}
|
||||
|
||||
// Created returns the time the image was created
|
||||
func (i *Image) Created() time.Time {
|
||||
return i.image.Created
|
||||
@ -778,3 +787,18 @@ func splitString(input string) string {
|
||||
func (i *Image) InputIsID() bool {
|
||||
return strings.HasPrefix(i.ID(), i.InputName)
|
||||
}
|
||||
|
||||
// Containers a list of container IDs associated with the image
|
||||
func (i *Image) Containers() ([]string, error) {
|
||||
containers, err := i.imageruntime.store.Containers()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var imageContainers []string
|
||||
for _, c := range containers {
|
||||
if c.ImageID == i.ID() {
|
||||
imageContainers = append(imageContainers, c.ID)
|
||||
}
|
||||
}
|
||||
return imageContainers, err
|
||||
}
|
||||
|
@ -4,7 +4,6 @@ import (
|
||||
"runtime"
|
||||
"strconv"
|
||||
|
||||
"github.com/projectatomic/libpod/cmd/podman/ioprojectatomicpodman"
|
||||
podmanVersion "github.com/projectatomic/libpod/version"
|
||||
)
|
||||
|
||||
@ -20,7 +19,6 @@ var (
|
||||
|
||||
//Version is an output struct for varlink
|
||||
type Version struct {
|
||||
ioprojectatomicpodman.VarlinkInterface
|
||||
Version string
|
||||
GoVersion string
|
||||
GitCommit string
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/containers/image/types"
|
||||
"github.com/opencontainers/image-spec/specs-go/v1"
|
||||
"github.com/pkg/errors"
|
||||
"golang.org/x/crypto/ssh/terminal"
|
||||
)
|
||||
@ -54,3 +55,68 @@ func StringInSlice(s string, sl []string) bool {
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// GetImageConfig converts the --change flag values in the format "CMD=/bin/bash USER=example"
|
||||
// to a type v1.ImageConfig
|
||||
func GetImageConfig(changes []string) (v1.ImageConfig, error) {
|
||||
// USER=value | EXPOSE=value | ENV=value | ENTRYPOINT=value |
|
||||
// CMD=value | VOLUME=value | WORKDIR=value | LABEL=key=value | STOPSIGNAL=value
|
||||
|
||||
var (
|
||||
user string
|
||||
env []string
|
||||
entrypoint []string
|
||||
cmd []string
|
||||
workingDir string
|
||||
stopSignal string
|
||||
)
|
||||
|
||||
exposedPorts := make(map[string]struct{})
|
||||
volumes := make(map[string]struct{})
|
||||
labels := make(map[string]string)
|
||||
|
||||
for _, ch := range changes {
|
||||
pair := strings.Split(ch, "=")
|
||||
if len(pair) == 1 {
|
||||
return v1.ImageConfig{}, errors.Errorf("no value given for instruction %q", ch)
|
||||
}
|
||||
switch pair[0] {
|
||||
case "USER":
|
||||
user = pair[1]
|
||||
case "EXPOSE":
|
||||
var st struct{}
|
||||
exposedPorts[pair[1]] = st
|
||||
case "ENV":
|
||||
env = append(env, pair[1])
|
||||
case "ENTRYPOINT":
|
||||
entrypoint = append(entrypoint, pair[1])
|
||||
case "CMD":
|
||||
cmd = append(cmd, pair[1])
|
||||
case "VOLUME":
|
||||
var st struct{}
|
||||
volumes[pair[1]] = st
|
||||
case "WORKDIR":
|
||||
workingDir = pair[1]
|
||||
case "LABEL":
|
||||
if len(pair) == 3 {
|
||||
labels[pair[1]] = pair[2]
|
||||
} else {
|
||||
labels[pair[1]] = ""
|
||||
}
|
||||
case "STOPSIGNAL":
|
||||
stopSignal = pair[1]
|
||||
}
|
||||
}
|
||||
|
||||
return v1.ImageConfig{
|
||||
User: user,
|
||||
ExposedPorts: exposedPorts,
|
||||
Env: env,
|
||||
Entrypoint: entrypoint,
|
||||
Cmd: cmd,
|
||||
Volumes: volumes,
|
||||
WorkingDir: workingDir,
|
||||
Labels: labels,
|
||||
StopSignal: stopSignal,
|
||||
}, nil
|
||||
}
|
||||
|
@ -1,14 +1,18 @@
|
||||
package varlinkapi
|
||||
|
||||
import "github.com/projectatomic/libpod/cmd/podman/ioprojectatomicpodman"
|
||||
import (
|
||||
ioprojectatomicpodman "github.com/projectatomic/libpod/cmd/podman/varlink"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
// LibpodAPI is the basic varlink struct for libpod
|
||||
type LibpodAPI struct {
|
||||
Cli *cli.Context
|
||||
ioprojectatomicpodman.VarlinkInterface
|
||||
}
|
||||
|
||||
var (
|
||||
lp = LibpodAPI{}
|
||||
// VarlinkLibpod instantiation
|
||||
VarlinkLibpod = ioprojectatomicpodman.VarlinkNew(&lp)
|
||||
)
|
||||
// New creates a new varlink client
|
||||
func New(cli *cli.Context) *ioprojectatomicpodman.VarlinkInterface {
|
||||
lp := LibpodAPI{Cli: cli}
|
||||
return ioprojectatomicpodman.VarlinkNew(&lp)
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
package varlinkapi
|
||||
|
||||
import (
|
||||
"github.com/projectatomic/libpod/cmd/podman/ioprojectatomicpodman"
|
||||
ioprojectatomicpodman "github.com/projectatomic/libpod/cmd/podman/varlink"
|
||||
)
|
||||
|
||||
// ListContainers ...
|
||||
|
@ -1,75 +1,285 @@
|
||||
package varlinkapi
|
||||
|
||||
import (
|
||||
"github.com/projectatomic/libpod/cmd/podman/ioprojectatomicpodman"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/containers/image/docker"
|
||||
"github.com/opencontainers/image-spec/specs-go/v1"
|
||||
"github.com/projectatomic/libpod/cmd/podman/libpodruntime"
|
||||
ioprojectatomicpodman "github.com/projectatomic/libpod/cmd/podman/varlink"
|
||||
"github.com/projectatomic/libpod/libpod/image"
|
||||
sysreg "github.com/projectatomic/libpod/pkg/registries"
|
||||
"github.com/projectatomic/libpod/pkg/util"
|
||||
)
|
||||
|
||||
// ListImages ...
|
||||
// ListImages lists all the images in the store
|
||||
// It requires no inputs.
|
||||
func (i *LibpodAPI) ListImages(call ioprojectatomicpodman.VarlinkCall) error {
|
||||
return call.ReplyMethodNotImplemented("ListImages")
|
||||
runtime, err := libpodruntime.GetRuntime(i.Cli)
|
||||
if err != nil {
|
||||
return call.ReplyRuntimeError(err.Error())
|
||||
}
|
||||
images, err := runtime.ImageRuntime().GetImages()
|
||||
if err != nil {
|
||||
return call.ReplyErrorOccurred(fmt.Sprintf("unable to get list of images %q", err))
|
||||
}
|
||||
var imageList []ioprojectatomicpodman.ImageInList
|
||||
for _, image := range images {
|
||||
//size, _:= image.Size(getContext())
|
||||
labels, _ := image.Labels(getContext())
|
||||
containers, _ := image.Containers()
|
||||
|
||||
i := ioprojectatomicpodman.ImageInList{
|
||||
Id: image.ID(),
|
||||
ParentId: image.Parent,
|
||||
RepoTags: image.Names(),
|
||||
RepoDigests: image.RepoDigests(),
|
||||
Created: image.Created().String(),
|
||||
//Size: size,
|
||||
VirtualSize: image.VirtualSize,
|
||||
Containers: int64(len(containers)),
|
||||
Labels: labels,
|
||||
}
|
||||
imageList = append(imageList, i)
|
||||
}
|
||||
return call.ReplyListImages(imageList)
|
||||
}
|
||||
|
||||
// BuildImage ...
|
||||
// TODO Waiting for buildah to be vendored into libpod to do this only one
|
||||
func (i *LibpodAPI) BuildImage(call ioprojectatomicpodman.VarlinkCall) error {
|
||||
return call.ReplyMethodNotImplemented("BuildImage")
|
||||
}
|
||||
|
||||
// CreateImage ...
|
||||
// TODO With Pull being added, should we skip Create?
|
||||
func (i *LibpodAPI) CreateImage(call ioprojectatomicpodman.VarlinkCall) error {
|
||||
return call.ReplyMethodNotImplemented("CreateImage")
|
||||
}
|
||||
|
||||
// InspectImage ...
|
||||
func (i *LibpodAPI) InspectImage(call ioprojectatomicpodman.VarlinkCall) error {
|
||||
return call.ReplyMethodNotImplemented("InspectImage")
|
||||
// InspectImage returns an image's inspect information as a string that can be serialized.
|
||||
// Requires an image ID or name
|
||||
func (i *LibpodAPI) InspectImage(call ioprojectatomicpodman.VarlinkCall, name string) error {
|
||||
runtime, err := libpodruntime.GetRuntime(i.Cli)
|
||||
if err != nil {
|
||||
return call.ReplyRuntimeError(err.Error())
|
||||
}
|
||||
newImage, err := runtime.ImageRuntime().NewFromLocal(name)
|
||||
if err != nil {
|
||||
return call.ReplyImageNotFound(name)
|
||||
}
|
||||
inspectInfo, err := newImage.Inspect(getContext())
|
||||
b, err := json.Marshal(inspectInfo)
|
||||
if err != nil {
|
||||
return call.ReplyErrorOccurred(fmt.Sprintf("unable to serialize"))
|
||||
}
|
||||
return call.ReplyInspectImage(string(b))
|
||||
}
|
||||
|
||||
// HistoryImage ...
|
||||
func (i *LibpodAPI) HistoryImage(call ioprojectatomicpodman.VarlinkCall) error {
|
||||
return call.ReplyMethodNotImplemented("HistoryImage")
|
||||
// HistoryImage returns the history of the image's layers
|
||||
// Requires an image or name
|
||||
func (i *LibpodAPI) HistoryImage(call ioprojectatomicpodman.VarlinkCall, name string) error {
|
||||
runtime, err := libpodruntime.GetRuntime(i.Cli)
|
||||
if err != nil {
|
||||
return call.ReplyRuntimeError(err.Error())
|
||||
}
|
||||
newImage, err := runtime.ImageRuntime().NewFromLocal(name)
|
||||
if err != nil {
|
||||
return call.ReplyImageNotFound(name)
|
||||
}
|
||||
history, layerInfos, err := newImage.History(getContext())
|
||||
if err != nil {
|
||||
return call.ReplyErrorOccurred(err.Error())
|
||||
}
|
||||
var histories []ioprojectatomicpodman.ImageHistory
|
||||
for i, h := range history {
|
||||
imageHistory := ioprojectatomicpodman.ImageHistory{
|
||||
Id: newImage.ID(),
|
||||
Created: h.Created.String(),
|
||||
CreatedBy: h.CreatedBy,
|
||||
Tags: newImage.Names(),
|
||||
Size: layerInfos[i].Size,
|
||||
Comment: h.Comment,
|
||||
}
|
||||
histories = append(histories, imageHistory)
|
||||
}
|
||||
return call.ReplyHistoryImage(histories)
|
||||
}
|
||||
|
||||
// PushImage ...
|
||||
func (i *LibpodAPI) PushImage(call ioprojectatomicpodman.VarlinkCall) error {
|
||||
return call.ReplyMethodNotImplemented("PushImage")
|
||||
// PushImage pushes an local image to registry
|
||||
// TODO We need to add options for signing, credentials, and tls
|
||||
func (i *LibpodAPI) PushImage(call ioprojectatomicpodman.VarlinkCall, name, tag string, tlsVerify bool) error {
|
||||
runtime, err := libpodruntime.GetRuntime(i.Cli)
|
||||
if err != nil {
|
||||
return call.ReplyRuntimeError(err.Error())
|
||||
}
|
||||
newImage, err := runtime.ImageRuntime().NewFromLocal(name)
|
||||
if err != nil {
|
||||
return call.ReplyImageNotFound(err.Error())
|
||||
}
|
||||
destname := name
|
||||
if tag != "" {
|
||||
destname = tag
|
||||
}
|
||||
|
||||
dockerRegistryOptions := image.DockerRegistryOptions{
|
||||
DockerInsecureSkipTLSVerify: !tlsVerify,
|
||||
}
|
||||
|
||||
so := image.SigningOptions{}
|
||||
|
||||
if err := newImage.PushImage(getContext(), destname, "", "", "", nil, false, so, &dockerRegistryOptions); err != nil {
|
||||
return call.ReplyErrorOccurred(err.Error())
|
||||
}
|
||||
return call.ReplyPushImage()
|
||||
}
|
||||
|
||||
// TagImage ...
|
||||
func (i *LibpodAPI) TagImage(call ioprojectatomicpodman.VarlinkCall) error {
|
||||
return call.ReplyMethodNotImplemented("TagImage")
|
||||
// TagImage accepts an image name and tag as strings and tags an image in the local store.
|
||||
func (i *LibpodAPI) TagImage(call ioprojectatomicpodman.VarlinkCall, name, tag string) error {
|
||||
runtime, err := libpodruntime.GetRuntime(i.Cli)
|
||||
if err != nil {
|
||||
return call.ReplyRuntimeError(err.Error())
|
||||
}
|
||||
newImage, err := runtime.ImageRuntime().NewFromLocal(name)
|
||||
if err != nil {
|
||||
return call.ReplyImageNotFound(name)
|
||||
}
|
||||
if err := newImage.TagImage(tag); err != nil {
|
||||
return call.ReplyErrorOccurred(err.Error())
|
||||
}
|
||||
return call.ReplyTagImage()
|
||||
}
|
||||
|
||||
// RemoveImage ...
|
||||
func (i *LibpodAPI) RemoveImage(call ioprojectatomicpodman.VarlinkCall) error {
|
||||
return call.ReplyMethodNotImplemented("RemoveImage")
|
||||
// RemoveImage accepts a image name or ID as a string and force bool to determine if it should
|
||||
// remove the image even if being used by stopped containers
|
||||
func (i *LibpodAPI) RemoveImage(call ioprojectatomicpodman.VarlinkCall, name string, force bool) error {
|
||||
runtime, err := libpodruntime.GetRuntime(i.Cli)
|
||||
if err != nil {
|
||||
return call.ReplyRuntimeError(err.Error())
|
||||
}
|
||||
newImage, err := runtime.ImageRuntime().NewFromLocal(name)
|
||||
if err != nil {
|
||||
return call.ReplyImageNotFound(name)
|
||||
}
|
||||
if err := newImage.Remove(force); err != nil {
|
||||
return call.ReplyErrorOccurred(err.Error())
|
||||
}
|
||||
return call.ReplyRemoveImage()
|
||||
}
|
||||
|
||||
// SearchImage ...
|
||||
func (i *LibpodAPI) SearchImage(call ioprojectatomicpodman.VarlinkCall) error {
|
||||
return call.ReplyMethodNotImplemented("SearchImage")
|
||||
// SearchImage searches all registries configured in /etc/containers/registries.conf for an image
|
||||
// Requires an image name and a search limit as int
|
||||
func (i *LibpodAPI) SearchImage(call ioprojectatomicpodman.VarlinkCall, name string, limit int64) error {
|
||||
sc := image.GetSystemContext("", "", false)
|
||||
registries, err := sysreg.GetRegistries()
|
||||
if err != nil {
|
||||
return call.ReplyErrorOccurred(fmt.Sprintf("unable to get system registries: %q", err))
|
||||
}
|
||||
var imageResults []ioprojectatomicpodman.ImageSearch
|
||||
for _, reg := range registries {
|
||||
results, err := docker.SearchRegistry(getContext(), sc, reg, name, int(limit))
|
||||
if err != nil {
|
||||
return call.ReplyErrorOccurred(err.Error())
|
||||
}
|
||||
for _, result := range results {
|
||||
i := ioprojectatomicpodman.ImageSearch{
|
||||
Description: result.Description,
|
||||
Is_official: result.IsOfficial,
|
||||
Is_automated: result.IsAutomated,
|
||||
Name: result.Name,
|
||||
Star_count: int64(result.StarCount),
|
||||
}
|
||||
imageResults = append(imageResults, i)
|
||||
}
|
||||
}
|
||||
return call.ReplySearchImage(imageResults)
|
||||
}
|
||||
|
||||
// DeleteUnusedImages ...
|
||||
// DeleteUnusedImages deletes any images that do not have containers associated with it.
|
||||
// TODO Filters are not implemented
|
||||
func (i *LibpodAPI) DeleteUnusedImages(call ioprojectatomicpodman.VarlinkCall) error {
|
||||
return call.ReplyMethodNotImplemented("DeleteUnusedImages")
|
||||
runtime, err := libpodruntime.GetRuntime(i.Cli)
|
||||
if err != nil {
|
||||
return call.ReplyRuntimeError(err.Error())
|
||||
}
|
||||
images, err := runtime.ImageRuntime().GetImages()
|
||||
if err != nil {
|
||||
return call.ReplyErrorOccurred(err.Error())
|
||||
}
|
||||
var deletedImages []string
|
||||
for _, img := range images {
|
||||
containers, err := img.Containers()
|
||||
if err != nil {
|
||||
return call.ReplyErrorOccurred(err.Error())
|
||||
}
|
||||
if len(containers) == 0 {
|
||||
if err := img.Remove(false); err != nil {
|
||||
return call.ReplyErrorOccurred(err.Error())
|
||||
}
|
||||
deletedImages = append(deletedImages, img.ID())
|
||||
}
|
||||
}
|
||||
return call.ReplyDeleteUnusedImages(deletedImages)
|
||||
}
|
||||
|
||||
// CreateFromContainer ...
|
||||
// TODO This must wait until buildah is properly vendored into libpod
|
||||
func (i *LibpodAPI) CreateFromContainer(call ioprojectatomicpodman.VarlinkCall) error {
|
||||
return call.ReplyMethodNotImplemented("CreateFromContainer")
|
||||
}
|
||||
|
||||
// ImportImage ...
|
||||
func (i *LibpodAPI) ImportImage(call ioprojectatomicpodman.VarlinkCall) error {
|
||||
return call.ReplyMethodNotImplemented("ImportImage")
|
||||
// ImportImage imports an image from a tarball to the image store
|
||||
func (i *LibpodAPI) ImportImage(call ioprojectatomicpodman.VarlinkCall, source, reference, message string, changes []string) error {
|
||||
runtime, err := libpodruntime.GetRuntime(i.Cli)
|
||||
if err != nil {
|
||||
return call.ReplyRuntimeError(err.Error())
|
||||
}
|
||||
configChanges, err := util.GetImageConfig(changes)
|
||||
if err != nil {
|
||||
return call.ReplyErrorOccurred(err.Error())
|
||||
}
|
||||
history := []v1.History{
|
||||
{Comment: message},
|
||||
}
|
||||
config := v1.Image{
|
||||
Config: configChanges,
|
||||
History: history,
|
||||
}
|
||||
newImage, err := runtime.ImageRuntime().Import(getContext(), source, reference, nil, image.SigningOptions{}, config)
|
||||
if err != nil {
|
||||
return call.ReplyErrorOccurred(err.Error())
|
||||
}
|
||||
return call.ReplyImportImage(newImage.ID())
|
||||
}
|
||||
|
||||
// ExportImage ...
|
||||
func (i *LibpodAPI) ExportImage(call ioprojectatomicpodman.VarlinkCall) error {
|
||||
return call.ReplyMethodNotImplemented("ExportImage")
|
||||
// ExportImage exports an image to the provided destination
|
||||
// destination must have the transport type!!
|
||||
func (i *LibpodAPI) ExportImage(call ioprojectatomicpodman.VarlinkCall, name, destination string, compress bool) error {
|
||||
runtime, err := libpodruntime.GetRuntime(i.Cli)
|
||||
if err != nil {
|
||||
return call.ReplyRuntimeError(err.Error())
|
||||
}
|
||||
newImage, err := runtime.ImageRuntime().NewFromLocal(name)
|
||||
if err != nil {
|
||||
return call.ReplyImageNotFound(name)
|
||||
}
|
||||
if err := newImage.PushImage(getContext(), destination, "", "", "", nil, compress, image.SigningOptions{}, &image.DockerRegistryOptions{}); err != nil {
|
||||
return call.ReplyErrorOccurred(err.Error())
|
||||
}
|
||||
return call.ReplyExportImage()
|
||||
}
|
||||
|
||||
// PullImage ...
|
||||
func (i *LibpodAPI) PullImage(call ioprojectatomicpodman.VarlinkCall) error {
|
||||
return call.ReplyMethodNotImplemented("PullImage")
|
||||
// PullImage pulls an image from a registry to the image store.
|
||||
// TODO This implementation is incomplete
|
||||
func (i *LibpodAPI) PullImage(call ioprojectatomicpodman.VarlinkCall, name string) error {
|
||||
runtime, err := libpodruntime.GetRuntime(i.Cli)
|
||||
if err != nil {
|
||||
return call.ReplyRuntimeError(err.Error())
|
||||
}
|
||||
newImage, err := runtime.ImageRuntime().New(getContext(), name, "", "", nil, &image.DockerRegistryOptions{}, image.SigningOptions{}, true, false)
|
||||
if err != nil {
|
||||
return call.ReplyErrorOccurred(fmt.Sprintf("unable to pull %s", name))
|
||||
}
|
||||
return call.ReplyPullImage(newImage.ID())
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
package varlinkapi
|
||||
|
||||
import (
|
||||
"github.com/projectatomic/libpod/cmd/podman/ioprojectatomicpodman"
|
||||
ioprojectatomicpodman "github.com/projectatomic/libpod/cmd/podman/varlink"
|
||||
"github.com/projectatomic/libpod/libpod"
|
||||
)
|
||||
|
||||
|
10
pkg/varlinkapi/util.go
Normal file
10
pkg/varlinkapi/util.go
Normal file
@ -0,0 +1,10 @@
|
||||
package varlinkapi
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
// getContext returns a non-nil, empty context
|
||||
func getContext() context.Context {
|
||||
return context.TODO()
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
from varlink import (Client, VarlinkError)
|
||||
import json
|
||||
|
||||
address = "unix:/run/podman/io.projectatomic.podman"
|
||||
|
||||
with Client(address=address) as client:
|
||||
podman = client.open('io.projectatomic.podman')
|
||||
response = podman.GetVersion()
|
||||
print(json.dumps(response, indent=4, separators=(',', ': ')))
|
Reference in New Issue
Block a user