Skip to content

Commit abde08a

Browse files
authored
Merge pull request moby#3092 from thaJeztah/fix_healthcheck_interval
frontend: fix Healthcheck intervals and retries not accepting default values
2 parents 7b34166 + 20c7fda commit abde08a

File tree

4 files changed

+12
-3
lines changed

4 files changed

+12
-3
lines changed

frontend/dockerfile/instructions/parse.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func nodeArgs(node *parser.Node) []string {
3737
if len(arg.Children) == 0 {
3838
result = append(result, arg.Value)
3939
} else if len(arg.Children) == 1 {
40-
//sub command
40+
// sub command
4141
result = append(result, arg.Children[0].Value)
4242
result = append(result, nodeArgs(arg.Children[0])...)
4343
}
@@ -505,6 +505,9 @@ func parseOptInterval(f *Flag) (time.Duration, error) {
505505
if err != nil {
506506
return 0, err
507507
}
508+
if d == 0 {
509+
return 0, nil
510+
}
508511
if d < container.MinimumDuration {
509512
return 0, fmt.Errorf("Interval %#v cannot be less than %s", f.name, container.MinimumDuration)
510513
}
@@ -579,8 +582,8 @@ func parseHealthcheck(req parseRequest) (*HealthCheckCommand, error) {
579582
if err != nil {
580583
return nil, err
581584
}
582-
if retries < 1 {
583-
return nil, fmt.Errorf("--retries must be at least 1 (not %d)", retries)
585+
if retries < 0 {
586+
return nil, fmt.Errorf("--retries cannot be negative (%d)", retries)
584587
}
585588
healthcheck.Retries = int(retries)
586589
} else {

frontend/dockerfile/instructions/parse_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@ func TestParseOptInterval(t *testing.T) {
136136
require.Error(t, err)
137137
require.Contains(t, err.Error(), "cannot be less than 1ms")
138138

139+
flInterval.Value = "0ms"
140+
_, err = parseOptInterval(flInterval)
141+
require.NoError(t, err)
142+
139143
flInterval.Value = "1ms"
140144
_, err = parseOptInterval(flInterval)
141145
require.NoError(t, err)

frontend/dockerfile/parser/testfiles/health/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ HEALTHCHECK CMD
88
HEALTHCHECK CMD a b
99
HEALTHCHECK --timeout=3s CMD ["foo"]
1010
HEALTHCHECK CONNECT TCP 7000
11+
HEALTHCHECK --start-period=0s --interval=5s --timeout=0s --retries=0 CMD ["foo"]

frontend/dockerfile/parser/testfiles/health/result

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@
77
(healthcheck "CMD" "a b")
88
(healthcheck ["--timeout=3s"] "CMD" "foo")
99
(healthcheck "CONNECT" "TCP 7000")
10+
(healthcheck ["--start-period=0s" "--interval=5s" "--timeout=0s" "--retries=0"] "CMD" "foo")

0 commit comments

Comments
 (0)