mirror of https://github.com/docker/compose.git
Add support for deploy.resources
Signed-off-by: aiordache <anca.iordache@docker.com> Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
parent
3706d8617f
commit
2ef1e28f1d
|
@ -117,6 +117,44 @@ services:
|
|||
assert.Check(t, s.DesiredCount == 10)
|
||||
}
|
||||
|
||||
func TestTaskSizeConvert(t *testing.T) {
|
||||
template := convertYaml(t, "test", `
|
||||
version: "3"
|
||||
services:
|
||||
test:
|
||||
image: nginx
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
cpus: '0.5'
|
||||
memory: 2048M
|
||||
reservations:
|
||||
cpus: '0.5'
|
||||
memory: 2048M
|
||||
`)
|
||||
def := template.Resources["TestTaskDefinition"].(*ecs.TaskDefinition)
|
||||
assert.Equal(t, def.Cpu, "512")
|
||||
assert.Equal(t, def.Memory, "2048")
|
||||
|
||||
template = convertYaml(t, "test", `
|
||||
version: "3"
|
||||
services:
|
||||
test:
|
||||
image: nginx
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
cpus: '4'
|
||||
memory: 8192M
|
||||
reservations:
|
||||
cpus: '4'
|
||||
memory: 8192M
|
||||
`)
|
||||
def = template.Resources["TestTaskDefinition"].(*ecs.TaskDefinition)
|
||||
assert.Equal(t, def.Cpu, "4096")
|
||||
assert.Equal(t, def.Memory, "8192")
|
||||
}
|
||||
|
||||
func TestLoadBalancerTypeNetwork(t *testing.T) {
|
||||
template := convertYaml(t, "test", `
|
||||
version: "3"
|
||||
|
|
|
@ -16,6 +16,12 @@ var compatibleComposeAttributes = []string{
|
|||
"services.depends_on",
|
||||
"services.deploy",
|
||||
"services.deploy.replicas",
|
||||
"services.deploy.resources.limits",
|
||||
"services.deploy.resources.limits.cpus",
|
||||
"services.deploy.resources.limits.memory",
|
||||
"services.deploy.resources.reservations",
|
||||
"services.deploy.resources.reservations.cpus",
|
||||
"services.deploy.resources.reservations.memory",
|
||||
"services.entrypoint",
|
||||
"services.environment",
|
||||
"service.image",
|
||||
|
|
|
@ -21,6 +21,10 @@ func Convert(project *types.Project, service types.ServiceConfig) (*ecs.TaskDefi
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_, memReservation, err := toContainerReservation(service)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
credential := getRepoCredentials(service)
|
||||
|
||||
// override resolve.conf search directive to also search <project>.local
|
||||
|
@ -60,6 +64,7 @@ func Convert(project *types.Project, service types.ServiceConfig) (*ecs.TaskDefi
|
|||
"awslogs-stream-prefix": project.Name,
|
||||
},
|
||||
},
|
||||
MemoryReservation: memReservation,
|
||||
Name: service.Name,
|
||||
PortMappings: toPortMappings(service.Ports),
|
||||
Privileged: service.Privileged,
|
||||
|
@ -111,6 +116,8 @@ func toSystemControls(sysctls types.Mapping) []ecs.TaskDefinition_SystemControl
|
|||
return sys
|
||||
}
|
||||
|
||||
const Mb = 1024 * 1024
|
||||
|
||||
func toLimits(service types.ServiceConfig) (string, string, error) {
|
||||
// All possible cpu/mem values for Fargate
|
||||
cpuToMem := map[int64][]types.UnitBytes{
|
||||
|
@ -142,9 +149,9 @@ func toLimits(service types.ServiceConfig) (string, string, error) {
|
|||
}
|
||||
|
||||
for cpu, mem := range cpuToMem {
|
||||
if v <= cpu*1024*1024 {
|
||||
if v <= cpu*Mb {
|
||||
for _, m := range mem {
|
||||
if limits.MemoryBytes <= m*1024*1024 {
|
||||
if limits.MemoryBytes <= m*Mb {
|
||||
cpuLimit = strconv.FormatInt(cpu, 10)
|
||||
memLimit = strconv.FormatInt(int64(m), 10)
|
||||
return cpuLimit, memLimit, nil
|
||||
|
@ -155,6 +162,21 @@ func toLimits(service types.ServiceConfig) (string, string, error) {
|
|||
return "", "", fmt.Errorf("unable to find cpu/mem for the required resources")
|
||||
}
|
||||
|
||||
func toContainerReservation(service types.ServiceConfig) (string, int, error) {
|
||||
cpuReservation := ".0"
|
||||
memReservation := 0
|
||||
|
||||
if service.Deploy == nil {
|
||||
return cpuReservation, memReservation, nil
|
||||
}
|
||||
|
||||
reservations := service.Deploy.Resources.Reservations
|
||||
if reservations == nil {
|
||||
return cpuReservation, memReservation, nil
|
||||
}
|
||||
return reservations.NanoCPUs, int(reservations.MemoryBytes / Mb), nil
|
||||
}
|
||||
|
||||
func toRequiresCompatibilities(isolation string) []*string {
|
||||
if isolation == "" {
|
||||
return nil
|
||||
|
@ -206,8 +228,6 @@ func toUlimits(ulimits map[string]*types.UlimitsConfig) []ecs.TaskDefinition_Uli
|
|||
return u
|
||||
}
|
||||
|
||||
const Mb = 1024 * 1024
|
||||
|
||||
func toLinuxParameters(service types.ServiceConfig) *ecs.TaskDefinition_LinuxParameters {
|
||||
return &ecs.TaskDefinition_LinuxParameters{
|
||||
Capabilities: toKernelCapabilities(service.CapAdd, service.CapDrop),
|
||||
|
|
Loading…
Reference in New Issue