Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ecs-patterns): Add support for Docker labels to ECS Patterns #14783

Merged
merged 20 commits into from
Jun 9, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
4a711aa
Add support for Docker labels to ECS Patterns
ABevier May 19, 2021
d981ecb
Merge branch 'master' into ecs-pattern-dockerlabel
ABevier May 19, 2021
15ce86b
Merge branch 'master' into ecs-pattern-dockerlabel
ABevier May 20, 2021
2fee3ee
Merge branch 'master' into ecs-pattern-dockerlabel
ABevier May 20, 2021
fad2527
Merge branch 'master' into ecs-pattern-dockerlabel
ABevier May 20, 2021
3518adf
Merge branch 'master' into ecs-pattern-dockerlabel
ABevier May 20, 2021
22e4a6e
Merge branch 'master' into ecs-pattern-dockerlabel
ABevier May 21, 2021
bd05a45
Merge branch 'master' into ecs-pattern-dockerlabel
ABevier May 21, 2021
300eb8f
Merge branch 'master' into ecs-pattern-dockerlabel
ABevier May 24, 2021
dfb288b
Merge branch 'master' into ecs-pattern-dockerlabel
ABevier May 24, 2021
bfe7cf8
Merge branch 'master' into ecs-pattern-dockerlabel
ABevier May 27, 2021
5da3553
Merge branch 'master' into ecs-pattern-dockerlabel
ABevier Jun 1, 2021
b25fd52
Merge branch 'master' into ecs-pattern-dockerlabel
ABevier Jun 1, 2021
15be8b5
Merge branch 'master' into ecs-pattern-dockerlabel
ABevier Jun 2, 2021
e7ceb46
Merge branch 'master' into ecs-pattern-dockerlabel
ABevier Jun 3, 2021
c678f2d
update README
ABevier Jun 7, 2021
b86506c
Merge branch 'master' into ecs-pattern-dockerlabel
ABevier Jun 7, 2021
71c63ee
Merge branch 'master' into ecs-pattern-dockerlabel
ABevier Jun 8, 2021
b2efb47
Merge branch 'master' into ecs-pattern-dockerlabel
SoManyHs Jun 9, 2021
3aa8ee3
Merge branch 'master' into ecs-pattern-dockerlabel
SoManyHs Jun 9, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,13 @@ export interface ApplicationLoadBalancedTaskImageOptions {
* @default - Automatically generated name.
*/
readonly family?: string;

/**
* A key/value map of labels to add to the container.
*
* @default - No labels.
*/
readonly dockerLabels?: { [key: string]: string };
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,13 @@ export interface ApplicationLoadBalancedTaskImageProps {
* @default - Automatically generated name.
*/
readonly family?: string;

/**
* A key/value map of labels to add to the container.
*
* @default - No labels.
*/
readonly dockerLabels?: { [key: string]: string };
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,13 @@ export interface NetworkLoadBalancedTaskImageOptions {
* @default - Automatically generated name.
*/
readonly family?: string;

/**
* A key/value map of labels to add to the container.
*
* @default - No labels.
*/
readonly dockerLabels?: { [key: string]: string };
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,13 @@ export interface NetworkLoadBalancedTaskImageProps {
* @default - Automatically generated name.
*/
readonly family?: string;

/**
* A key/value map of labels to add to the container.
*
* @default - No labels.
*/
readonly dockerLabels?: { [key: string]: string };
}

/**
Expand Down Expand Up @@ -452,4 +459,4 @@ export abstract class NetworkMultipleTargetGroupsServiceBase extends CoreConstru
});
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ export class ApplicationLoadBalancedEc2Service extends ApplicationLoadBalancedSe
environment: taskImageOptions.environment,
secrets: taskImageOptions.secrets,
logging: logDriver,
dockerLabels: taskImageOptions.dockerLabels,
});
container.addPortMappings({
containerPort: taskImageOptions.containerPort || 80,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ export class ApplicationMultipleTargetGroupsEc2Service extends ApplicationMultip
environment: taskImageOptions.environment,
secrets: taskImageOptions.secrets,
logging: this.logDriver,
dockerLabels: taskImageOptions.dockerLabels,
});
if (taskImageOptions.containerPorts) {
for (const containerPort of taskImageOptions.containerPorts) {
Expand Down Expand Up @@ -151,4 +152,4 @@ export class ApplicationMultipleTargetGroupsEc2Service extends ApplicationMultip
cloudMapOptions: props.cloudMapOptions,
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ export class NetworkLoadBalancedEc2Service extends NetworkLoadBalancedServiceBas
environment: taskImageOptions.environment,
secrets: taskImageOptions.secrets,
logging: logDriver,
dockerLabels: taskImageOptions.dockerLabels,
});
container.addPortMappings({
containerPort: taskImageOptions.containerPort || 80,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ export class NetworkMultipleTargetGroupsEc2Service extends NetworkMultipleTarget
environment: taskImageOptions.environment,
secrets: taskImageOptions.secrets,
logging: this.logDriver,
dockerLabels: taskImageOptions.dockerLabels,
});
if (taskImageOptions.containerPorts) {
for (const containerPort of taskImageOptions.containerPorts) {
Expand Down Expand Up @@ -151,4 +152,4 @@ export class NetworkMultipleTargetGroupsEc2Service extends NetworkMultipleTarget
cloudMapOptions: props.cloudMapOptions,
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ export class ApplicationLoadBalancedFargateService extends ApplicationLoadBalanc
logging: logDriver,
environment: taskImageOptions.environment,
secrets: taskImageOptions.secrets,
dockerLabels: taskImageOptions.dockerLabels,
});
container.addPortMappings({
containerPort: taskImageOptions.containerPort || 80,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ export class ApplicationMultipleTargetGroupsFargateService extends ApplicationMu
logging: this.logDriver,
environment: taskImageOptions.environment,
secrets: taskImageOptions.secrets,
dockerLabels: taskImageOptions.dockerLabels,
});
if (taskImageOptions.containerPorts) {
for (const containerPort of taskImageOptions.containerPorts) {
Expand Down Expand Up @@ -184,4 +185,4 @@ export class ApplicationMultipleTargetGroupsFargateService extends ApplicationMu
platformVersion: props.platformVersion,
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ export class NetworkLoadBalancedFargateService extends NetworkLoadBalancedServic
logging: logDriver,
environment: taskImageOptions.environment,
secrets: taskImageOptions.secrets,
dockerLabels: taskImageOptions.dockerLabels,
});
container.addPortMappings({
containerPort: taskImageOptions.containerPort || 80,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ export class NetworkMultipleTargetGroupsFargateService extends NetworkMultipleTa
logging: this.logDriver,
environment: taskImageOptions.environment,
secrets: taskImageOptions.secrets,
dockerLabels: taskImageOptions.dockerLabels,
});
if (taskImageOptions.containerPorts) {
for (const containerPort of taskImageOptions.containerPorts) {
Expand Down Expand Up @@ -184,4 +185,4 @@ export class NetworkMultipleTargetGroupsFargateService extends NetworkMultipleTa
platformVersion: props.platformVersion,
});
}
}
}
12 changes: 11 additions & 1 deletion packages/@aws-cdk/aws-ecs-patterns/test/ec2/test.l3s-v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ export = {
taskRole: new Role(stack, 'TaskRole', {
assumedBy: new ServicePrincipal('ecs-tasks.amazonaws.com'),
}),
dockerLabels: { label1: 'labelValue1', label2: 'labelValue2' },
},
cpu: 256,
desiredCount: 3,
Expand Down Expand Up @@ -214,6 +215,10 @@ export = {
Protocol: 'tcp',
},
],
DockerLabels: {
label1: 'labelValue1',
label2: 'labelValue2',
},
},
],
ExecutionRoleArn: {
Expand Down Expand Up @@ -967,6 +972,7 @@ export = {
taskRole: new Role(stack, 'TaskRole', {
assumedBy: new ServicePrincipal('ecs-tasks.amazonaws.com'),
}),
dockerLabels: { label1: 'labelValue1', label2: 'labelValue2' },
},
cpu: 256,
desiredCount: 3,
Expand Down Expand Up @@ -1079,6 +1085,10 @@ export = {
Protocol: 'tcp',
},
],
DockerLabels: {
label1: 'labelValue1',
label2: 'labelValue2',
},
},
],
ExecutionRoleArn: {
Expand Down Expand Up @@ -1532,4 +1542,4 @@ export = {
test.done();
},
},
};
};
10 changes: 10 additions & 0 deletions packages/@aws-cdk/aws-ecs-patterns/test/ec2/test.l3s.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export = {
TEST_ENVIRONMENT_VARIABLE1: 'test environment variable 1 value',
TEST_ENVIRONMENT_VARIABLE2: 'test environment variable 2 value',
},
dockerLabels: { label1: 'labelValue1', label2: 'labelValue2' },
},
desiredCount: 2,
});
Expand All @@ -54,6 +55,10 @@ export = {
},
],
Memory: 1024,
DockerLabels: {
label1: 'labelValue1',
label2: 'labelValue2',
},
},
],
}));
Expand Down Expand Up @@ -389,6 +394,7 @@ export = {
TEST_ENVIRONMENT_VARIABLE1: 'test environment variable 1 value',
TEST_ENVIRONMENT_VARIABLE2: 'test environment variable 2 value',
},
dockerLabels: { label1: 'labelValue1', label2: 'labelValue2' },
},
desiredCount: 2,
});
Expand Down Expand Up @@ -416,6 +422,10 @@ export = {
'awslogs-region': { Ref: 'AWS::Region' },
},
},
DockerLabels: {
label1: 'labelValue1',
label2: 'labelValue2',
},
},
],
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ export = {
taskRole: new Role(stack, 'TaskRole', {
assumedBy: new ServicePrincipal('ecs-tasks.amazonaws.com'),
}),
dockerLabels: { label1: 'labelValue1', label2: 'labelValue2' },
},
cpu: 256,
assignPublicIp: true,
Expand Down Expand Up @@ -223,6 +224,10 @@ export = {
Protocol: 'tcp',
},
],
DockerLabels: {
label1: 'labelValue1',
label2: 'labelValue2',
},
},
],
Cpu: '256',
Expand Down Expand Up @@ -413,6 +418,7 @@ export = {
taskRole: new Role(stack, 'TaskRole', {
assumedBy: new ServicePrincipal('ecs-tasks.amazonaws.com'),
}),
dockerLabels: { label1: 'labelValue1', label2: 'labelValue2' },
},
cpu: 256,
assignPublicIp: true,
Expand Down Expand Up @@ -517,6 +523,10 @@ export = {
Protocol: 'tcp',
},
],
DockerLabels: {
label1: 'labelValue1',
label2: 'labelValue2',
},
},
],
Cpu: '256',
Expand Down Expand Up @@ -599,4 +609,4 @@ export = {
test.done();
},
},
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -1012,4 +1012,65 @@ export = {

},

'test ALB load balanced service with docker labels defined'(test: Test) {
// GIVEN
const stack = new cdk.Stack();
const vpc = new ec2.Vpc(stack, 'VPC');
const cluster = new ecs.Cluster(stack, 'Cluster', { vpc });

// WHEN
new ecsPatterns.ApplicationLoadBalancedFargateService(stack, 'Service', {
cluster,
taskImageOptions: {
image: ecs.ContainerImage.fromRegistry('/aws/aws-example-app'),
dockerLabels: { label1: 'labelValue1', label2: 'labelValue2' },
},
});

// THEN
expect(stack).to(haveResourceLike('AWS::ECS::TaskDefinition', {
ContainerDefinitions: [
{
Image: '/aws/aws-example-app',
DockerLabels: {
label1: 'labelValue1',
label2: 'labelValue2',
},
},
],
}));

test.done();
},

'test Network load balanced service with docker labels defined'(test: Test) {
// GIVEN
const stack = new cdk.Stack();
const vpc = new ec2.Vpc(stack, 'VPC');
const cluster = new ecs.Cluster(stack, 'Cluster', { vpc });

// WHEN
new ecsPatterns.NetworkLoadBalancedFargateService(stack, 'Service', {
cluster,
taskImageOptions: {
image: ecs.ContainerImage.fromRegistry('/aws/aws-example-app'),
dockerLabels: { label1: 'labelValue1', label2: 'labelValue2' },
},
});

// THEN
expect(stack).to(haveResourceLike('AWS::ECS::TaskDefinition', {
ContainerDefinitions: [
{
Image: '/aws/aws-example-app',
DockerLabels: {
label1: 'labelValue1',
label2: 'labelValue2',
},
},
],
}));

test.done();
},
};