Open blimmer opened 2 years ago
Is it possible to change dockerTagPrefix after the stack instance is created? The use case is: Our stack will create two container images (one for arm64, the other for x86_64). However, we can't find a suitable ECR lifecycle policy to guarantee that the latest version of both images will be retained if they share the same prefix. So, it will be useful if the dockerTagPrefix can be changed (maybe by a dedicated method?) after the stack instance is created. For example:
constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps = {}) {
// init the stack instance with prefix 'arm64-'
super(scope, id, {
synthesizer: new DefaultStackSynthesizer({
dockerTagPrefix: `arm64-`
}),
...props,
});
//Some logic to create the arm64 image. The image uploaded to ECR should have prefix 'arm64-'
...
//Change the dockerTagPrefix to 'x86-' with dedicated method, say, updateDockerTagPrefix
updateDockerTagPrefix('x86-');
//Some logic to create the x86 image. The image uploaded to ECR should have prefix 'x86-'
...
}
Agree, the prefix must be on a container image basis, not on the stack. An alternative would be to add the prefix
const container = taskDefinition.addContainer(containerName, {
containerName: containerName,
image: ecs.ContainerImage.fromAsset("../", {
dockerTagPrefix: containerName
file: "server.dockerfile",
buildArgs: { }
}),
Related: #9628
Description
Today, when assets like Docker Images and Files are produced, the filename is a hash of the file contents. The hash behavior is great because it allows CloudFormation to skip re-uploading assets when the changes are "no-op"s. However, these assets are not very human-friendly because they're not identifiable in any way.
Use Case
Ther are a few distinct use-cases I can think of:
gc
in the future: https://github.com/aws/aws-cdk-rfcs/issues/64.c83185b9d9d867148abd3f2c7c1f2d8aa3f39effb705b56ae99d114e015bf729.py
today. By just looking at this, I have no idea what it could be. However, if the Stack ID was prepended, I would automatically have a better idea of what that file isMyStackId-c83185b9d9d867148abd3f2c7c1f2d8aa3f39effb705b56ae99d114e015bf729.py
Proposed Solution
Currently, there are two properties exposed by the
DefaultStackSynthesizer
that make this change fairly straightforward,bucketPrefix
anddockerTagPrefix
https://github.com/aws/aws-cdk/blob/534babde886646b6cd01f8799e3b4ed6db221263/packages/%40aws-cdk/core/lib/stack-synthesizers/default-synthesizer.ts#L168-L183The defaults are currently blank strings https://github.com/aws/aws-cdk/blob/534babde886646b6cd01f8799e3b4ed6db221263/packages/%40aws-cdk/core/lib/stack-synthesizers/default-synthesizer.ts#L250-L257
I propose that, instead of blank strings, we use the stack name and some separator (e.g.,
-
or_
) as the default prefix for Docker Images and File assets.You can get this behavior today by overriding these values like so
but I think there's an argument to make this the default in CDK.
Other information
There are a number of other issues that relate to this idea:
Though this wouldn't solve these issues directly, it could make it easier to implement these types of improvements in the future.
Acknowledge