diff --git a/frontend/dockerfile/instructions/parse.go b/frontend/dockerfile/instructions/parse.go index ae5bdbb06ad0..9694592267e7 100644 --- a/frontend/dockerfile/instructions/parse.go +++ b/frontend/dockerfile/instructions/parse.go @@ -37,7 +37,7 @@ func nodeArgs(node *parser.Node) []string { if len(arg.Children) == 0 { result = append(result, arg.Value) } else if len(arg.Children) == 1 { - //sub command + // sub command result = append(result, arg.Children[0].Value) result = append(result, nodeArgs(arg.Children[0])...) } @@ -505,6 +505,9 @@ func parseOptInterval(f *Flag) (time.Duration, error) { if err != nil { return 0, err } + if d == 0 { + return 0, nil + } if d < container.MinimumDuration { return 0, fmt.Errorf("Interval %#v cannot be less than %s", f.name, container.MinimumDuration) } @@ -579,8 +582,8 @@ func parseHealthcheck(req parseRequest) (*HealthCheckCommand, error) { if err != nil { return nil, err } - if retries < 1 { - return nil, fmt.Errorf("--retries must be at least 1 (not %d)", retries) + if retries < 0 { + return nil, fmt.Errorf("--retries cannot be negative (%d)", retries) } healthcheck.Retries = int(retries) } else { diff --git a/frontend/dockerfile/instructions/parse_test.go b/frontend/dockerfile/instructions/parse_test.go index bffbd37c2447..887efe5799fe 100644 --- a/frontend/dockerfile/instructions/parse_test.go +++ b/frontend/dockerfile/instructions/parse_test.go @@ -136,6 +136,10 @@ func TestParseOptInterval(t *testing.T) { require.Error(t, err) require.Contains(t, err.Error(), "cannot be less than 1ms") + flInterval.Value = "0ms" + _, err = parseOptInterval(flInterval) + require.NoError(t, err) + flInterval.Value = "1ms" _, err = parseOptInterval(flInterval) require.NoError(t, err) diff --git a/frontend/dockerfile/parser/testfiles/health/Dockerfile b/frontend/dockerfile/parser/testfiles/health/Dockerfile index 081e4428820a..f34fe9462167 100644 --- a/frontend/dockerfile/parser/testfiles/health/Dockerfile +++ b/frontend/dockerfile/parser/testfiles/health/Dockerfile @@ -8,3 +8,4 @@ HEALTHCHECK CMD HEALTHCHECK CMD a b HEALTHCHECK --timeout=3s CMD ["foo"] HEALTHCHECK CONNECT TCP 7000 +HEALTHCHECK --start-period=0s --interval=5s --timeout=0s --retries=0 CMD ["foo"] diff --git a/frontend/dockerfile/parser/testfiles/health/result b/frontend/dockerfile/parser/testfiles/health/result index 092924f88c5c..b4f69164e9af 100644 --- a/frontend/dockerfile/parser/testfiles/health/result +++ b/frontend/dockerfile/parser/testfiles/health/result @@ -7,3 +7,4 @@ (healthcheck "CMD" "a b") (healthcheck ["--timeout=3s"] "CMD" "foo") (healthcheck "CONNECT" "TCP 7000") +(healthcheck ["--start-period=0s" "--interval=5s" "--timeout=0s" "--retries=0"] "CMD" "foo")