From fc0815e800cbfd05aa383ff7991a7d6baaa3b619 Mon Sep 17 00:00:00 2001 From: Aditya R Date: Tue, 19 Apr 2022 13:51:27 +0530 Subject: [PATCH] healthcheck: set appropriate defaults for interval, timeout and retries 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: https://github.com/containers/podman/issues/13912 Signed-off-by: Aditya R --- builder_test.go | 15 +++++++++++++++ dispatchers.go | 8 ++++---- .../testdata/Dockerfile.healthcheckdefaults | 6 ++++++ 3 files changed, 25 insertions(+), 4 deletions(-) create mode 100644 dockerclient/testdata/Dockerfile.healthcheckdefaults diff --git a/builder_test.go b/builder_test.go index fa68eb00..356a56cc 100644 --- a/builder_test.go +++ b/builder_test.go @@ -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", diff --git a/dispatchers.go b/dispatchers.go index fd05f031..1165f020 100644 --- a/dispatchers.go +++ b/dispatchers.go @@ -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 diff --git a/dockerclient/testdata/Dockerfile.healthcheckdefaults b/dockerclient/testdata/Dockerfile.healthcheckdefaults new file mode 100644 index 00000000..50d8c164 --- /dev/null +++ b/dockerclient/testdata/Dockerfile.healthcheckdefaults @@ -0,0 +1,6 @@ +FROM debian +CMD /app/main.sh +HEALTHCHECK CMD a b +HEALTHCHECK CMD ["foo"] +HEALTHCHECK CMD /app/check.sh --quiet +