Skip to content

Commit

Permalink
create: improve parser for --healthcheck-command
Browse files Browse the repository at this point in the history
Fix Docker CLI compatibility issue: the "--healthcheck-command" option
value should not be split but instead be passed as single string to
"/bin/sh -c <opt>".

On the other hand implement the same extension as is already available
for "--entrypoint", i.e. allow the option value to be a JSON array of
strings. This will make life easier for tools like podman-compose.

Continuation of containers#3455 & containers#3507
  • Loading branch information
stefanb2 committed Jul 13, 2019
1 parent c59d08b commit dbcfa0f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
8 changes: 5 additions & 3 deletions cmd/podman/shared/create.go
Expand Up @@ -26,7 +26,6 @@ import (
"github.com/docker/docker/pkg/signal"
"github.com/docker/go-connections/nat"
"github.com/docker/go-units"
"github.com/google/shlex"
"github.com/opencontainers/selinux/go-selinux/label"
"github.com/opentracing/opentracing-go"
"github.com/pkg/errors"
Expand Down Expand Up @@ -788,9 +787,12 @@ func makeHealthCheckFromCli(c *GenericCLIResults) (*manifest.Schema2HealthConfig
return nil, errors.New("Must define a healthcheck command for all healthchecks")
}

cmd, err := shlex.Split(inCommand)
// first try to parse option value as JSON array of strings...
cmd := []string{}
err := json.Unmarshal([]byte(inCommand), &cmd)
if err != nil {
return nil, errors.Wrap(err, "failed to parse healthcheck command")
// ...otherwise pass it to "/bin/sh -c"
cmd = []string{"/bin/sh", "-c", inCommand}
}
hc := manifest.Schema2HealthConfig{
Test: cmd,
Expand Down
4 changes: 3 additions & 1 deletion docs/podman-create.1.md
Expand Up @@ -272,12 +272,14 @@ The following example maps uids 0-2000 in the container to the uids 30000-31999

Add additional groups to run as

**--healthcheck-command**=*command*
**--healthcheck-command**=*"command"* | *'["command", "arg1", ...]'*

Set or alter a healthcheck command for a container. The command is a command to be executed inside your
container that determines your container health. The command is required for other healthcheck options
to be applied. A value of `none` disables existing healthchecks.

You need to specify multi option commands in the form of a json string.

**--healthcheck-interval**=*interval*

Set an interval for the healthchecks (a value of `disable` results in no automatic timer setup) (default "30s")
Expand Down
4 changes: 3 additions & 1 deletion docs/podman-run.1.md
Expand Up @@ -279,12 +279,14 @@ The example maps gids 0-2000 in the container to the gids 30000-31999 on the hos

Add additional groups to run as

**--healthcheck-command**=*command*
**--healthcheck-command**=*"command"* | *'["command", "arg1", ...]'*

Set or alter a healthcheck command for a container. The command is a command to be executed inside your
container that determines your container health. The command is required for other healthcheck options
to be applied. A value of `none` disables existing healthchecks.

You need to specify multi option commands in the form of a json string.

**--healthcheck-interval**=*interval*

Set an interval for the healthchecks (a value of `disable` results in no automatic timer setup) (default "30s")
Expand Down

0 comments on commit dbcfa0f

Please sign in to comment.