Skip to content

Commit

Permalink
add support for start_interval
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
  • Loading branch information
ndeloof committed Nov 20, 2023
1 parent a1b7bee commit e5a4575
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 13 deletions.
30 changes: 22 additions & 8 deletions pkg/compose/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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,

Check failure on line 85 in pkg/compose/convert.go

View workflow job for this annotation

GitHub Actions / Analyze (go)

unknown field StartInterval in struct literal of type "github.com/docker/docker/api/types/container".HealthConfig
Retries: retries,
}, nil
}

// ToSeconds convert into seconds
Expand Down
12 changes: 7 additions & 5 deletions pkg/compose/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 {
Expand Down

0 comments on commit e5a4575

Please sign in to comment.