@@ -74,6 +74,18 @@ func TestParseV1V2_Version1_HappyPath(t *testing.T) {
74
74
securityOpts := []string {"label:type:test_virt" }
75
75
shmSize := int64 (128 )
76
76
user := "user"
77
+ ulimits := []* ecs.Ulimit {
78
+ {
79
+ Name : aws .String ("nproc" ),
80
+ HardLimit : aws .Int64 (65535 ),
81
+ SoftLimit : aws .Int64 (65535 ),
82
+ },
83
+ {
84
+ Name : aws .String ("nofile" ),
85
+ HardLimit : aws .Int64 (40000 ),
86
+ SoftLimit : aws .Int64 (20000 ),
87
+ },
88
+ }
77
89
volumesFrom := []* ecs.VolumeFrom {
78
90
{
79
91
ReadOnly : aws .Bool (true ),
@@ -115,7 +127,10 @@ func TestParseV1V2_Version1_HappyPath(t *testing.T) {
115
127
- label:type:test_virt
116
128
shm_size: 128M
117
129
ulimits:
118
- nofile: 1024
130
+ nproc: 65535
131
+ nofile:
132
+ soft: 20000
133
+ hard: 40000
119
134
user: user
120
135
volumes:
121
136
- ./code
@@ -160,7 +175,7 @@ redis:
160
175
assert .Equal (t , cpuShares , web .CPU , "Expected CPU to match" )
161
176
assert .Equal (t , dnsSearchDomains , web .DNSSearchDomains , "Expected DNSSearchDomains to match" )
162
177
assert .Equal (t , dnsServers , web .DNSServers , "Expected DNSServers to match" )
163
- assert .Equal (t , labels , web .DockerLabels , "Expected docker labels to match" )
178
+ assert .Equal (t , labels , web .DockerLabels , "Expected DockerLabels to match" )
164
179
assert .Equal (t , securityOpts , web .DockerSecurityOptions , "Expected DockerSecurityOptions to match" )
165
180
assert .Equal (t , entryPoint , web .Entrypoint , "Expected EntryPoint to be match" )
166
181
assert .Equal (t , env , web .Environment , "Expected Environment to match" )
@@ -169,13 +184,14 @@ redis:
169
184
assert .Equal (t , webImage , web .Image , "Expected Image to match" )
170
185
assert .Equal (t , links , web .Links , "Expected Links to match" )
171
186
assert .Equal (t , logging , web .LogConfiguration , "Expected LogConfiguration to match" )
172
- assert .Equal (t , memory , web .Memory , "Expected memory to match" )
187
+ assert .Equal (t , memory , web .Memory , "Expected Memory to match" )
173
188
assert .Equal (t , mountPoints , web .MountPoints , "Expected MountPoints to match" )
174
- assert .Equal (t , ports , web .PortMappings , "Expected PortMappings to match" )
189
+ assert .ElementsMatch (t , ports , web .PortMappings , "Expected PortMappings to match" )
175
190
assert .Equal (t , privileged , web .Privileged , "Expected Privileged to match" )
176
191
assert .Equal (t , readonly , web .ReadOnly , "Expected ReadOnly to match" )
177
192
assert .Equal (t , shmSize , web .ShmSize , "Expected ShmSize to match" )
178
- assert .Equal (t , user , web .User , "Expected user to match" )
193
+ assert .Equal (t , user , web .User , "Expected User to match" )
194
+ assert .ElementsMatch (t , ulimits , web .Ulimits , "Expected Ulimits to match" )
179
195
assert .Equal (t , workingDir , web .WorkingDirectory , "Expected WorkingDirectory to match" )
180
196
}
181
197
@@ -232,8 +248,7 @@ func TestParseV1V2_Version2Files(t *testing.T) {
232
248
Size : aws .Int64 (64 ),
233
249
},
234
250
}
235
- volumesFrom := []* ecs.VolumeFrom {
236
- {
251
+ volumesFrom := []* ecs.VolumeFrom { {
237
252
ReadOnly : aws .Bool (false ),
238
253
SourceContainer : aws .String ("mysql" ),
239
254
},
@@ -367,6 +382,79 @@ func TestParseV1V2_Version1_WithEnvFile(t *testing.T) {
367
382
assert .Equal (t , expectedEnv , web .Environment , "Expected Environment to match" )
368
383
}
369
384
385
+ func TestParseV1V2_WithEnvFromShell (t * testing.T ) {
386
+ // If the value for a key in the environment field is blank, it
387
+ // resolves to the shell value (good for specifying secrets).
388
+ // If a value is specified for a key in the environment field, it
389
+ // overrides the shell value for that key.
390
+
391
+ envKey1 := "RACK_ENV"
392
+ envValue1 := "staging"
393
+
394
+ envKey2 := "SHOW"
395
+ envValue2 := "true"
396
+ envKey3 := "SESSION_SECRET"
397
+ envValue3 := "clydeIsTheGoodestDog"
398
+
399
+ os .Setenv (envKey1 , envValue1 )
400
+ os .Setenv (envKey2 , envValue2 )
401
+ os .Setenv (envKey3 , envValue3 )
402
+ defer func () {
403
+ os .Unsetenv (envKey1 )
404
+ os .Unsetenv (envKey2 )
405
+ os .Unsetenv (envKey3 )
406
+ }()
407
+
408
+ expectedEnv := []* ecs.KeyValuePair {
409
+ {
410
+ Name : aws .String (envKey1 ),
411
+ Value : aws .String ("development" ),
412
+ },
413
+ {
414
+ Name : aws .String (envKey2 ),
415
+ Value : aws .String (envValue2 ),
416
+ },
417
+ {
418
+ Name : aws .String (envKey3 ),
419
+ Value : aws .String (envValue3 ),
420
+ },
421
+ }
422
+ // Setup docker-compose file
423
+ webImage := "webapp"
424
+ composeFileString := `version: '2'
425
+ services:
426
+ web:
427
+ image: webapp
428
+ environment:
429
+ - RACK_ENV=development
430
+ - SHOW=
431
+ - SESSION_SECRET`
432
+
433
+ tmpfile , err := ioutil .TempFile ("" , "test" )
434
+ assert .NoError (t , err , "Unexpected error in creating test file" )
435
+
436
+ defer os .Remove (tmpfile .Name ())
437
+
438
+ _ , err = tmpfile .Write ([]byte (composeFileString ))
439
+ assert .NoError (t , err , "Unexpected error in writing to test file" )
440
+
441
+ err = tmpfile .Close ()
442
+ assert .NoError (t , err , "Unexpected error closing file" )
443
+
444
+ // Set up project
445
+ project := setupTestProject (t )
446
+ project .ecsContext .ComposeFiles = append (project .ecsContext .ComposeFiles , tmpfile .Name ())
447
+
448
+ actualConfigs , err := project .parseV1V2 ()
449
+ assert .NoError (t , err , "Unexpected error parsing file" )
450
+
451
+ // verify wordpress ServiceConfig
452
+ web , err := getContainerConfigByName ("web" , actualConfigs )
453
+ assert .NoError (t , err , "Unexpected error retrieving container config" )
454
+ assert .Equal (t , webImage , web .Image , "Expected Image to match" )
455
+ assert .Equal (t , expectedEnv , web .Environment , "Expected Environment to match" )
456
+ }
457
+
370
458
func getContainerConfigByName (name string , configs * []containerconfig.ContainerConfig ) (* containerconfig.ContainerConfig , error ) {
371
459
for _ , config := range * configs {
372
460
if config .Name == name {
0 commit comments