Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stacks: Add schema 3.12, and add support for start interval #4611

Merged
merged 2 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions cli/compose/convert/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -436,8 +436,8 @@ func convertHealthcheck(healthcheck *composetypes.HealthCheckConfig) (*container
return nil, nil
}
var (
timeout, interval, startPeriod time.Duration
retries int
timeout, interval, startPeriod, startInterval time.Duration
retries int
)
if healthcheck.Disable {
if len(healthcheck.Test) != 0 {
Expand All @@ -457,15 +457,19 @@ func convertHealthcheck(healthcheck *composetypes.HealthCheckConfig) (*container
if healthcheck.StartPeriod != nil {
startPeriod = time.Duration(*healthcheck.StartPeriod)
}
if healthcheck.StartInterval != nil {
startInterval = time.Duration(*healthcheck.StartInterval)
}
if healthcheck.Retries != nil {
retries = int(*healthcheck.Retries)
}
return &container.HealthConfig{
Test: healthcheck.Test,
Timeout: timeout,
Interval: interval,
Retries: retries,
StartPeriod: startPeriod,
Test: healthcheck.Test,
Timeout: timeout,
Interval: interval,
Retries: retries,
StartPeriod: startPeriod,
StartInterval: startInterval,
}, nil
}

Expand Down
23 changes: 15 additions & 8 deletions cli/compose/convert/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,17 +124,24 @@ func TestConvertHealthcheck(t *testing.T) {
retries := uint64(10)
timeout := composetypes.Duration(30 * time.Second)
interval := composetypes.Duration(2 * time.Millisecond)
startPeriod := composetypes.Duration(time.Minute)
startInterval := composetypes.Duration(1 * time.Second)

source := &composetypes.HealthCheckConfig{
Test: []string{"EXEC", "touch", "/foo"},
Timeout: &timeout,
Interval: &interval,
Retries: &retries,
Test: []string{"EXEC", "touch", "/foo"},
Timeout: &timeout,
Interval: &interval,
Retries: &retries,
StartPeriod: &startPeriod,
StartInterval: &startInterval,
}
expected := &container.HealthConfig{
Test: source.Test,
Timeout: time.Duration(timeout),
Interval: time.Duration(interval),
Retries: 10,
Test: source.Test,
Timeout: time.Duration(timeout),
Interval: time.Duration(interval),
StartPeriod: time.Duration(startPeriod),
StartInterval: time.Duration(startInterval),
Retries: 10,
}

healthcheck, err := convertHealthcheck(source)
Expand Down
3 changes: 2 additions & 1 deletion cli/compose/loader/full-example.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: "3.10"
version: "3.12"

services:
foo:
Expand Down Expand Up @@ -158,6 +158,7 @@ services:
timeout: 1s
retries: 5
start_period: 15s
start_interval: 1s

# Any valid image reference - repo, tag, id, sha
image: redis
Expand Down
13 changes: 7 additions & 6 deletions cli/compose/loader/full-struct_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

func fullExampleConfig(workingDir, homeDir string) *types.Config {
return &types.Config{
Version: "3.10",
Version: "3.12",
Services: services(workingDir, homeDir),
Networks: networks(),
Volumes: volumes(),
Expand Down Expand Up @@ -154,11 +154,12 @@ func services(workingDir, homeDir string) []types.ServiceConfig {
"x-foo": "bar",
},
HealthCheck: &types.HealthCheckConfig{
Test: types.HealthCheckTest([]string{"CMD-SHELL", "echo \"hello world\""}),
Interval: durationPtr(10 * time.Second),
Timeout: durationPtr(1 * time.Second),
Retries: uint64Ptr(5),
StartPeriod: durationPtr(15 * time.Second),
Test: types.HealthCheckTest([]string{"CMD-SHELL", "echo \"hello world\""}),
Interval: durationPtr(10 * time.Second),
Timeout: durationPtr(1 * time.Second),
Retries: uint64Ptr(5),
StartPeriod: durationPtr(15 * time.Second),
StartInterval: durationPtr(1 * time.Second),
},
Hostname: "foo",
Image: "redis",
Expand Down
2 changes: 1 addition & 1 deletion cli/compose/loader/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func strPtr(val string) *string {
}

var sampleConfig = types.Config{
Version: "3.11",
Version: "3.12",
Services: []types.ServiceConfig{
{
Name: "foo",
Expand Down
5 changes: 3 additions & 2 deletions cli/compose/loader/testdata/full-example.json.golden
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,8 @@
"timeout": "1s",
"interval": "10s",
"retries": 5,
"start_period": "15s"
"start_period": "15s",
"start_interval": "1s"
},
"image": "redis",
"ipc": "host",
Expand Down Expand Up @@ -508,7 +509,7 @@
"working_dir": "/code"
}
},
"version": "3.10",
"version": "3.12",
"volumes": {
"another-volume": {
"name": "user_specified_name",
Expand Down
3 changes: 2 additions & 1 deletion cli/compose/loader/testdata/full-example.yaml.golden
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: "3.10"
version: "3.12"
services:
foo:
build:
Expand Down Expand Up @@ -126,6 +126,7 @@ services:
interval: 10s
retries: 5
start_period: 15s
start_interval: 1s
image: redis
ipc: host
labels:
Expand Down
Loading
Loading