File tree Expand file tree Collapse file tree 2 files changed +87
-3
lines changed
packages/@aws-cdk/aws-ecs Expand file tree Collapse file tree 2 files changed +87
-3
lines changed Original file line number Diff line number Diff line change @@ -141,7 +141,7 @@ export class TaskDefinition extends cdk.Construct {
141
141
/**
142
142
* All volumes
143
143
*/
144
- private readonly volumes : CfnTaskDefinition . VolumeProperty [ ] = [ ] ;
144
+ private readonly volumes : Volume [ ] = [ ] ;
145
145
146
146
/**
147
147
* Execution role for this task definition
@@ -345,8 +345,12 @@ export interface Volume {
345
345
/**
346
346
* A name for the volume
347
347
*/
348
- name ?: string ;
349
- // FIXME add dockerVolumeConfiguration
348
+ name : string ;
349
+
350
+ /**
351
+ * Specifies this configuration when using Docker volumes
352
+ */
353
+ dockerVolumeConfiguration ?: DockerVolumeConfiguration ;
350
354
}
351
355
352
356
/**
@@ -359,6 +363,50 @@ export interface Host {
359
363
sourcePath ?: string ;
360
364
}
361
365
366
+ /**
367
+ * A configuration of a Docker volume
368
+ */
369
+ export interface DockerVolumeConfiguration {
370
+ /**
371
+ * If true, the Docker volume is created if it does not already exist
372
+ *
373
+ * @default false
374
+ */
375
+ autoprovision ?: boolean ;
376
+ /**
377
+ * The Docker volume driver to use
378
+ */
379
+ driver : string ;
380
+ /**
381
+ * A map of Docker driver specific options passed through
382
+ *
383
+ * @default No options
384
+ */
385
+ driverOpts ?: string [ ] ;
386
+ /**
387
+ * Custom metadata to add to your Docker volume
388
+ *
389
+ * @default No labels
390
+ */
391
+ labels ?: string [ ] ;
392
+ /**
393
+ * The scope for the Docker volume which determines it's lifecycle
394
+ */
395
+ scope : Scope ;
396
+ }
397
+
398
+ export enum Scope {
399
+ /**
400
+ * Docker volumes are automatically provisioned when the task starts and destroyed when the task stops
401
+ */
402
+ Task = "task" ,
403
+
404
+ /**
405
+ * Docker volumes are persist after the task stops
406
+ */
407
+ Shared = "shared"
408
+ }
409
+
362
410
/**
363
411
* A constraint on how instances should be placed
364
412
*/
Original file line number Diff line number Diff line change @@ -237,5 +237,41 @@ export = {
237
237
238
238
test . done ( ) ;
239
239
} ,
240
+
241
+ "correctly sets dockerVolumeConfiguration" ( test : Test ) {
242
+ // GIVEN
243
+ const stack = new cdk . Stack ( ) ;
244
+ const volume = {
245
+ name : "scratch" ,
246
+ dockerVolumeConfiguration : {
247
+ driver : "local" ,
248
+ scope : ecs . Scope . Task
249
+ }
250
+ } ;
251
+
252
+ const taskDefinition = new ecs . Ec2TaskDefinition ( stack , 'Ec2TaskDef' , {
253
+ volumes : [ volume ]
254
+ } ) ;
255
+
256
+ taskDefinition . addContainer ( "web" , {
257
+ image : ecs . ContainerImage . fromDockerHub ( "amazon/amazon-ecs-sample" ) ,
258
+ memoryLimitMiB : 512
259
+ } ) ;
260
+
261
+ // THEN
262
+ expect ( stack ) . to ( haveResourceLike ( "AWS::ECS::TaskDefinition" , {
263
+ Family : "Ec2TaskDef" ,
264
+ Volumes : [ {
265
+ Name : "scratch" ,
266
+ DockerVolumeConfiguration : {
267
+ Driver : "local" ,
268
+ Scope : 'task'
269
+ }
270
+ } ]
271
+ } ) ) ;
272
+
273
+ test . done ( ) ;
274
+ } ,
275
+
240
276
}
241
277
} ;
You can’t perform that action at this time.
0 commit comments