From e5a45751d4c2ca1168068ff455b954d08e2e629a Mon Sep 17 00:00:00 2001 From: Nicolas De Loof Date: Mon, 28 Aug 2023 09:01:34 +0200 Subject: [PATCH] add support for start_interval Signed-off-by: Nicolas De Loof --- pkg/compose/convert.go | 30 ++++++++++++++++++++++-------- pkg/compose/create.go | 12 +++++++----- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/pkg/compose/convert.go b/pkg/compose/convert.go index 6f092ee2d51..0ef88bc2ffb 100644 --- a/pkg/compose/convert.go +++ b/pkg/compose/convert.go @@ -17,11 +17,13 @@ package compose import ( + "context" "fmt" "time" compose "github.com/compose-spec/compose-go/types" "github.com/docker/docker/api/types/container" + "github.com/docker/docker/api/types/versions" ) // ToMobyEnv convert into []string @@ -38,9 +40,9 @@ func ToMobyEnv(environment compose.MappingWithEquals) []string { } // ToMobyHealthCheck convert into container.HealthConfig -func ToMobyHealthCheck(check *compose.HealthCheckConfig) *container.HealthConfig { +func (s *composeService) ToMobyHealthCheck(ctx context.Context, check *compose.HealthCheckConfig) (*container.HealthConfig, error) { if check == nil { - return nil + return nil, nil } var ( interval time.Duration @@ -64,13 +66,25 @@ func ToMobyHealthCheck(check *compose.HealthCheckConfig) *container.HealthConfig if check.Disable { test = []string{"NONE"} } - return &container.HealthConfig{ - Test: test, - Interval: interval, - Timeout: timeout, - StartPeriod: period, - Retries: retries, + var startInterval time.Duration + if check.StartInterval != nil { + version, err := s.RuntimeVersion(ctx) + if err != nil { + return nil, err + } + if versions.LessThan(version, "1.25") { + return nil, fmt.Errorf("Can't set healthcheck.start_interval as feature require Moby 1.25 or later - ignored") + } + startInterval = time.Duration(*check.StartInterval) } + return &container.HealthConfig{ + Test: test, + Interval: interval, + Timeout: timeout, + StartPeriod: period, + StartInterval: startInterval, + Retries: retries, + }, nil } // ToSeconds convert into seconds diff --git a/pkg/compose/create.go b/pkg/compose/create.go index 2d88d66b111..947d5ea6f73 100644 --- a/pkg/compose/create.go +++ b/pkg/compose/create.go @@ -182,7 +182,11 @@ func (s *composeService) getCreateConfigs(ctx context.Context, proxyConfig := types.MappingWithEquals(s.configFile().ParseProxyConfig(s.apiClient().DaemonHost(), nil)) env := proxyConfig.OverrideBy(service.Environment) - containerConfig := container.Config{ + healthcheck, err := s.ToMobyHealthCheck(ctx, service.HealthCheck) + if err != nil { + return createConfigs{}, err + } + var containerConfig = container.Config{ Hostname: service.Hostname, Domainname: service.DomainName, User: service.User, @@ -202,11 +206,9 @@ func (s *composeService) getCreateConfigs(ctx context.Context, Labels: labels, StopSignal: service.StopSignal, Env: ToMobyEnv(env), - Healthcheck: ToMobyHealthCheck(service.HealthCheck), + Healthcheck: healthcheck, StopTimeout: ToSeconds(service.StopGracePeriod), - } - - // VOLUMES/MOUNTS/FILESYSTEMS + } // VOLUMES/MOUNTS/FILESYSTEMS tmpfs := map[string]string{} for _, t := range service.Tmpfs { if arr := strings.SplitN(t, ":", 2); len(arr) > 1 {