Skip to content

Commit

Permalink
fix(aws-ecs): allow linux parameters to be settable (#2397)
Browse files Browse the repository at this point in the history
Fixes #2380
  • Loading branch information
SoManyHs authored and rix0rrr committed May 7, 2019
1 parent 7d60055 commit 417e5e8
Show file tree
Hide file tree
Showing 14 changed files with 150 additions and 119 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -231,14 +231,6 @@
"Essential": true,
"Image": "amazon/amazon-ecs-sample",
"Links": [],
"LinuxParameters": {
"Capabilities": {
"Add": [],
"Drop": []
},
"Devices": [],
"Tmpfs": []
},
"MountPoints": [],
"Name": "Container",
"PortMappings": [],
Expand Down
10 changes: 8 additions & 2 deletions packages/@aws-cdk/aws-ecs/lib/container-definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,11 @@ export interface ContainerDefinitionOptions {
* Configures a custom log driver for the container.
*/
readonly logging?: LogDriver;

/**
* Configures Linux Parameters
*/
readonly linuxParameters?: LinuxParameters;
}

/**
Expand All @@ -187,7 +192,7 @@ export class ContainerDefinition extends cdk.Construct {
/**
* Access Linux Parameters
*/
public readonly linuxParameters = new LinuxParameters();
public readonly linuxParameters?: LinuxParameters;

/**
* The configured mount points
Expand Down Expand Up @@ -234,6 +239,7 @@ export class ContainerDefinition extends cdk.Construct {
this.essential = props.essential !== undefined ? props.essential : true;
this.taskDefinition = props.taskDefinition;
this.memoryLimitSpecified = props.memoryLimitMiB !== undefined || props.memoryReservationMiB !== undefined;
this.linuxParameters = props.linuxParameters;

props.image.bind(this);
if (props.logging) { props.logging.bind(this); }
Expand Down Expand Up @@ -394,7 +400,7 @@ export class ContainerDefinition extends cdk.Construct {
extraHosts: this.props.extraHosts && renderKV(this.props.extraHosts, 'hostname', 'ipAddress'),
healthCheck: this.props.healthCheck && renderHealthCheck(this.props.healthCheck),
links: this.links,
linuxParameters: this.linuxParameters.renderLinuxParameters(),
linuxParameters: this.linuxParameters && this.linuxParameters.renderLinuxParameters(),
};
}
}
Expand Down
43 changes: 34 additions & 9 deletions packages/@aws-cdk/aws-ecs/lib/linux-parameters.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,61 @@
import cdk = require('@aws-cdk/cdk');
import { CfnTaskDefinition } from './ecs.generated';

/**
* Linux parameter setup in a container
* Properties for defining Linux Parameters
*/
export class LinuxParameters {
export interface LinuxParametersProps {
/**
* Whether the init process is enabled
*/
public initProcessEnabled?: boolean;
readonly initProcessEnabled?: boolean;

/**
* The shared memory size
*/
public sharedMemorySize?: number;
readonly sharedMemorySize?: number;
}

/**
* Linux Parameters for an ECS container
*/
export class LinuxParameters extends cdk.Construct {
/**
* Whether the init process is enabled
*/
private readonly initProcessEnabled?: boolean;

/**
* The shared memory size. Not valid for Fargate launch type
*/
private readonly sharedMemorySize?: number;

/**
* Capabilities to be added
*/
private readonly capAdd: Capability[] = [];
private readonly capAdd = new Array<Capability>();

/**
* Capabilities to be dropped
*/
private readonly capDrop: Capability[] = [];
private readonly capDrop = new Array<Capability>();

/**
* Device mounts
*/
private readonly devices: Device[] = [];
private readonly devices = new Array<Device>();

/**
* TMPFS mounts
* TmpFs mounts
*/
private readonly tmpfs: Tmpfs[] = [];
private readonly tmpfs = new Array<Tmpfs>();

constructor(scope: cdk.Construct, id: string, props: LinuxParametersProps = {}) {
super(scope, id);

this.sharedMemorySize = props.sharedMemorySize;
this.initProcessEnabled = props.initProcessEnabled;
}

/**
* Add one or more capabilities
Expand Down Expand Up @@ -61,6 +84,8 @@ export class LinuxParameters {

/**
* Add one or more tmpfs mounts
*
* Only works with EC2 launch type.
*/
public addTmpfs(...tmpfs: Tmpfs[]) {
this.tmpfs.push(...tmpfs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -710,14 +710,6 @@
]
},
"Links": [],
"LinuxParameters": {
"Capabilities": {
"Add": [],
"Drop": []
},
"Devices": [],
"Tmpfs": []
},
"LogConfiguration": {
"LogDriver": "awslogs",
"Options": {
Expand Down Expand Up @@ -1159,4 +1151,4 @@
"Description": "S3 key for asset version \"aws-ecs-integ-ecs/AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62c/Code\""
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -766,14 +766,6 @@
"Essential": true,
"Image": "amazon/amazon-ecs-sample",
"Links": [],
"LinuxParameters": {
"Capabilities": {
"Add": [],
"Drop": []
},
"Devices": [],
"Tmpfs": []
},
"Memory": 256,
"MountPoints": [],
"Name": "web",
Expand Down Expand Up @@ -1006,4 +998,4 @@
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -787,14 +787,6 @@
"Essential": true,
"Image": "amazon/amazon-ecs-sample",
"Links": [],
"LinuxParameters": {
"Capabilities": {
"Add": [],
"Drop": []
},
"Devices": [],
"Tmpfs": []
},
"Memory": 256,
"MountPoints": [],
"Name": "web",
Expand Down Expand Up @@ -969,4 +961,4 @@
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -775,14 +775,6 @@
"Essential": true,
"Image": "amazon/amazon-ecs-sample",
"Links": [],
"LinuxParameters": {
"Capabilities": {
"Add": [],
"Drop": []
},
"Devices": [],
"Tmpfs": []
},
"Memory": 256,
"MountPoints": [],
"Name": "frontend",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -775,14 +775,6 @@
"Essential": true,
"Image": "amazon/amazon-ecs-sample",
"Links": [],
"LinuxParameters": {
"Capabilities": {
"Add": [],
"Drop": []
},
"Devices": [],
"Tmpfs": []
},
"Memory": 256,
"MountPoints": [],
"Name": "frontend",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,6 @@ export = {
Memory: 512,
Image: "amazon/amazon-ecs-sample",
Links: [],
LinuxParameters: {
Capabilities: {
Add: [],
Drop: []
},
Devices: [],
Tmpfs: []
},
MountPoints: [],
Name: "web",
PortMappings: [{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -761,14 +761,6 @@
]
},
"Links": [],
"LinuxParameters": {
"Capabilities": {
"Add": [],
"Drop": []
},
"Devices": [],
"Tmpfs": []
},
"LogConfiguration": {
"LogDriver": "awslogs",
"Options": {
Expand Down Expand Up @@ -1040,4 +1032,4 @@
}
}
}
}
}
8 changes: 0 additions & 8 deletions packages/@aws-cdk/aws-ecs/test/fargate/integ.l3.expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -481,14 +481,6 @@
"Essential": true,
"Image": "amazon/amazon-ecs-sample",
"Links": [],
"LinuxParameters": {
"Capabilities": {
"Add": [],
"Drop": []
},
"Devices": [],
"Tmpfs": []
},
"LogConfiguration": {
"LogDriver": "awslogs",
"Options": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,14 +381,6 @@
"Essential": true,
"Image": "amazon/amazon-ecs-sample",
"Links": [],
"LinuxParameters": {
"Capabilities": {
"Add": [],
"Drop": []
},
"Devices": [],
"Tmpfs": []
},
"MountPoints": [],
"Name": "web",
"PortMappings": [
Expand Down
Loading

0 comments on commit 417e5e8

Please sign in to comment.