mirror of https://github.com/docker/compose.git
add support for start_interval
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
parent
30e80d2440
commit
fb3868ffaf
|
@ -17,11 +17,14 @@
|
|||
package compose
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
compose "github.com/compose-spec/compose-go/v2/types"
|
||||
"github.com/docker/docker/api/types/container"
|
||||
"github.com/docker/docker/api/types/versions"
|
||||
)
|
||||
|
||||
// ToMobyEnv convert into []string
|
||||
|
@ -38,9 +41,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 +67,26 @@ func ToMobyHealthCheck(check *compose.HealthCheckConfig) *container.HealthConfig
|
|||
if check.Disable {
|
||||
test = []string{"NONE"}
|
||||
}
|
||||
var startInterval time.Duration
|
||||
if check.StartInterval != nil {
|
||||
version, err := s.RuntimeVersion(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if versions.LessThan(version, "1.44") {
|
||||
return nil, errors.New("can't set healthcheck.start_interval as feature require Docker Engine 1.25 or later")
|
||||
} else {
|
||||
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
|
||||
|
|
|
@ -178,7 +178,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,
|
||||
|
@ -198,11 +202,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 {
|
||||
|
|
Loading…
Reference in New Issue