Skip to content

Commit 0ef4bb4

Browse files
authored
feat(cli): make ecr images immutable when created from cdk bootstrap (#19937)
As CDK creates images always with different name/tag, it can be ensured that those are not changed at the repository side. Changes default functionality without offering immutability setting [`AWS::ECR::Repository.ImageTagMutability`](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ecr-repository.html#cfn-ecr-repository-imagetagmutability) Fixes #18376 ---- ### All Submissions: * [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md) ### Adding new Unconventional Dependencies: * [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md/#adding-new-unconventional-dependencies) ### New Features * [x] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/master/INTEGRATION_TESTS.md)? * [x] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)? *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 734faa5 commit 0ef4bb4

File tree

4 files changed

+32
-6
lines changed

4 files changed

+32
-6
lines changed

packages/aws-cdk/README.md

+5-4
Original file line numberDiff line numberDiff line change
@@ -510,10 +510,11 @@ $ cdk destroy --app='node bin/main.js' MyStackName
510510

511511
### `cdk bootstrap`
512512

513-
Deploys a `CDKToolkit` CloudFormation stack into the specified environment(s), that provides an S3 bucket that
514-
`cdk deploy` will use to store synthesized templates and the related assets, before triggering a CloudFormation stack
515-
update. The name of the deployed stack can be configured using the `--toolkit-stack-name` argument. The S3 Bucket
516-
Public Access Block Configuration can be configured using the `--public-access-block-configuration` argument.
513+
Deploys a `CDKToolkit` CloudFormation stack into the specified environment(s), that provides an S3 bucket
514+
and ECR reposity that `cdk deploy` will use to store synthesized templates and the related assets, before
515+
triggering a CloudFormation stack update. The name of the deployed stack can be configured using the
516+
`--toolkit-stack-name` argument. The S3 Bucket Public Access Block Configuration can be configured using
517+
the `--public-access-block-configuration` argument. ECR uses immutable tags for images.
517518

518519
```console
519520
$ # Deploys to all environments

packages/aws-cdk/lib/api/bootstrap/bootstrap-template.yaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ Resources:
202202
ContainerAssetsRepository:
203203
Type: AWS::ECR::Repository
204204
Properties:
205+
ImageTagMutability: IMMUTABLE
205206
ImageScanningConfiguration:
206207
ScanOnPush: true
207208
RepositoryName:
@@ -509,7 +510,7 @@ Resources:
509510
Type: String
510511
Name:
511512
Fn::Sub: '/cdk-bootstrap/${Qualifier}/version'
512-
Value: '12'
513+
Value: '13'
513514
Outputs:
514515
BucketName:
515516
Description: The name of the S3 bucket owned by the CDK toolkit stack

packages/aws-cdk/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"lint": "cdk-lint",
1414
"pkglint": "pkglint -f",
1515
"test": "cdk-test",
16-
"integ": "jest --testMatch '**/?(*.)+(integ-test).js'",
16+
"integ": "jest --testMatch '**/?(*.)+(integtest).js'",
1717
"package": "cdk-package",
1818
"build+test+package": "yarn build+test && yarn package",
1919
"build+test": "yarn build && yarn test",

packages/aws-cdk/test/integ/cli/bootstrapping.integtest.ts

+24
Original file line numberDiff line numberDiff line change
@@ -252,3 +252,27 @@ integTest('can deploy modern-synthesized stack even if bootstrap stack name is u
252252
],
253253
});
254254
}));
255+
256+
integTest('create ECR with tag IMMUTABILITY to set on', withDefaultFixture(async (fixture) => {
257+
const bootstrapStackName = fixture.bootstrapStackName;
258+
259+
await fixture.cdkBootstrapModern({
260+
verbose: true,
261+
toolkitStackName: bootstrapStackName,
262+
});
263+
264+
const response = await fixture.aws.cloudFormation('describeStackResources', {
265+
StackName: bootstrapStackName,
266+
});
267+
const ecrResource = response.StackResources?.find(resource => resource.LogicalResourceId === 'ContainerAssetsRepository');
268+
expect(ecrResource).toBeDefined();
269+
270+
const ecrResponse = await fixture.aws.ecr('describeRepositories', {
271+
repositoryNames: [
272+
// This is set, as otherwise we don't end up here
273+
ecrResource?.PhysicalResourceId ?? '',
274+
],
275+
});
276+
277+
expect(ecrResponse.repositories?.[0].imageTagMutability).toEqual('IMMUTABLE');
278+
}));

0 commit comments

Comments
 (0)