Skip to content

Commit

Permalink
healthcheck: set appropriate defaults for interval, timeout and retries
Browse files Browse the repository at this point in the history
Set appropriate defaults from interval, timeout and retries when
processing a Containerfile with build format as docker.

See: https://docs.docker.com/engine/reference/builder/#healthcheck
Closes: containers/podman#13912

Signed-off-by: Aditya R <[email protected]>
  • Loading branch information
flouthoc committed Apr 19, 2022
1 parent d949291 commit fc0815e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
15 changes: 15 additions & 0 deletions builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,21 @@ func TestBuilder(t *testing.T) {
},
},
},
{
Dockerfile: "dockerclient/testdata/Dockerfile.healthcheckdefaults",
From: "debian",
Config: docker.Config{
Image: "debian",
Cmd: []string{"/bin/sh", "-c", "/app/main.sh"},
Healthcheck: &docker.HealthConfig{
StartPeriod: 0 * time.Second,
Interval: 30 * time.Second,
Timeout: 30 * time.Second,
Retries: 3,
Test: []string{"CMD-SHELL", "/app/check.sh --quiet"},
},
},
},
{
Dockerfile: "dockerclient/testdata/Dockerfile.envsubst",
From: "busybox",
Expand Down
8 changes: 4 additions & 4 deletions dispatchers.go
Original file line number Diff line number Diff line change
Expand Up @@ -516,12 +516,12 @@ func healthcheck(b *Builder, args []string, attributes map[string]bool, flagArgs
}

healthcheck := docker.HealthConfig{}

// Use docker defaults for flags https://docs.docker.com/engine/reference/builder/#healthcheck
flags := flag.NewFlagSet("", flag.ContinueOnError)
flags.String("start-period", "", "")
flags.String("interval", "", "")
flags.String("timeout", "", "")
flRetries := flags.String("retries", "", "")
flags.String("interval", "30s", "")
flags.String("timeout", "30s", "")
flRetries := flags.String("retries", "3", "")

if err := flags.Parse(flagArgs); err != nil {
return err
Expand Down
6 changes: 6 additions & 0 deletions dockerclient/testdata/Dockerfile.healthcheckdefaults
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM debian
CMD /app/main.sh
HEALTHCHECK CMD a b
HEALTHCHECK CMD ["foo"]
HEALTHCHECK CMD /app/check.sh --quiet

0 comments on commit fc0815e

Please sign in to comment.