Skip to content

Commit 417e5e8

Browse files
SoManyHsrix0rrr
authored andcommitted
fix(aws-ecs): allow linux parameters to be settable (#2397)
Fixes #2380
1 parent 7d60055 commit 417e5e8

14 files changed

+150
-119
lines changed

packages/@aws-cdk/aws-codepipeline-actions/test/integ.pipeline-ecs-deploy.expected.json

-8
Original file line numberDiff line numberDiff line change
@@ -231,14 +231,6 @@
231231
"Essential": true,
232232
"Image": "amazon/amazon-ecs-sample",
233233
"Links": [],
234-
"LinuxParameters": {
235-
"Capabilities": {
236-
"Add": [],
237-
"Drop": []
238-
},
239-
"Devices": [],
240-
"Tmpfs": []
241-
},
242234
"MountPoints": [],
243235
"Name": "Container",
244236
"PortMappings": [],

packages/@aws-cdk/aws-ecs/lib/container-definition.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,11 @@ export interface ContainerDefinitionOptions {
168168
* Configures a custom log driver for the container.
169169
*/
170170
readonly logging?: LogDriver;
171+
172+
/**
173+
* Configures Linux Parameters
174+
*/
175+
readonly linuxParameters?: LinuxParameters;
171176
}
172177

173178
/**
@@ -187,7 +192,7 @@ export class ContainerDefinition extends cdk.Construct {
187192
/**
188193
* Access Linux Parameters
189194
*/
190-
public readonly linuxParameters = new LinuxParameters();
195+
public readonly linuxParameters?: LinuxParameters;
191196

192197
/**
193198
* The configured mount points
@@ -234,6 +239,7 @@ export class ContainerDefinition extends cdk.Construct {
234239
this.essential = props.essential !== undefined ? props.essential : true;
235240
this.taskDefinition = props.taskDefinition;
236241
this.memoryLimitSpecified = props.memoryLimitMiB !== undefined || props.memoryReservationMiB !== undefined;
242+
this.linuxParameters = props.linuxParameters;
237243

238244
props.image.bind(this);
239245
if (props.logging) { props.logging.bind(this); }
@@ -394,7 +400,7 @@ export class ContainerDefinition extends cdk.Construct {
394400
extraHosts: this.props.extraHosts && renderKV(this.props.extraHosts, 'hostname', 'ipAddress'),
395401
healthCheck: this.props.healthCheck && renderHealthCheck(this.props.healthCheck),
396402
links: this.links,
397-
linuxParameters: this.linuxParameters.renderLinuxParameters(),
403+
linuxParameters: this.linuxParameters && this.linuxParameters.renderLinuxParameters(),
398404
};
399405
}
400406
}

packages/@aws-cdk/aws-ecs/lib/linux-parameters.ts

+34-9
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,61 @@
1+
import cdk = require('@aws-cdk/cdk');
12
import { CfnTaskDefinition } from './ecs.generated';
23

34
/**
4-
* Linux parameter setup in a container
5+
* Properties for defining Linux Parameters
56
*/
6-
export class LinuxParameters {
7+
export interface LinuxParametersProps {
78
/**
89
* Whether the init process is enabled
910
*/
10-
public initProcessEnabled?: boolean;
11+
readonly initProcessEnabled?: boolean;
1112

1213
/**
1314
* The shared memory size
1415
*/
15-
public sharedMemorySize?: number;
16+
readonly sharedMemorySize?: number;
17+
}
18+
19+
/**
20+
* Linux Parameters for an ECS container
21+
*/
22+
export class LinuxParameters extends cdk.Construct {
23+
/**
24+
* Whether the init process is enabled
25+
*/
26+
private readonly initProcessEnabled?: boolean;
27+
28+
/**
29+
* The shared memory size. Not valid for Fargate launch type
30+
*/
31+
private readonly sharedMemorySize?: number;
1632

1733
/**
1834
* Capabilities to be added
1935
*/
20-
private readonly capAdd: Capability[] = [];
36+
private readonly capAdd = new Array<Capability>();
2137

2238
/**
2339
* Capabilities to be dropped
2440
*/
25-
private readonly capDrop: Capability[] = [];
41+
private readonly capDrop = new Array<Capability>();
2642

2743
/**
2844
* Device mounts
2945
*/
30-
private readonly devices: Device[] = [];
46+
private readonly devices = new Array<Device>();
3147

3248
/**
33-
* TMPFS mounts
49+
* TmpFs mounts
3450
*/
35-
private readonly tmpfs: Tmpfs[] = [];
51+
private readonly tmpfs = new Array<Tmpfs>();
52+
53+
constructor(scope: cdk.Construct, id: string, props: LinuxParametersProps = {}) {
54+
super(scope, id);
55+
56+
this.sharedMemorySize = props.sharedMemorySize;
57+
this.initProcessEnabled = props.initProcessEnabled;
58+
}
3659

3760
/**
3861
* Add one or more capabilities
@@ -61,6 +84,8 @@ export class LinuxParameters {
6184

6285
/**
6386
* Add one or more tmpfs mounts
87+
*
88+
* Only works with EC2 launch type.
6489
*/
6590
public addTmpfs(...tmpfs: Tmpfs[]) {
6691
this.tmpfs.push(...tmpfs);

packages/@aws-cdk/aws-ecs/test/ec2/integ.event-task.lit.expected.json

+1-9
Original file line numberDiff line numberDiff line change
@@ -710,14 +710,6 @@
710710
]
711711
},
712712
"Links": [],
713-
"LinuxParameters": {
714-
"Capabilities": {
715-
"Add": [],
716-
"Drop": []
717-
},
718-
"Devices": [],
719-
"Tmpfs": []
720-
},
721713
"LogConfiguration": {
722714
"LogDriver": "awslogs",
723715
"Options": {
@@ -1159,4 +1151,4 @@
11591151
"Description": "S3 key for asset version \"aws-ecs-integ-ecs/AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62c/Code\""
11601152
}
11611153
}
1162-
}
1154+
}

packages/@aws-cdk/aws-ecs/test/ec2/integ.lb-awsvpc-nw.expected.json

+1-9
Original file line numberDiff line numberDiff line change
@@ -766,14 +766,6 @@
766766
"Essential": true,
767767
"Image": "amazon/amazon-ecs-sample",
768768
"Links": [],
769-
"LinuxParameters": {
770-
"Capabilities": {
771-
"Add": [],
772-
"Drop": []
773-
},
774-
"Devices": [],
775-
"Tmpfs": []
776-
},
777769
"Memory": 256,
778770
"MountPoints": [],
779771
"Name": "web",
@@ -1006,4 +998,4 @@
1006998
}
1007999
}
10081000
}
1009-
}
1001+
}

packages/@aws-cdk/aws-ecs/test/ec2/integ.lb-bridge-nw.expected.json

+1-9
Original file line numberDiff line numberDiff line change
@@ -787,14 +787,6 @@
787787
"Essential": true,
788788
"Image": "amazon/amazon-ecs-sample",
789789
"Links": [],
790-
"LinuxParameters": {
791-
"Capabilities": {
792-
"Add": [],
793-
"Drop": []
794-
},
795-
"Devices": [],
796-
"Tmpfs": []
797-
},
798790
"Memory": 256,
799791
"MountPoints": [],
800792
"Name": "web",
@@ -969,4 +961,4 @@
969961
}
970962
}
971963
}
972-
}
964+
}

packages/@aws-cdk/aws-ecs/test/ec2/integ.sd-awsvpc-nw.expected.json

-8
Original file line numberDiff line numberDiff line change
@@ -775,14 +775,6 @@
775775
"Essential": true,
776776
"Image": "amazon/amazon-ecs-sample",
777777
"Links": [],
778-
"LinuxParameters": {
779-
"Capabilities": {
780-
"Add": [],
781-
"Drop": []
782-
},
783-
"Devices": [],
784-
"Tmpfs": []
785-
},
786778
"Memory": 256,
787779
"MountPoints": [],
788780
"Name": "frontend",

packages/@aws-cdk/aws-ecs/test/ec2/integ.sd-bridge-nw.expected.json

-8
Original file line numberDiff line numberDiff line change
@@ -775,14 +775,6 @@
775775
"Essential": true,
776776
"Image": "amazon/amazon-ecs-sample",
777777
"Links": [],
778-
"LinuxParameters": {
779-
"Capabilities": {
780-
"Add": [],
781-
"Drop": []
782-
},
783-
"Devices": [],
784-
"Tmpfs": []
785-
},
786778
"Memory": 256,
787779
"MountPoints": [],
788780
"Name": "frontend",

packages/@aws-cdk/aws-ecs/test/ec2/test.ec2-task-definition.ts

-8
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,6 @@ export = {
7171
Memory: 512,
7272
Image: "amazon/amazon-ecs-sample",
7373
Links: [],
74-
LinuxParameters: {
75-
Capabilities: {
76-
Add: [],
77-
Drop: []
78-
},
79-
Devices: [],
80-
Tmpfs: []
81-
},
8274
MountPoints: [],
8375
Name: "web",
8476
PortMappings: [{

packages/@aws-cdk/aws-ecs/test/fargate/integ.asset-image.expected.json

+1-9
Original file line numberDiff line numberDiff line change
@@ -761,14 +761,6 @@
761761
]
762762
},
763763
"Links": [],
764-
"LinuxParameters": {
765-
"Capabilities": {
766-
"Add": [],
767-
"Drop": []
768-
},
769-
"Devices": [],
770-
"Tmpfs": []
771-
},
772764
"LogConfiguration": {
773765
"LogDriver": "awslogs",
774766
"Options": {
@@ -1040,4 +1032,4 @@
10401032
}
10411033
}
10421034
}
1043-
}
1035+
}

packages/@aws-cdk/aws-ecs/test/fargate/integ.l3.expected.json

-8
Original file line numberDiff line numberDiff line change
@@ -481,14 +481,6 @@
481481
"Essential": true,
482482
"Image": "amazon/amazon-ecs-sample",
483483
"Links": [],
484-
"LinuxParameters": {
485-
"Capabilities": {
486-
"Add": [],
487-
"Drop": []
488-
},
489-
"Devices": [],
490-
"Tmpfs": []
491-
},
492484
"LogConfiguration": {
493485
"LogDriver": "awslogs",
494486
"Options": {

packages/@aws-cdk/aws-ecs/test/fargate/integ.lb-awsvpc-nw.expected.json

-8
Original file line numberDiff line numberDiff line change
@@ -381,14 +381,6 @@
381381
"Essential": true,
382382
"Image": "amazon/amazon-ecs-sample",
383383
"Links": [],
384-
"LinuxParameters": {
385-
"Capabilities": {
386-
"Add": [],
387-
"Drop": []
388-
},
389-
"Devices": [],
390-
"Tmpfs": []
391-
},
392384
"MountPoints": [],
393385
"Name": "web",
394386
"PortMappings": [

0 commit comments

Comments
 (0)