Skip to content

Commit c6a1835

Browse files
authored
Merge pull request moby#3998 from cpuguy83/health-start-interval
Add support for health start interval
2 parents 2c0cf71 + 836e71b commit c6a1835

File tree

94 files changed

+546
-855
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+546
-855
lines changed

exporter/containerimage/image/docker_image.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ type HealthConfig struct {
1919
Test []string `json:",omitempty"`
2020

2121
// Zero means to inherit. Durations are expressed as integer nanoseconds.
22-
Interval time.Duration `json:",omitempty"` // Interval is the time to wait between checks.
23-
Timeout time.Duration `json:",omitempty"` // Timeout is the time to wait before considering the check to have hung.
24-
StartPeriod time.Duration `json:",omitempty"` // The start period for the container to initialize before the retries starts to count down.
22+
Interval time.Duration `json:",omitempty"` // Interval is the time to wait between checks.
23+
Timeout time.Duration `json:",omitempty"` // Timeout is the time to wait before considering the check to have hung.
24+
StartPeriod time.Duration `json:",omitempty"` // The start period for the container to initialize before the retries starts to count down.
25+
StartInterval time.Duration `json:",omitempty"` // StartInterval is the time to wait between checks during the start period.
2526

2627
// Retries is the number of consecutive failures needed to consider a container as unhealthy.
2728
// Zero means inherit.

frontend/dockerfile/dockerfile2llb/convert.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1274,11 +1274,12 @@ func dispatchEntrypoint(d *dispatchState, c *instructions.EntrypointCommand) err
12741274

12751275
func dispatchHealthcheck(d *dispatchState, c *instructions.HealthCheckCommand) error {
12761276
d.image.Config.Healthcheck = &image.HealthConfig{
1277-
Test: c.Health.Test,
1278-
Interval: c.Health.Interval,
1279-
Timeout: c.Health.Timeout,
1280-
StartPeriod: c.Health.StartPeriod,
1281-
Retries: c.Health.Retries,
1277+
Test: c.Health.Test,
1278+
Interval: c.Health.Interval,
1279+
Timeout: c.Health.Timeout,
1280+
StartPeriod: c.Health.StartPeriod,
1281+
StartInterval: c.Health.StartInterval,
1282+
Retries: c.Health.Retries,
12821283
}
12831284
return commitToHistory(&d.image, fmt.Sprintf("HEALTHCHECK %q", d.image.Config.Healthcheck), false, nil, d.epoch)
12841285
}

frontend/dockerfile/docs/reference.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2400,6 +2400,7 @@ The options that can appear before `CMD` are:
24002400
- `--interval=DURATION` (default: `30s`)
24012401
- `--timeout=DURATION` (default: `30s`)
24022402
- `--start-period=DURATION` (default: `0s`)
2403+
- `--start-interval=DURATION` (default: `5s`)
24032404
- `--retries=N` (default: `3`)
24042405

24052406
The health check will first run **interval** seconds after the container is
@@ -2416,6 +2417,8 @@ Probe failure during that period will not be counted towards the maximum number
24162417
However, if a health check succeeds during the start period, the container is considered
24172418
started and all consecutive failures will be counted towards the maximum number of retries.
24182419

2420+
**start interval** is the time between health checks during the start period.
2421+
24192422
There can only be one `HEALTHCHECK` instruction in a Dockerfile. If you list
24202423
more than one then only the last `HEALTHCHECK` will take effect.
24212424

frontend/dockerfile/instructions/parse.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,7 @@ func parseHealthcheck(req parseRequest) (*HealthCheckCommand, error) {
544544
flInterval := req.flags.AddString("interval", "")
545545
flTimeout := req.flags.AddString("timeout", "")
546546
flStartPeriod := req.flags.AddString("start-period", "")
547+
flStartInterval := req.flags.AddString("start-interval", "")
547548
flRetries := req.flags.AddString("retries", "")
548549

549550
if err := req.flags.Parse(); err != nil {
@@ -584,6 +585,12 @@ func parseHealthcheck(req parseRequest) (*HealthCheckCommand, error) {
584585
}
585586
healthcheck.StartPeriod = startPeriod
586587

588+
startInterval, err := parseOptInterval(flStartInterval)
589+
if err != nil {
590+
return nil, err
591+
}
592+
healthcheck.StartInterval = startInterval
593+
587594
if flRetries.Value != "" {
588595
retries, err := strconv.ParseInt(flRetries.Value, 10, 32)
589596
if err != nil {

frontend/dockerfile/parser/testfiles/health/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +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"]
11+
HEALTHCHECK --start-period=0s --start-interval=0s --interval=5s --timeout=0s --retries=0 CMD ["foo"]

frontend/dockerfile/parser/testfiles/health/result

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +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")
10+
(healthcheck ["--start-period=0s" "--start-interval=0s" "--interval=5s" "--timeout=0s" "--retries=0"] "CMD" "foo")

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ require (
2828
github.com/coreos/go-systemd/v22 v22.5.0
2929
github.com/docker/cli v24.0.2+incompatible
3030
github.com/docker/distribution v2.8.2+incompatible
31-
github.com/docker/docker v24.0.2+incompatible
31+
github.com/docker/docker v24.0.0-rc.2.0.20230706181717-98d3da79ef9c+incompatible
3232
github.com/docker/go-connections v0.4.0
3333
github.com/docker/go-units v0.5.0
3434
github.com/gofrs/flock v0.8.1

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -445,8 +445,8 @@ github.com/docker/docker v1.4.2-0.20180531152204-71cd53e4a197/go.mod h1:eEKB0N0r
445445
github.com/docker/docker v1.4.2-0.20190924003213-a8608b5b67c7/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
446446
github.com/docker/docker v17.12.0-ce-rc1.0.20200730172259-9f28837c1d93+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
447447
github.com/docker/docker v20.10.0-beta1.0.20201110211921-af34b94a78a1+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
448-
github.com/docker/docker v24.0.2+incompatible h1:eATx+oLz9WdNVkQrr0qjQ8HvRJ4bOOxfzEo8R+dA3cg=
449-
github.com/docker/docker v24.0.2+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
448+
github.com/docker/docker v24.0.0-rc.2.0.20230706181717-98d3da79ef9c+incompatible h1:XccikgvtGCEZE9ZQoaEApdx9ZvruGYakfi2tw4d/vUg=
449+
github.com/docker/docker v24.0.0-rc.2.0.20230706181717-98d3da79ef9c+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
450450
github.com/docker/docker-credential-helpers v0.6.3/go.mod h1:WRaJzqw3CTB9bk10avuGsjVBZsD05qeibJ1/TYlvc0Y=
451451
github.com/docker/docker-credential-helpers v0.7.0 h1:xtCHsjxogADNZcdv1pKUHXryefjlVRqWqIhk/uXJp0A=
452452
github.com/docker/docker-credential-helpers v0.7.0/go.mod h1:rETQfLdHNT3foU5kuNkFR1R1V12OJRRO5lzt2D1b5X0=

vendor/github.com/docker/docker/AUTHORS

Lines changed: 16 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/docker/docker/api/common.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)