-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Description
Describe the feature
It would be nice to be able to add docker labels after the container has been constructed.
For example, I can call addEnvironment to add an environment variable after the fact: https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ecs.ContainerDefinition.html#addwbrenvironmentname-value
However, I can't do the same with docker labels.
Use Case
I have a construct that automatically applies Datadog monitoring information to a TaskDefinition with an application container. Datadog requires that I set some information as Docker Labels for observability:
However, I want to add these labels after the user already created their default container.
Proposed Solution
Add a .addDockerLabel method similar to .addEnvironment to the ContainerDefiniton construct. It'd be similar to #2559 / #17889
Other Information
You can hack this like so:
const defaultContainerAsAny = defaultContainer as any;
defaultContainerAsAny.props.dockerLabels = Object.assign(defaultContainerAsAny.props.dockerLabels || {}, {
"com.datadoghq.tags.env": this.env,
"com.datadoghq.tags.service": serviceName,
// TODO: The ECS CircleCI orb doesn't expose the ability to set `dockerLabels` when deploying
// a task definition update. See https://github.com/CircleCI-Public/aws-ecs-orb/issues/119
// "com.datadoghq.tags.version": "",
"com.datadoghq.ad.instances": JSON.stringify([
{ host: "%%host%%", port: defaultContainer.portMappings.length ? defaultContainer.ingressPort : null },
]),
"com.datadoghq.ad.check_names": JSON.stringify([serviceName]),
"com.datadoghq.ad.init_configs": JSON.stringify([{}]),
});But it's not ideal
Acknowledgements
- I may be able to implement this feature request
- This feature might incur a breaking change
CDK version used
2.135.0
Environment details (OS name and version, etc.)
MacOS Sonoma
