summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile6
-rw-r--r--README.md6
-rw-r--r--cmd/podman/commands.go2
-rw-r--r--cmd/podman/container.go1
-rw-r--r--cmd/podman/main.go1
-rw-r--r--cmd/podman/restart.go84
-rw-r--r--pkg/adapter/containers.go69
-rw-r--r--pkg/adapter/containers_remote.go79
-rw-r--r--test/e2e/restart_test.go2
-rw-r--r--test/system/005-info.bats4
-rw-r--r--test/system/030-run.bats2
-rw-r--r--test/system/035-logs.bats2
-rw-r--r--test/system/070-build.bats6
-rw-r--r--test/system/400-unprivileged-access.bats8
14 files changed, 190 insertions, 82 deletions
diff --git a/Makefile b/Makefile
index ebd0ddf2d..1990c2d11 100644
--- a/Makefile
+++ b/Makefile
@@ -152,6 +152,12 @@ libpodimage: ## Build the libpod image
dbuild: libpodimage
${CONTAINER_RUNTIME} run --name=${LIBPOD_INSTANCE} --privileged -v ${PWD}:/go/src/${PROJECT} --rm ${LIBPOD_IMAGE} make all
+dbuild-podman-remote: libpodimage
+ ${CONTAINER_RUNTIME} run --name=${LIBPOD_INSTANCE} --privileged -v ${PWD}:/go/src/${PROJECT} --rm ${LIBPOD_IMAGE} go build -ldflags '$(LDFLAGS_PODMAN)' -tags "$(BUILDTAGS) remoteclient" -o bin/podman-remote $(PROJECT)/cmd/podman
+
+dbuild-podman-remote-darwin: libpodimage
+ ${CONTAINER_RUNTIME} run --name=${LIBPOD_INSTANCE} --privileged -v ${PWD}:/go/src/${PROJECT} --rm ${LIBPOD_IMAGE} env GOOS=darwin go build -ldflags '$(LDFLAGS_PODMAN)' -tags "remoteclient containers_image_openpgp exclude_graphdriver_devicemapper" -o bin/podman-remote-darwin $(PROJECT)/cmd/podman
+
test: libpodimage ## Run tests on built image
${CONTAINER_RUNTIME} run -e STORAGE_OPTIONS="--storage-driver=vfs" -e TESTFLAGS -e OCI_RUNTIME -e CGROUP_MANAGER=cgroupfs -e TRAVIS -t --privileged --rm -v ${CURDIR}:/go/src/${PROJECT} ${LIBPOD_IMAGE} make clean all localunit install.catatonit localintegration
diff --git a/README.md b/README.md
index 73a7057ea..da516fa0d 100644
--- a/README.md
+++ b/README.md
@@ -45,7 +45,11 @@ This project tests all builds against each supported version of Fedora, the late
Podman can also generate Kubernetes YAML based on a container or Pod (see
[podman-generate-kube](https://github.com/containers/libpod/blob/master/docs/podman-generate-kube.1.md)),
which allows for an easy transition from a local development environment
- to a production Kubernetes cluster.
+ to a production Kubernetes cluster. If Kubernetes does not fit your requirements,
+ there are other third-party tools that support the docker-compose format such as
+ [kompose](https://github.com/kubernetes/kompose/) and
+ [podman-compose](https://github.com/muayyad-alsadi/podman-compose)
+ that might be appropriate for your environment.
## OCI Projects Plans
diff --git a/cmd/podman/commands.go b/cmd/podman/commands.go
index c36452cfe..7680d6df2 100644
--- a/cmd/podman/commands.go
+++ b/cmd/podman/commands.go
@@ -19,7 +19,6 @@ func getMainCommands() []*cobra.Command {
_mountCommand,
_portCommand,
_refreshCommand,
- _restartCommand,
_searchCommand,
_statsCommand,
_topCommand,
@@ -50,7 +49,6 @@ func getContainerSubCommands() []*cobra.Command {
_portCommand,
_pruneContainersCommand,
_refreshCommand,
- _restartCommand,
_restoreCommand,
_runlabelCommand,
_statsCommand,
diff --git a/cmd/podman/container.go b/cmd/podman/container.go
index 7733c8eef..28e0f0e4a 100644
--- a/cmd/podman/container.go
+++ b/cmd/podman/container.go
@@ -60,6 +60,7 @@ var (
_listSubCommand,
_logsCommand,
_pauseCommand,
+ _restartCommand,
_runCommand,
_rmCommand,
_startCommand,
diff --git a/cmd/podman/main.go b/cmd/podman/main.go
index 15f4a5d71..392dfe542 100644
--- a/cmd/podman/main.go
+++ b/cmd/podman/main.go
@@ -50,6 +50,7 @@ var mainCommands = []*cobra.Command{
&_psCommand,
_pullCommand,
_pushCommand,
+ _restartCommand,
_rmCommand,
&_rmiCommand,
_runCommand,
diff --git a/cmd/podman/restart.go b/cmd/podman/restart.go
index 5a9f3043a..9ab2dd528 100644
--- a/cmd/podman/restart.go
+++ b/cmd/podman/restart.go
@@ -2,11 +2,9 @@ package main
import (
"github.com/containers/libpod/cmd/podman/cliconfig"
- "github.com/containers/libpod/cmd/podman/libpodruntime"
- "github.com/containers/libpod/cmd/podman/shared"
"github.com/containers/libpod/libpod"
+ "github.com/containers/libpod/pkg/adapter"
"github.com/pkg/errors"
- "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
@@ -22,7 +20,6 @@ var (
RunE: func(cmd *cobra.Command, args []string) error {
restartCommand.InputArgs = args
restartCommand.GlobalFlags = MainGlobalOpts
- restartCommand.Remote = remoteclient
return restartCmd(&restartCommand)
},
Args: func(cmd *cobra.Command, args []string) error {
@@ -49,83 +46,30 @@ func init() {
}
func restartCmd(c *cliconfig.RestartValues) error {
- var (
- restartFuncs []shared.ParallelWorkerInput
- containers []*libpod.Container
- restartContainers []*libpod.Container
- )
-
- args := c.InputArgs
- runOnly := c.Running
all := c.All
- if len(args) < 1 && !c.Latest && !all {
+ if len(c.InputArgs) < 1 && !c.Latest && !all {
return errors.Wrapf(libpod.ErrInvalidArg, "you must provide at least one container name or ID")
}
- runtime, err := libpodruntime.GetRuntime(&c.PodmanCommand)
+ runtime, err := adapter.GetRuntime(&c.PodmanCommand)
if err != nil {
return errors.Wrapf(err, "error creating libpod runtime")
}
defer runtime.Shutdown(false)
- timeout := c.Timeout
- useTimeout := c.Flag("timeout").Changed || c.Flag("time").Changed
-
- // Handle --latest
- if c.Latest {
- lastCtr, err := runtime.GetLatestContainer()
- if err != nil {
- return errors.Wrapf(err, "unable to get latest container")
- }
- restartContainers = append(restartContainers, lastCtr)
- } else if runOnly {
- containers, err = getAllOrLatestContainers(&c.PodmanCommand, runtime, libpod.ContainerStateRunning, "running")
- if err != nil {
- return err
- }
- restartContainers = append(restartContainers, containers...)
- } else if all {
- containers, err = runtime.GetAllContainers()
- if err != nil {
- return err
- }
- restartContainers = append(restartContainers, containers...)
- } else {
- for _, id := range args {
- ctr, err := runtime.LookupContainer(id)
- if err != nil {
- return err
+ ok, failures, err := runtime.Restart(getContext(), c)
+ if err != nil {
+ if errors.Cause(err) == libpod.ErrNoSuchCtr {
+ if len(c.InputArgs) > 1 {
+ exitCode = 125
+ } else {
+ exitCode = 1
}
- restartContainers = append(restartContainers, ctr)
}
+ return err
}
-
- maxWorkers := shared.Parallelize("restart")
- if c.GlobalIsSet("max-workers") {
- maxWorkers = c.GlobalFlags.MaxWorks
+ if len(failures) > 0 {
+ exitCode = 125
}
-
- logrus.Debugf("Setting maximum workers to %d", maxWorkers)
-
- // We now have a slice of all the containers to be restarted. Iterate them to
- // create restart Funcs with a timeout as needed
- for _, ctr := range restartContainers {
- con := ctr
- ctrTimeout := ctr.StopTimeout()
- if useTimeout {
- ctrTimeout = timeout
- }
-
- f := func() error {
- return con.RestartWithTimeout(getContext(), ctrTimeout)
- }
-
- restartFuncs = append(restartFuncs, shared.ParallelWorkerInput{
- ContainerID: con.ID(),
- ParallelFunc: f,
- })
- }
-
- restartErrors, errCount := shared.ParallelExecuteWorkerPool(maxWorkers, restartFuncs)
- return printParallelOutput(restartErrors, errCount)
+ return printCmdResults(ok, failures)
}
diff --git a/pkg/adapter/containers.go b/pkg/adapter/containers.go
index a5b911da1..8481a0cec 100644
--- a/pkg/adapter/containers.go
+++ b/pkg/adapter/containers.go
@@ -697,3 +697,72 @@ func (r *LocalRuntime) UnpauseContainers(ctx context.Context, cli *cliconfig.Unp
}
return pool.Run()
}
+
+// Restart containers without or without a timeout
+func (r *LocalRuntime) Restart(ctx context.Context, c *cliconfig.RestartValues) ([]string, map[string]error, error) {
+ var (
+ containers []*libpod.Container
+ restartContainers []*libpod.Container
+ err error
+ )
+ useTimeout := c.Flag("timeout").Changed || c.Flag("time").Changed
+ inputTimeout := c.Timeout
+
+ // Handle --latest
+ if c.Latest {
+ lastCtr, err := r.Runtime.GetLatestContainer()
+ if err != nil {
+ return nil, nil, errors.Wrapf(err, "unable to get latest container")
+ }
+ restartContainers = append(restartContainers, lastCtr)
+ } else if c.Running {
+ containers, err = r.GetRunningContainers()
+ if err != nil {
+ return nil, nil, err
+ }
+ restartContainers = append(restartContainers, containers...)
+ } else if c.All {
+ containers, err = r.Runtime.GetAllContainers()
+ if err != nil {
+ return nil, nil, err
+ }
+ restartContainers = append(restartContainers, containers...)
+ } else {
+ for _, id := range c.InputArgs {
+ ctr, err := r.Runtime.LookupContainer(id)
+ if err != nil {
+ return nil, nil, err
+ }
+ restartContainers = append(restartContainers, ctr)
+ }
+ }
+
+ maxWorkers := shared.DefaultPoolSize("restart")
+ if c.GlobalIsSet("max-workers") {
+ maxWorkers = c.GlobalFlags.MaxWorks
+ }
+
+ logrus.Debugf("Setting maximum workers to %d", maxWorkers)
+
+ // We now have a slice of all the containers to be restarted. Iterate them to
+ // create restart Funcs with a timeout as needed
+ pool := shared.NewPool("restart", maxWorkers, len(restartContainers))
+ for _, c := range restartContainers {
+ ctr := c
+ timeout := ctr.StopTimeout()
+ if useTimeout {
+ timeout = inputTimeout
+ }
+ pool.Add(shared.Job{
+ ID: ctr.ID(),
+ Fn: func() error {
+ err := ctr.RestartWithTimeout(ctx, timeout)
+ if err != nil {
+ logrus.Debugf("Failed to restart container %s: %s", ctr.ID(), err.Error())
+ }
+ return err
+ },
+ })
+ }
+ return pool.Run()
+}
diff --git a/pkg/adapter/containers_remote.go b/pkg/adapter/containers_remote.go
index cb61871bf..e8f221eaf 100644
--- a/pkg/adapter/containers_remote.go
+++ b/pkg/adapter/containers_remote.go
@@ -45,6 +45,12 @@ func (c *Container) ID() string {
return c.config.ID
}
+// Restart a single container
+func (c *Container) Restart(timeout int64) error {
+ _, err := iopodman.RestartContainer().Call(c.Runtime.Conn, c.ID(), timeout)
+ return err
+}
+
// Pause a container
func (c *Container) Pause() error {
_, err := iopodman.PauseContainer().Call(c.Runtime.Conn, c.ID())
@@ -132,6 +138,23 @@ func (r *LocalRuntime) LookupContainer(idOrName string) (*Container, error) {
}, nil
}
+// GetAllContainers returns all containers in a slice
+func (r *LocalRuntime) GetAllContainers() ([]*Container, error) {
+ var containers []*Container
+ ctrs, err := iopodman.GetContainersByContext().Call(r.Conn, true, false, []string{})
+ if err != nil {
+ return nil, err
+ }
+ for _, ctr := range ctrs {
+ container, err := r.LookupContainer(ctr)
+ if err != nil {
+ return nil, err
+ }
+ containers = append(containers, container)
+ }
+ return containers, nil
+}
+
func (r *LocalRuntime) LookupContainersWithStatus(filters []string) ([]*Container, error) {
var containers []*Container
ctrs, err := iopodman.GetContainersByStatus().Call(r.Conn, filters)
@@ -753,3 +776,59 @@ func (r *LocalRuntime) UnpauseContainers(ctx context.Context, cli *cliconfig.Unp
}
return ok, failures, nil
}
+
+// Restart restarts a container over varlink
+func (r *LocalRuntime) Restart(ctx context.Context, c *cliconfig.RestartValues) ([]string, map[string]error, error) {
+ var (
+ containers []*Container
+ restartContainers []*Container
+ err error
+ ok = []string{}
+ failures = map[string]error{}
+ )
+ useTimeout := c.Flag("timeout").Changed || c.Flag("time").Changed
+ inputTimeout := c.Timeout
+
+ if c.Latest {
+ lastCtr, err := r.GetLatestContainer()
+ if err != nil {
+ return nil, nil, errors.Wrapf(err, "unable to get latest container")
+ }
+ restartContainers = append(restartContainers, lastCtr)
+ } else if c.Running {
+ containers, err = r.LookupContainersWithStatus([]string{libpod.ContainerStateRunning.String()})
+ if err != nil {
+ return nil, nil, err
+ }
+ restartContainers = append(restartContainers, containers...)
+ } else if c.All {
+ containers, err = r.GetAllContainers()
+ if err != nil {
+ return nil, nil, err
+ }
+ restartContainers = append(restartContainers, containers...)
+ } else {
+ for _, id := range c.InputArgs {
+ ctr, err := r.LookupContainer(id)
+ if err != nil {
+ return nil, nil, err
+ }
+ restartContainers = append(restartContainers, ctr)
+ }
+ }
+
+ for _, c := range restartContainers {
+ c := c
+ timeout := c.config.StopTimeout
+ if useTimeout {
+ timeout = inputTimeout
+ }
+ err := c.Restart(int64(timeout))
+ if err != nil {
+ failures[c.ID()] = err
+ } else {
+ ok = append(ok, c.ID())
+ }
+ }
+ return ok, failures, nil
+}
diff --git a/test/e2e/restart_test.go b/test/e2e/restart_test.go
index 1daf63a0e..7a9a466d8 100644
--- a/test/e2e/restart_test.go
+++ b/test/e2e/restart_test.go
@@ -1,5 +1,3 @@
-// +build !remoteclient
-
package integration
import (
diff --git a/test/system/005-info.bats b/test/system/005-info.bats
index c64b011bd..47c7a52fc 100644
--- a/test/system/005-info.bats
+++ b/test/system/005-info.bats
@@ -3,7 +3,7 @@
load helpers
@test "podman info - basic test" {
- skip_if_remote
+ skip_if_remote "capitalization inconsistencies"
run_podman info
@@ -28,7 +28,7 @@ RunRoot:
}
@test "podman info - json" {
- skip_if_remote
+ skip_if_remote "capitalization inconsistencies"
run_podman info --format=json
diff --git a/test/system/030-run.bats b/test/system/030-run.bats
index bdbe724ef..a29b1adc3 100644
--- a/test/system/030-run.bats
+++ b/test/system/030-run.bats
@@ -3,8 +3,6 @@
load helpers
@test "podman run - basic tests" {
- skip_if_remote
-
rand=$(random_string 30)
tests="
true | 0 |
diff --git a/test/system/035-logs.bats b/test/system/035-logs.bats
index 5736e0939..055865c8d 100644
--- a/test/system/035-logs.bats
+++ b/test/system/035-logs.bats
@@ -6,8 +6,6 @@
load helpers
@test "podman logs - basic test" {
- skip_if_remote
-
rand_string=$(random_string 40)
run_podman create $IMAGE echo $rand_string
diff --git a/test/system/070-build.bats b/test/system/070-build.bats
index c6a25093f..53acf6edd 100644
--- a/test/system/070-build.bats
+++ b/test/system/070-build.bats
@@ -6,7 +6,11 @@
load helpers
@test "podman build - basic test" {
- skip_if_remote
+ if [[ "$PODMAN" =~ -remote ]]; then
+ if [ "$(id -u)" -ne 0 ]; then
+ skip "unreliable with podman-remote and rootless; #2972"
+ fi
+ fi
rand_filename=$(random_string 20)
rand_content=$(random_string 50)
diff --git a/test/system/400-unprivileged-access.bats b/test/system/400-unprivileged-access.bats
index 0358b3beb..738d8d87b 100644
--- a/test/system/400-unprivileged-access.bats
+++ b/test/system/400-unprivileged-access.bats
@@ -31,6 +31,12 @@ die() {
echo "#| FAIL: $*" >&2
echo "#\\^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^" >&2
+ # Show permissions of directories from here on up
+ while expr "$path" : "/var/lib/containers" >/dev/null; do
+ echo "#| $(ls -ld $path)"
+ path=$(dirname $path)
+ done
+
exit 1
}
@@ -65,8 +71,10 @@ EOF
# get podman image and container storage directories
run_podman info --format '{{.store.GraphRoot}}'
+ is "$output" "/var/lib/containers/storage" "GraphRoot in expected place"
GRAPH_ROOT="$output"
run_podman info --format '{{.store.RunRoot}}'
+ is "$output" "/var/run/containers/storage" "RunRoot in expected place"
RUN_ROOT="$output"
# The main test: find all world-writable files or directories underneath