Skip to content

Commit fb3868f

Browse files
committed
add support for start_interval
Signed-off-by: Nicolas De Loof <[email protected]>
1 parent 30e80d2 commit fb3868f

File tree

2 files changed

+31
-13
lines changed

2 files changed

+31
-13
lines changed

pkg/compose/convert.go

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,14 @@
1717
package compose
1818

1919
import (
20+
"context"
21+
"errors"
2022
"fmt"
2123
"time"
2224

2325
compose "github.com/compose-spec/compose-go/v2/types"
2426
"github.com/docker/docker/api/types/container"
27+
"github.com/docker/docker/api/types/versions"
2528
)
2629

2730
// ToMobyEnv convert into []string
@@ -38,9 +41,9 @@ func ToMobyEnv(environment compose.MappingWithEquals) []string {
3841
}
3942

4043
// ToMobyHealthCheck convert into container.HealthConfig
41-
func ToMobyHealthCheck(check *compose.HealthCheckConfig) *container.HealthConfig {
44+
func (s *composeService) ToMobyHealthCheck(ctx context.Context, check *compose.HealthCheckConfig) (*container.HealthConfig, error) {
4245
if check == nil {
43-
return nil
46+
return nil, nil
4447
}
4548
var (
4649
interval time.Duration
@@ -64,13 +67,26 @@ func ToMobyHealthCheck(check *compose.HealthCheckConfig) *container.HealthConfig
6467
if check.Disable {
6568
test = []string{"NONE"}
6669
}
67-
return &container.HealthConfig{
68-
Test: test,
69-
Interval: interval,
70-
Timeout: timeout,
71-
StartPeriod: period,
72-
Retries: retries,
70+
var startInterval time.Duration
71+
if check.StartInterval != nil {
72+
version, err := s.RuntimeVersion(ctx)
73+
if err != nil {
74+
return nil, err
75+
}
76+
if versions.LessThan(version, "1.44") {
77+
return nil, errors.New("can't set healthcheck.start_interval as feature require Docker Engine 1.25 or later")
78+
} else {
79+
startInterval = time.Duration(*check.StartInterval)
80+
}
7381
}
82+
return &container.HealthConfig{
83+
Test: test,
84+
Interval: interval,
85+
Timeout: timeout,
86+
StartPeriod: period,
87+
StartInterval: startInterval,
88+
Retries: retries,
89+
}, nil
7490
}
7591

7692
// ToSeconds convert into seconds

pkg/compose/create.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,11 @@ func (s *composeService) getCreateConfigs(ctx context.Context,
178178
proxyConfig := types.MappingWithEquals(s.configFile().ParseProxyConfig(s.apiClient().DaemonHost(), nil))
179179
env := proxyConfig.OverrideBy(service.Environment)
180180

181-
containerConfig := container.Config{
181+
healthcheck, err := s.ToMobyHealthCheck(ctx, service.HealthCheck)
182+
if err != nil {
183+
return createConfigs{}, err
184+
}
185+
var containerConfig = container.Config{
182186
Hostname: service.Hostname,
183187
Domainname: service.DomainName,
184188
User: service.User,
@@ -198,11 +202,9 @@ func (s *composeService) getCreateConfigs(ctx context.Context,
198202
Labels: labels,
199203
StopSignal: service.StopSignal,
200204
Env: ToMobyEnv(env),
201-
Healthcheck: ToMobyHealthCheck(service.HealthCheck),
205+
Healthcheck: healthcheck,
202206
StopTimeout: ToSeconds(service.StopGracePeriod),
203-
}
204-
205-
// VOLUMES/MOUNTS/FILESYSTEMS
207+
} // VOLUMES/MOUNTS/FILESYSTEMS
206208
tmpfs := map[string]string{}
207209
for _, t := range service.Tmpfs {
208210
if arr := strings.SplitN(t, ":", 2); len(arr) > 1 {

0 commit comments

Comments
 (0)