@@ -263,33 +263,29 @@ func isZero(v reflect.Value) bool {
263263 return v .Interface () == zero .Interface ()
264264}
265265
266- // convertToContainerDef transforms each service in the compose yml
267- // to an equivalent ECS container definition
266+ // convertToContainerDef transforms each service in docker- compose. yml and
267+ // ecs-params.yml to an equivalent ECS container definition
268268func convertToContainerDef (context * project.Context , inputCfg * config.ServiceConfig ,
269269 volumes * volumes , outputContDef * ecs.ContainerDefinition , ecsContainerDef * ContainerDef ) error {
270+
270271 // setting memory limit
271- var mem int64
272- var memoryReservation int64
273- if inputCfg .MemReservation != 0 {
274- memoryReservation = int64 (inputCfg .MemReservation ) / miB // convert bytes to MiB
275- }
272+ // MemLimit and MemReservation on libcompose ServiceConfig are parsed
273+ // as yaml.MemStringorInt value representing the memory in bytes
274+ mem := ConvertToMemoryInMB (int64 (inputCfg .MemLimit ))
275+ memoryReservation := ConvertToMemoryInMB (int64 (inputCfg .MemReservation ))
276276
277- if inputCfg .MemLimit != 0 {
278- mem = int64 (inputCfg .MemLimit ) / miB // convert bytes to MiB
279- }
280- // mem_limit should be > mem_reservation, if it is specified
281277 if mem != 0 && memoryReservation != 0 && mem < memoryReservation {
282- return errors .New ("mem_limit should not be less than mem_reservation" )
278+ return errors .New ("mem_limit must be greater than mem_reservation" )
283279 }
284280
285- // TODO: We should be letting docker set the default here -- see note on default shared
286- // memory size?
281+ // One or both of memory and memoryReservation is required to register a task definition with ECS
282+ // NOTE: Docker does not set a memory limit for containers
287283 if mem == 0 && memoryReservation == 0 {
288284 mem = defaultMemLimit
289285 }
290286
291287 // convert shared memory size
292- shmSize := ConvertToSharedMemorySize ( inputCfg )
288+ shmSize := ConvertToMemoryInMB ( int64 ( inputCfg . ShmSize ) )
293289
294290 // convert environment variables
295291 environment := convertToKeyValuePairs (context , inputCfg .Environment , * outputContDef .Name )
@@ -336,7 +332,7 @@ func convertToContainerDef(context *project.Context, inputCfg *config.ServiceCon
336332 return err
337333 }
338334
339- // populating container definition, offloading the validation to aws-sdk
335+ // Populate ECS container definition, offloading the validation to aws-sdk
340336 outputContDef .Cpu = aws .Int64 (int64 (inputCfg .CPUShares ))
341337 outputContDef .Command = aws .StringSlice (inputCfg .Command )
342338 outputContDef .DnsSearchDomains = aws .StringSlice (inputCfg .DNSSearch )
@@ -784,12 +780,11 @@ func ConvertToLogConfiguration(inputCfg *config.ServiceConfig) (*ecs.LogConfigur
784780 return logConfig , nil
785781}
786782
787- // ConvertToSharedMemorySize converts libcompose-parsed bytes
788- // to MiB, expected by ECS
789- func ConvertToSharedMemorySize (inputCfg * config.ServiceConfig ) int64 {
790- var shmSize int64
791- if inputCfg .ShmSize != 0 {
792- shmSize = int64 (inputCfg .ShmSize ) / miB
783+ // ConvertToMemoryInMB converts libcompose-parsed bytes to MiB, expected by ECS
784+ func ConvertToMemoryInMB (bytes int64 ) int64 {
785+ var memory int64
786+ if bytes != 0 {
787+ memory = int64 (bytes ) / miB
793788 }
794- return shmSize
789+ return memory
795790}
0 commit comments