Skip to content

Commit 764e902

Browse files
committed
frontend: allow 0 (default) value for healthcheck intervals
While these intervals have a minimum value when set: // MinimumDuration puts a minimum on user configured duration. // This is to prevent API error on time unit. For example, API may // set 3 as healthcheck interval with intention of 3 seconds, but // Docker interprets it as 3 nanoseconds. const MinimumDuration = 1 * time.Millisecond It should be possible to set them to `0` (which is teh default). This patch updates the Dockerfile parser to use the same logic as the docker daemon uses; if healthConfig.StartPeriod != 0 && healthConfig.StartPeriod < containertypes.MinimumDuration { return errors.Errorf("StartPeriod in Healthcheck cannot be less than %s", containertypes.MinimumDuration) } Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent c9a0f4d commit 764e902

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

frontend/dockerfile/instructions/parse.go

Lines changed: 4 additions & 1 deletion
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
}

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)

0 commit comments

Comments
 (0)