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
pkg/compose
|
@ -17,11 +17,14 @@
|
||||||
package compose
|
package compose
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
compose "github.com/compose-spec/compose-go/v2/types"
|
compose "github.com/compose-spec/compose-go/v2/types"
|
||||||
"github.com/docker/docker/api/types/container"
|
"github.com/docker/docker/api/types/container"
|
||||||
|
"github.com/docker/docker/api/types/versions"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ToMobyEnv convert into []string
|
// ToMobyEnv convert into []string
|
||||||
|
@ -38,9 +41,9 @@ func ToMobyEnv(environment compose.MappingWithEquals) []string {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ToMobyHealthCheck convert into container.HealthConfig
|
// 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 {
|
if check == nil {
|
||||||
return nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
var (
|
var (
|
||||||
interval time.Duration
|
interval time.Duration
|
||||||
|
@ -64,13 +67,26 @@ func ToMobyHealthCheck(check *compose.HealthCheckConfig) *container.HealthConfig
|
||||||
if check.Disable {
|
if check.Disable {
|
||||||
test = []string{"NONE"}
|
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{
|
return &container.HealthConfig{
|
||||||
Test: test,
|
Test: test,
|
||||||
Interval: interval,
|
Interval: interval,
|
||||||
Timeout: timeout,
|
Timeout: timeout,
|
||||||
StartPeriod: period,
|
StartPeriod: period,
|
||||||
|
StartInterval: startInterval,
|
||||||
Retries: retries,
|
Retries: retries,
|
||||||
}
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ToSeconds convert into seconds
|
// 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))
|
proxyConfig := types.MappingWithEquals(s.configFile().ParseProxyConfig(s.apiClient().DaemonHost(), nil))
|
||||||
env := proxyConfig.OverrideBy(service.Environment)
|
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,
|
Hostname: service.Hostname,
|
||||||
Domainname: service.DomainName,
|
Domainname: service.DomainName,
|
||||||
User: service.User,
|
User: service.User,
|
||||||
|
@ -198,11 +202,9 @@ func (s *composeService) getCreateConfigs(ctx context.Context,
|
||||||
Labels: labels,
|
Labels: labels,
|
||||||
StopSignal: service.StopSignal,
|
StopSignal: service.StopSignal,
|
||||||
Env: ToMobyEnv(env),
|
Env: ToMobyEnv(env),
|
||||||
Healthcheck: ToMobyHealthCheck(service.HealthCheck),
|
Healthcheck: healthcheck,
|
||||||
StopTimeout: ToSeconds(service.StopGracePeriod),
|
StopTimeout: ToSeconds(service.StopGracePeriod),
|
||||||
}
|
} // VOLUMES/MOUNTS/FILESYSTEMS
|
||||||
|
|
||||||
// VOLUMES/MOUNTS/FILESYSTEMS
|
|
||||||
tmpfs := map[string]string{}
|
tmpfs := map[string]string{}
|
||||||
for _, t := range service.Tmpfs {
|
for _, t := range service.Tmpfs {
|
||||||
if arr := strings.SplitN(t, ":", 2); len(arr) > 1 {
|
if arr := strings.SplitN(t, ":", 2); len(arr) > 1 {
|
||||||
|
|
Loading…
Reference in New Issue