Skip to content

Commit

Permalink
varlink images
Browse files Browse the repository at this point in the history
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
  • Loading branch information
baude authored and rh-atomic-bot committed Apr 26, 2018
1 parent 0ccfd7d commit 39a7a77
Show file tree
Hide file tree
Showing 55 changed files with 1,221 additions and 642 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion cmd/podman/attach.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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")
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/podman/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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")
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/podman/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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")
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/podman/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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")
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/podman/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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")
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/podman/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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")
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/podman/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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")
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/podman/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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")
}
Expand Down
72 changes: 4 additions & 68 deletions cmd/podman/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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")
}
Expand All @@ -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)
}
Expand Down Expand Up @@ -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
}
3 changes: 2 additions & 1 deletion cmd/podman/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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")
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/podman/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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")
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/podman/kill.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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")
}
Expand Down
59 changes: 59 additions & 0 deletions cmd/podman/libpodruntime/runtime.go
Original file line number Diff line number Diff line change
@@ -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...)
}
3 changes: 2 additions & 1 deletion cmd/podman/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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")
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/podman/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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")
}
Expand Down
Loading

1 comment on commit 39a7a77

@baude
Copy link
Member Author

@baude baude commented on 39a7a77 May 1, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.