Skip to content

Commit 460b911

Browse files
committed
Add service cpu_shares, mem_limit, and mem_reservation fields to ecs-params
1 parent a1139bc commit 460b911

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

ecs-cli/modules/utils/compose/ecs_params_reader.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,17 @@ package utils
1616
// ECS Params Reader is used to parse the ecs-params.yml file and marshal the data into the ECSParams struct
1717

1818
import (
19+
"io/ioutil"
20+
"os"
21+
1922
"github.com/aws/aws-sdk-go/aws"
2023
"github.com/aws/aws-sdk-go/service/ecs"
24+
libYaml "github.com/docker/libcompose/yaml"
2125
"github.com/pkg/errors"
2226
"gopkg.in/yaml.v2"
23-
"io/ioutil"
24-
"os"
2527
)
2628

29+
// ECSParams contains the information parsed from the ecs-params.yml file
2730
type ECSParams struct {
2831
Version string
2932
TaskDefinition EcsTaskDef `yaml:"task_definition"`
@@ -36,15 +39,23 @@ type EcsTaskDef struct {
3639
TaskRoleArn string `yaml:"task_role_arn"`
3740
ContainerDefinitions ContainerDefs `yaml:"services"`
3841
ExecutionRole string `yaml:"task_execution_role"`
39-
TaskSize TaskSize `yaml:"task_size"` // Needed to run FARGATE tasks
42+
TaskSize TaskSize `yaml:"task_size"` // Needed to run FARGATE tasks
4043
}
4144

45+
// ContainerDefs is a map of ContainerDefs within a task definition
4246
type ContainerDefs map[string]ContainerDef
4347

48+
// ContainerDef specifies settings for a specific container
4449
type ContainerDef struct {
4550
Essential bool `yaml:"essential"`
51+
// resource field yaml names correspond to equivalent docker-compose field
52+
Cpu int64 `yaml:"cpu_shares"`
53+
Memory libYaml.MemStringorInt `yaml:"mem_limit"`
54+
MemoryReservation libYaml.MemStringorInt `yaml:"mem_reservation"`
4655
}
4756

57+
// TaskSize holds Cpu and Memory values needed for Fargate tasks
58+
// https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-cpu-memory-error.html
4859
type TaskSize struct {
4960
Cpu string `yaml:"cpu_limit"`
5061
Memory string `yaml:"mem_limit"`
@@ -55,10 +66,14 @@ type RunParams struct {
5566
NetworkConfiguration NetworkConfiguration `yaml:"network_configuration"`
5667
}
5768

69+
// NetworkConfiguration specifies the network config for the task definition.
70+
// Supports values 'awsvpc' (required for Fargate), 'bridge', 'host' or 'none'
5871
type NetworkConfiguration struct {
5972
AwsVpcConfiguration AwsVpcConfiguration `yaml:"awsvpc_configuration"`
6073
}
6174

75+
// AwsVpcConfiguration specifies the networking resources available to
76+
// tasks running in 'awsvpc' networking mode
6277
type AwsVpcConfiguration struct {
6378
Subnets []string `yaml:"subnets"`
6479
SecurityGroups []string `yaml:"security_groups"`

ecs-cli/modules/utils/compose/ecs_params_reader_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"testing"
2020

2121
"github.com/aws/aws-sdk-go/aws"
22+
"github.com/docker/libcompose/yaml"
2223
"github.com/stretchr/testify/assert"
2324
)
2425

@@ -77,6 +78,9 @@ task_definition:
7778
services:
7879
mysql:
7980
essential: false
81+
cpu_shares: 100
82+
mem_limit: 524288000
83+
mem_reservation: 500mb
8084
wordpress:
8185
essential: true`
8286

@@ -108,6 +112,9 @@ task_definition:
108112
wordpress := containerDefs["wordpress"]
109113

110114
assert.False(t, mysql.Essential, "Expected container to not be essential")
115+
assert.Equal(t, int64(100), mysql.Cpu)
116+
assert.Equal(t, yaml.MemStringorInt(524288000), mysql.Memory)
117+
assert.Equal(t, yaml.MemStringorInt(524288000), mysql.MemoryReservation)
111118
assert.True(t, wordpress.Essential, "Expected container to be essential")
112119
}
113120
}

0 commit comments

Comments
 (0)