mirror of https://github.com/docker/compose.git
Fix converting run health check options
Signed-off-by: Guillaume Tardif <guillaume.tardif@docker.com>
This commit is contained in:
parent
aa09ecb1f8
commit
0ef42f7bcb
|
@ -86,13 +86,6 @@ func (r *Opts) ToContainerConfig(image string) (containers.ContainerConfig, erro
|
|||
envVars = append(envVars, vars...)
|
||||
}
|
||||
|
||||
var healthCmd []string
|
||||
var healthInterval types.Duration
|
||||
if len(r.HealthCmd) > 0 {
|
||||
healthCmd = strings.Split(r.HealthCmd, " ")
|
||||
healthInterval = types.Duration(r.HealthInterval)
|
||||
}
|
||||
|
||||
return containers.ContainerConfig{
|
||||
ID: r.Name,
|
||||
Image: image,
|
||||
|
@ -106,14 +99,26 @@ func (r *Opts) ToContainerConfig(image string) (containers.ContainerConfig, erro
|
|||
RestartPolicyCondition: restartPolicy,
|
||||
DomainName: r.DomainName,
|
||||
AutoRemove: r.Rm,
|
||||
Healthcheck: containers.Healthcheck{
|
||||
Disable: len(healthCmd) == 0,
|
||||
Test: healthCmd,
|
||||
Interval: healthInterval,
|
||||
},
|
||||
Healthcheck: r.toHealthcheck(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (r *Opts) toHealthcheck() containers.Healthcheck {
|
||||
var healthCmd []string
|
||||
|
||||
if len(r.HealthCmd) > 0 {
|
||||
healthCmd = strings.Split(r.HealthCmd, " ")
|
||||
}
|
||||
return containers.Healthcheck{
|
||||
Disable: len(healthCmd) == 0,
|
||||
Test: healthCmd,
|
||||
Interval: types.Duration(r.HealthInterval),
|
||||
StartPeriod: types.Duration(r.HealthStartPeriod),
|
||||
Timeout: types.Duration(r.HealthTimeout),
|
||||
Retries: r.HealthRetries,
|
||||
}
|
||||
}
|
||||
|
||||
var restartPolicyMap = map[string]string{
|
||||
"": containers.RestartPolicyNone,
|
||||
containers.RestartPolicyNone: containers.RestartPolicyNone,
|
||||
|
|
|
@ -20,7 +20,9 @@ import (
|
|||
"errors"
|
||||
"regexp"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/compose-spec/compose-go/types"
|
||||
"github.com/google/go-cmp/cmp/cmpopts"
|
||||
"gotest.tools/v3/assert"
|
||||
"gotest.tools/v3/assert/cmp"
|
||||
|
@ -227,3 +229,31 @@ func TestValidateRestartPolicy(t *testing.T) {
|
|||
assert.Equal(t, testCase.expected, result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestToHealthcheck(t *testing.T) {
|
||||
testOpt := Opts{
|
||||
HealthCmd: "curl",
|
||||
}
|
||||
|
||||
assert.DeepEqual(t, testOpt.toHealthcheck(), containers.Healthcheck{
|
||||
Disable: false,
|
||||
Test: []string{"curl"},
|
||||
})
|
||||
|
||||
testOpt = Opts{
|
||||
HealthCmd: "curl",
|
||||
HealthRetries: 3,
|
||||
HealthInterval: 5 * time.Second,
|
||||
HealthTimeout: 2 * time.Second,
|
||||
HealthStartPeriod: 10 * time.Second,
|
||||
}
|
||||
|
||||
assert.DeepEqual(t, testOpt.toHealthcheck(), containers.Healthcheck{
|
||||
Disable: false,
|
||||
Test: []string{"curl"},
|
||||
Retries: 3,
|
||||
Interval: types.Duration(5 * time.Second),
|
||||
StartPeriod: types.Duration(10 * time.Second),
|
||||
Timeout: types.Duration(2 * time.Second),
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue