mirror of https://github.com/docker/cli.git
Merge pull request #28294 from vdemeester/compose-swarm-healthcheck
Add support for healthcheck in compose to swarm
This commit is contained in:
commit
4e343ae989
|
@ -6,6 +6,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
|
@ -13,6 +14,7 @@ import (
|
||||||
"github.com/aanand/compose-file/loader"
|
"github.com/aanand/compose-file/loader"
|
||||||
composetypes "github.com/aanand/compose-file/types"
|
composetypes "github.com/aanand/compose-file/types"
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
|
"github.com/docker/docker/api/types/container"
|
||||||
"github.com/docker/docker/api/types/mount"
|
"github.com/docker/docker/api/types/mount"
|
||||||
networktypes "github.com/docker/docker/api/types/network"
|
networktypes "github.com/docker/docker/api/types/network"
|
||||||
"github.com/docker/docker/api/types/swarm"
|
"github.com/docker/docker/api/types/swarm"
|
||||||
|
@ -492,6 +494,11 @@ func convertService(
|
||||||
return swarm.ServiceSpec{}, err
|
return swarm.ServiceSpec{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
healthcheck, err := convertHealthcheck(service.HealthCheck)
|
||||||
|
if err != nil {
|
||||||
|
return swarm.ServiceSpec{}, err
|
||||||
|
}
|
||||||
|
|
||||||
serviceSpec := swarm.ServiceSpec{
|
serviceSpec := swarm.ServiceSpec{
|
||||||
Annotations: swarm.Annotations{
|
Annotations: swarm.Annotations{
|
||||||
Name: name,
|
Name: name,
|
||||||
|
@ -504,6 +511,7 @@ func convertService(
|
||||||
Args: service.Command,
|
Args: service.Command,
|
||||||
Hostname: service.Hostname,
|
Hostname: service.Hostname,
|
||||||
Hosts: convertExtraHosts(service.ExtraHosts),
|
Hosts: convertExtraHosts(service.ExtraHosts),
|
||||||
|
Healthcheck: healthcheck,
|
||||||
Env: convertEnvironment(service.Environment),
|
Env: convertEnvironment(service.Environment),
|
||||||
Labels: getStackLabels(namespace.name, service.Labels),
|
Labels: getStackLabels(namespace.name, service.Labels),
|
||||||
Dir: service.WorkingDir,
|
Dir: service.WorkingDir,
|
||||||
|
@ -536,6 +544,47 @@ func convertExtraHosts(extraHosts map[string]string) []string {
|
||||||
return hosts
|
return hosts
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func convertHealthcheck(healthcheck *composetypes.HealthCheckConfig) (*container.HealthConfig, error) {
|
||||||
|
if healthcheck == nil {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
var (
|
||||||
|
err error
|
||||||
|
timeout, interval time.Duration
|
||||||
|
retries int
|
||||||
|
)
|
||||||
|
if healthcheck.Disable {
|
||||||
|
if len(healthcheck.Test) != 0 {
|
||||||
|
return nil, fmt.Errorf("command and disable key can't be set at the same time")
|
||||||
|
}
|
||||||
|
return &container.HealthConfig{
|
||||||
|
Test: []string{"NONE"},
|
||||||
|
}, nil
|
||||||
|
|
||||||
|
}
|
||||||
|
if healthcheck.Timeout != "" {
|
||||||
|
timeout, err = time.ParseDuration(healthcheck.Timeout)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if healthcheck.Interval != "" {
|
||||||
|
interval, err = time.ParseDuration(healthcheck.Interval)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if healthcheck.Retries != nil {
|
||||||
|
retries = int(*healthcheck.Retries)
|
||||||
|
}
|
||||||
|
return &container.HealthConfig{
|
||||||
|
Test: healthcheck.Test,
|
||||||
|
Timeout: timeout,
|
||||||
|
Interval: interval,
|
||||||
|
Retries: retries,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
func convertRestartPolicy(restart string, source *composetypes.RestartPolicy) (*swarm.RestartPolicy, error) {
|
func convertRestartPolicy(restart string, source *composetypes.RestartPolicy) (*swarm.RestartPolicy, error) {
|
||||||
// TODO: log if restart is being ignored
|
// TODO: log if restart is being ignored
|
||||||
if source == nil {
|
if source == nil {
|
||||||
|
@ -571,8 +620,12 @@ func convertUpdateConfig(source *composetypes.UpdateConfig) *swarm.UpdateConfig
|
||||||
if source == nil {
|
if source == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
parallel := uint64(1)
|
||||||
|
if source.Parallelism != nil {
|
||||||
|
parallel = *source.Parallelism
|
||||||
|
}
|
||||||
return &swarm.UpdateConfig{
|
return &swarm.UpdateConfig{
|
||||||
Parallelism: source.Parallelism,
|
Parallelism: parallel,
|
||||||
Delay: source.Delay,
|
Delay: source.Delay,
|
||||||
FailureAction: source.FailureAction,
|
FailureAction: source.FailureAction,
|
||||||
Monitor: source.Monitor,
|
Monitor: source.Monitor,
|
||||||
|
|
Loading…
Reference in New Issue