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

chore(app-staging-synthesizer): tool to test maximum ecr repository allowance #26173

Merged
merged 5 commits into from
Jul 3, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
2 changes: 1 addition & 1 deletion packages/@aws-cdk/app-staging-synthesizer-alpha/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -339,5 +339,5 @@ Since this module is experimental, there are some known limitations:
bootstrap stack, the staging resources in them will just go unused. You can customize the
template to remove them if desired.
- Due to limitations on the CloudFormation template size, CDK Applications can have
at most 38 independent ECR images. Please upvote [this issue](https://github.com/aws/aws-cdk/issues/26119)
at most 21 independent ECR images. Please upvote [this issue](https://github.com/aws/aws-cdk/issues/26119)
if you need more than this.
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ export class DefaultStagingStack extends Stack implements IStagingResources {
this.stagingRepos[asset.assetName] = new ecr.Repository(this, repoName, {
repositoryName: repoName,
lifecycleRules: [{
description: 'Garbage collect old image versions and keep the specified number of latest versions',
description: 'Garbage collect old image versions',
maxImageCount: this.props.imageAssetVersionCount ?? 3,
}],
...(this.autoDeleteStagingAssets ? {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Run this file as a script ("node check-max-repos.js") to test
* how many ECR repositories are allowed in the template before the
* template size exceeds 51200 bytes.
*/

import * as fs from 'fs';
import * as path from 'path';
import { APP_ID_MAX, testWithXRepos } from './util';

checkMaxRepos();

function checkMaxRepos(): number {
let copies = 1;
let templateSize = 0;
const cloudAssembly = path.join(__dirname, '..', 'cdk.out');

while (testWithXRepos(copies)) {
// find template size in cdk.out
templateSize = fs.statSync(path.join(cloudAssembly, `StagingStack-${APP_ID_MAX}-ACCOUNT-REGION.template.json`)).size;

// the integ test includes 1 other ECR repository
// eslint-disable-next-line no-console
console.log(`repos: ${copies + 1}, size: ${templateSize} bytes`);

copies += 1;
}

// clean up
process.env.IMAGE_COPIES = undefined;
fs.rmSync(cloudAssembly, { recursive: true, force: true });
return copies;
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
import { App } from 'aws-cdk-lib';
import { testWithXRepos } from './util';
import { DefaultStagingStack } from '../lib';

describe('default staging stack', () => {
test('can have at least 21 ECR Repositories', () => {
// Decreasing this number is a breaking change! We have committed
// to supporting 21 ECR repositories in the template. We can only
// increase this commitment, not decrease it.
expect(testWithXRepos(21)).toBeTruthy();
});

describe('appId fails', () => {
test('when appId > 20 characters', () => {
const app = new App();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"Fn::Join": [
"",
[
"cdk-default-resources-file-role-",
"cdk-default-resourcesmax-file-role-",
{
"Ref": "AWS::Region"
}
Expand Down Expand Up @@ -188,7 +188,7 @@
"BucketKeyAlias69A0886F": {
"Type": "AWS::KMS::Alias",
"Properties": {
"AliasName": "alias/cdk-default-resources-staging",
"AliasName": "alias/cdk-default-resourcesmax-staging",
"TargetKeyId": {
"Fn::GetAtt": [
"BucketKey7092080A",
Expand Down Expand Up @@ -219,7 +219,7 @@
"Fn::Join": [
"",
[
"cdk-default-resources-staging-",
"cdk-default-resourcesmax-staging-",
{
"Ref": "AWS::AccountId"
},
Expand Down Expand Up @@ -506,7 +506,7 @@
"Fn::Join": [
"",
[
"cdk-default-resources-image-role-",
"cdk-default-resourcesmax-image-role-",
{
"Ref": "AWS::Region"
}
Expand Down Expand Up @@ -536,13 +536,13 @@
"Resource": [
{
"Fn::GetAtt": [
"defaultresourcesecrasset2FBE6B8A9",
"defaultresourcesmaxecrasset13112F7F9",
"Arn"
]
},
{
"Fn::GetAtt": [
"defaultresourcesecrasset9191BD6E",
"defaultresourcesmaxecrasset2904B88A7",
"Arn"
]
}
Expand All @@ -564,13 +564,13 @@
]
}
},
"defaultresourcesecrasset9191BD6E": {
"defaultresourcesmaxecrasset13112F7F9": {
"Type": "AWS::ECR::Repository",
"Properties": {
"LifecyclePolicy": {
"LifecyclePolicyText": "{\"rules\":[{\"rulePriority\":1,\"description\":\"Garbage collect old image versions and keep the specified number of latest versions\",\"selection\":{\"tagStatus\":\"any\",\"countType\":\"imageCountMoreThan\",\"countNumber\":3},\"action\":{\"type\":\"expire\"}}]}"
"LifecyclePolicyText": "{\"rules\":[{\"rulePriority\":1,\"description\":\"Garbage collect old image versions\",\"selection\":{\"tagStatus\":\"any\",\"countType\":\"imageCountMoreThan\",\"countNumber\":3},\"action\":{\"type\":\"expire\"}}]}"
},
"RepositoryName": "default-resources/ecr-asset",
"RepositoryName": "default-resourcesmax/ecr-asset/1",
"Tags": [
{
"Key": "aws-cdk:auto-delete-images",
Expand All @@ -581,7 +581,7 @@
"UpdateReplacePolicy": "Delete",
"DeletionPolicy": "Delete"
},
"defaultresourcesecrassetAutoDeleteImagesCustomResource7AB58D8F": {
"defaultresourcesmaxecrasset1AutoDeleteImagesCustomResource0FD7F0F5": {
"Type": "Custom::ECRAutoDeleteImages",
"Properties": {
"ServiceToken": {
Expand All @@ -591,11 +591,11 @@
]
},
"RepositoryName": {
"Ref": "defaultresourcesecrasset9191BD6E"
"Ref": "defaultresourcesmaxecrasset13112F7F9"
}
},
"DependsOn": [
"defaultresourcesecrasset9191BD6E"
"defaultresourcesmaxecrasset13112F7F9"
],
"UpdateReplacePolicy": "Delete",
"DeletionPolicy": "Delete"
Expand Down Expand Up @@ -637,13 +637,13 @@
"Resource": [
{
"Fn::GetAtt": [
"defaultresourcesecrasset9191BD6E",
"defaultresourcesmaxecrasset13112F7F9",
"Arn"
]
},
{
"Fn::GetAtt": [
"defaultresourcesecrasset2FBE6B8A9",
"defaultresourcesmaxecrasset2904B88A7",
"Arn"
]
}
Expand Down Expand Up @@ -677,13 +677,13 @@
"CustomECRAutoDeleteImagesCustomResourceProviderRole665F2773"
]
},
"defaultresourcesecrasset2FBE6B8A9": {
"defaultresourcesmaxecrasset2904B88A7": {
"Type": "AWS::ECR::Repository",
"Properties": {
"LifecyclePolicy": {
"LifecyclePolicyText": "{\"rules\":[{\"rulePriority\":1,\"description\":\"Garbage collect old image versions and keep the specified number of latest versions\",\"selection\":{\"tagStatus\":\"any\",\"countType\":\"imageCountMoreThan\",\"countNumber\":3},\"action\":{\"type\":\"expire\"}}]}"
"LifecyclePolicyText": "{\"rules\":[{\"rulePriority\":1,\"description\":\"Garbage collect old image versions\",\"selection\":{\"tagStatus\":\"any\",\"countType\":\"imageCountMoreThan\",\"countNumber\":3},\"action\":{\"type\":\"expire\"}}]}"
},
"RepositoryName": "default-resources/ecr-asset-2",
"RepositoryName": "default-resourcesmax/ecr-asset-2",
"Tags": [
{
"Key": "aws-cdk:auto-delete-images",
Expand All @@ -694,7 +694,7 @@
"UpdateReplacePolicy": "Delete",
"DeletionPolicy": "Delete"
},
"defaultresourcesecrasset2AutoDeleteImagesCustomResource1272F059": {
"defaultresourcesmaxecrasset2AutoDeleteImagesCustomResource708714C1": {
"Type": "Custom::ECRAutoDeleteImages",
"Properties": {
"ServiceToken": {
Expand All @@ -704,11 +704,11 @@
]
},
"RepositoryName": {
"Ref": "defaultresourcesecrasset2FBE6B8A9"
"Ref": "defaultresourcesmaxecrasset2904B88A7"
}
},
"DependsOn": [
"defaultresourcesecrasset2FBE6B8A9"
"defaultresourcesmaxecrasset2904B88A7"
],
"UpdateReplacePolicy": "Delete",
"DeletionPolicy": "Delete"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"integ-tests/DefaultTest": {
"stacks": [
"synthesize-default-resources",
"StagingStack-default-resources-ACCOUNT-REGION"
"StagingStack-default-resourcesmax-ACCOUNT-REGION"
],
"assertionStack": "integ-tests/DefaultTest/DeployAssert",
"assertionStackName": "integtestsDefaultTestDeployAssert44C8D370"
Expand Down
Loading