@@ -32,6 +32,7 @@ import (
32
32
const (
33
33
defaultMemLimit = 512
34
34
kiB = 1024
35
+ miB = kiB * kiB // 1048576 bytes
35
36
36
37
// access mode with which the volume is mounted
37
38
readOnlyVolumeAccessMode = "ro"
@@ -44,7 +45,7 @@ var supportedComposeYamlOptions = []string{
44
45
"cpu_shares" , "command" , "dns" , "dns_search" , "entrypoint" , "env_file" ,
45
46
"environment" , "extra_hosts" , "hostname" , "image" , "labels" , "links" ,
46
47
"logging" , "log_driver" , "log_opt" , "mem_limit" , "mem_reservation" , "ports" , "privileged" , "read_only" ,
47
- "security_opt" , "ulimits" , "user" , "volumes" , "volumes_from" , "working_dir" , "cap_add" , "cap_drop" ,
48
+ "security_opt" , "ulimits" , "user" , "volumes" , "volumes_from" , "working_dir" , "cap_add" , "cap_drop" , "shm_size" ,
48
49
}
49
50
50
51
var supportedComposeYamlOptionsMap = getSupportedComposeYamlOptionsMap ()
@@ -53,7 +54,6 @@ type volumes struct {
53
54
volumeWithHost map [string ]string
54
55
volumeEmptyHost []string
55
56
}
56
-
57
57
func getSupportedComposeYamlOptionsMap () map [string ]bool {
58
58
optionsMap := make (map [string ]bool )
59
59
for _ , value := range supportedComposeYamlOptions {
@@ -233,10 +233,10 @@ func isZero(v reflect.Value) bool {
233
233
}
234
234
235
235
// convertToContainerDef transforms each service in the compose yml
236
- // to an equivalent container definition
236
+ // to an equivalent ECS container definition
237
237
func convertToContainerDef (context * project.Context , inputCfg * config.ServiceConfig ,
238
238
volumes * volumes , outputContDef * ecs.ContainerDefinition , ecsContainerDef * ContainerDef ) error {
239
- // setting memory
239
+ // setting memory limit
240
240
var mem int64
241
241
var memoryReservation int64
242
242
if inputCfg .MemReservation != 0 {
@@ -251,10 +251,20 @@ func convertToContainerDef(context *project.Context, inputCfg *config.ServiceCon
251
251
return errors .New ("mem_limit should not be less than mem_reservation" )
252
252
}
253
253
254
+ // TODO: We should be letting docker set the default here -- see note on default shared
255
+ // memory size?
254
256
if mem == 0 && memoryReservation == 0 {
255
257
mem = defaultMemLimit
256
258
}
257
259
260
+ // convert shared memory size
261
+ var shmSize int64
262
+ if inputCfg .ShmSize != 0 {
263
+ // libcompose will parse this field in the docker compose file as bytes but ECS
264
+ // expects sharedMemorySize in MiB
265
+ shmSize = int64 (inputCfg .ShmSize ) / miB
266
+ }
267
+
258
268
// convert environment variables
259
269
environment := convertToKeyValuePairs (context , inputCfg .Environment , * outputContDef .Name )
260
270
@@ -340,6 +350,13 @@ func convertToContainerDef(context *project.Context, inputCfg *config.ServiceCon
340
350
outputContDef .LinuxParameters .Capabilities .SetDrop (aws .StringSlice (inputCfg .CapDrop ))
341
351
}
342
352
353
+ // Only set shmSize if specified. Otherwise we expect this sharedMemorySize for the
354
+ // containerDefinition to be null; Docker will by default allocate 64M for shared memory if
355
+ // shmSize is null.
356
+ if shmSize != 0 {
357
+ outputContDef .LinuxParameters .SetSharedMemorySize (shmSize )
358
+ }
359
+
343
360
if ecsContainerDef != nil {
344
361
outputContDef .Essential = aws .Bool (ecsContainerDef .Essential )
345
362
}
0 commit comments