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

(aws-cdk-lib/aws-ecr): LifecycleRule not working properly (?) #28885

Closed
ValchanOficial opened this issue Jan 26, 2024 · 7 comments
Closed

(aws-cdk-lib/aws-ecr): LifecycleRule not working properly (?) #28885

ValchanOficial opened this issue Jan 26, 2024 · 7 comments
Labels
@aws-cdk/aws-ecr Related to Amazon Elastic Container Registry bug This issue is a bug. effort/medium Medium work item – several days of effort p2

Comments

@ValchanOficial
Copy link

ValchanOficial commented Jan 26, 2024

Describe the bug

maxImageAge is deleting all images, including images to be retained
I want to keep the latest 2 images from each tag and from each package
There is a way to say which package is when I create a new ecr.Repository?

Expected Behavior

keep images from maxImageCount

If I have 3 packages - Shoud be kept 2 images from each one - Total: 6
And so on

Current Behavior

All images are being deleted

Reproduction Steps

Code:

....
const lifecycleRules = [
  { tagPrefixList: ['alpha'],  maxImageCount: 2 }
  { tagPrefixList: ['beta'],  maxImageCount: 2 }
  { maxImageAge: Duration.days(30) } // when add this line, after 30 days, all images are deleted
]

const ecrExample = new ecr.Repository(scope, 'Example', {
  imageScanOnPush: true,
  imageTagMutability: ecr.TagMutability.IMMUTABLE,
  lifecycleRules,
  repositoryName: 'Example',
})
...

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

^2.93.0

Framework Version

No response

Node.js Version

18.16.0-alpine

OS

Linux

Language

TypeScript

Language Version

^5.1.6

Other information

It's a monorepo

@ValchanOficial ValchanOficial added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jan 26, 2024
@github-actions github-actions bot added the @aws-cdk/aws-ecr Related to Amazon Elastic Container Registry label Jan 26, 2024
@ayush-shah-1501
Copy link
Contributor

ayush-shah-1501 commented Jan 27, 2024

@ValchanOficial I don't think, it is an issue, if you give maxImageAge: 30 then it will delete all images after 30 days, please remove your rule { maxImageAge: Duration.days(30) }.

@ValchanOficial
Copy link
Author

@ValchanOficial I don't think, it is an issue, if you give maxImageAge: 30 then it will delete all images after 30 days, please remove your rule { maxImageAge: Duration.days(30) }.

But I don't want to keep old images, only the latest 2 images

@ayush-shah-1501
Copy link
Contributor

ayush-shah-1501 commented Jan 28, 2024

Your first two rules will contain only 2 latest images for each tags.
{ tagPrefixList: ['alpha'], maxImageCount: 2 }
{ tagPrefixList: ['beta'], maxImageCount: 2 }

you do not required
{ maxImageAge: Duration.days(30) } rule.

@pahud
Copy link
Contributor

pahud commented Jan 29, 2024

Thank you @ayush-shah-1501 for the feedback.

@pahud pahud added response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. p2 effort/medium Medium work item – several days of effort and removed needs-triage This issue or PR still needs to be triaged. labels Jan 29, 2024
@ValchanOficial
Copy link
Author

Your first two rules will contain only 2 latest images for each tags. { tagPrefixList: ['alpha'], maxImageCount: 2 } { tagPrefixList: ['beta'], maxImageCount: 2 }

you do not required { maxImageAge: Duration.days(30) } rule.

Thank you, I will try this

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Jan 29, 2024
@ValchanOficial
Copy link
Author

Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-ecr Related to Amazon Elastic Container Registry bug This issue is a bug. effort/medium Medium work item – several days of effort p2
Projects
None yet
Development

No branches or pull requests

3 participants