Skip to content

Commit 60b5508

Browse files
authored
Merge pull request #4611 from thaJeztah/stack_start_interval_carry
stacks: Add schema 3.12, and add support for start interval
2 parents 3e5f6ba + defa52b commit 60b5508

11 files changed

Lines changed: 724 additions & 34 deletions

File tree

cli/compose/convert/service.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -436,8 +436,8 @@ func convertHealthcheck(healthcheck *composetypes.HealthCheckConfig) (*container
436436
return nil, nil
437437
}
438438
var (
439-
timeout, interval, startPeriod time.Duration
440-
retries int
439+
timeout, interval, startPeriod, startInterval time.Duration
440+
retries int
441441
)
442442
if healthcheck.Disable {
443443
if len(healthcheck.Test) != 0 {
@@ -457,15 +457,19 @@ func convertHealthcheck(healthcheck *composetypes.HealthCheckConfig) (*container
457457
if healthcheck.StartPeriod != nil {
458458
startPeriod = time.Duration(*healthcheck.StartPeriod)
459459
}
460+
if healthcheck.StartInterval != nil {
461+
startInterval = time.Duration(*healthcheck.StartInterval)
462+
}
460463
if healthcheck.Retries != nil {
461464
retries = int(*healthcheck.Retries)
462465
}
463466
return &container.HealthConfig{
464-
Test: healthcheck.Test,
465-
Timeout: timeout,
466-
Interval: interval,
467-
Retries: retries,
468-
StartPeriod: startPeriod,
467+
Test: healthcheck.Test,
468+
Timeout: timeout,
469+
Interval: interval,
470+
Retries: retries,
471+
StartPeriod: startPeriod,
472+
StartInterval: startInterval,
469473
}, nil
470474
}
471475

cli/compose/convert/service_test.go

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -124,17 +124,24 @@ func TestConvertHealthcheck(t *testing.T) {
124124
retries := uint64(10)
125125
timeout := composetypes.Duration(30 * time.Second)
126126
interval := composetypes.Duration(2 * time.Millisecond)
127+
startPeriod := composetypes.Duration(time.Minute)
128+
startInterval := composetypes.Duration(1 * time.Second)
129+
127130
source := &composetypes.HealthCheckConfig{
128-
Test: []string{"EXEC", "touch", "/foo"},
129-
Timeout: &timeout,
130-
Interval: &interval,
131-
Retries: &retries,
131+
Test: []string{"EXEC", "touch", "/foo"},
132+
Timeout: &timeout,
133+
Interval: &interval,
134+
Retries: &retries,
135+
StartPeriod: &startPeriod,
136+
StartInterval: &startInterval,
132137
}
133138
expected := &container.HealthConfig{
134-
Test: source.Test,
135-
Timeout: time.Duration(timeout),
136-
Interval: time.Duration(interval),
137-
Retries: 10,
139+
Test: source.Test,
140+
Timeout: time.Duration(timeout),
141+
Interval: time.Duration(interval),
142+
StartPeriod: time.Duration(startPeriod),
143+
StartInterval: time.Duration(startInterval),
144+
Retries: 10,
138145
}
139146

140147
healthcheck, err := convertHealthcheck(source)

cli/compose/loader/full-example.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: "3.10"
1+
version: "3.12"
22

33
services:
44
foo:
@@ -158,6 +158,7 @@ services:
158158
timeout: 1s
159159
retries: 5
160160
start_period: 15s
161+
start_interval: 1s
161162

162163
# Any valid image reference - repo, tag, id, sha
163164
image: redis

cli/compose/loader/full-struct_test.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88

99
func fullExampleConfig(workingDir, homeDir string) *types.Config {
1010
return &types.Config{
11-
Version: "3.10",
11+
Version: "3.12",
1212
Services: services(workingDir, homeDir),
1313
Networks: networks(),
1414
Volumes: volumes(),
@@ -154,11 +154,12 @@ func services(workingDir, homeDir string) []types.ServiceConfig {
154154
"x-foo": "bar",
155155
},
156156
HealthCheck: &types.HealthCheckConfig{
157-
Test: types.HealthCheckTest([]string{"CMD-SHELL", "echo \"hello world\""}),
158-
Interval: durationPtr(10 * time.Second),
159-
Timeout: durationPtr(1 * time.Second),
160-
Retries: uint64Ptr(5),
161-
StartPeriod: durationPtr(15 * time.Second),
157+
Test: types.HealthCheckTest([]string{"CMD-SHELL", "echo \"hello world\""}),
158+
Interval: durationPtr(10 * time.Second),
159+
Timeout: durationPtr(1 * time.Second),
160+
Retries: uint64Ptr(5),
161+
StartPeriod: durationPtr(15 * time.Second),
162+
StartInterval: durationPtr(1 * time.Second),
162163
},
163164
Hostname: "foo",
164165
Image: "redis",

cli/compose/loader/loader_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ func strPtr(val string) *string {
181181
}
182182

183183
var sampleConfig = types.Config{
184-
Version: "3.11",
184+
Version: "3.12",
185185
Services: []types.ServiceConfig{
186186
{
187187
Name: "foo",

cli/compose/loader/testdata/full-example.json.golden

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,8 @@
252252
"timeout": "1s",
253253
"interval": "10s",
254254
"retries": 5,
255-
"start_period": "15s"
255+
"start_period": "15s",
256+
"start_interval": "1s"
256257
},
257258
"image": "redis",
258259
"ipc": "host",
@@ -508,7 +509,7 @@
508509
"working_dir": "/code"
509510
}
510511
},
511-
"version": "3.10",
512+
"version": "3.12",
512513
"volumes": {
513514
"another-volume": {
514515
"name": "user_specified_name",

cli/compose/loader/testdata/full-example.yaml.golden

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: "3.10"
1+
version: "3.12"
22
services:
33
foo:
44
build:
@@ -126,6 +126,7 @@ services:
126126
interval: 10s
127127
retries: 5
128128
start_period: 15s
129+
start_interval: 1s
129130
image: redis
130131
ipc: host
131132
labels:

0 commit comments

Comments
 (0)