Last active
November 15, 2024 09:58
-
-
Save xiaket/b16623765e11a657cbe52b61f1aeda8d to your computer and use it in GitHub Desktop.
ECR Lifecycle Policy example with explanations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"rules": [ | |
{ | |
"rulePriority": 10, | |
"description": "For `latest` tag, keep last 5 images", | |
"selection": { | |
"tagStatus": "tagged", | |
"tagPrefixList": ["latest"], | |
"countType": "imageCountMoreThan", | |
"countNumber": 5 | |
}, | |
"action": { "type": "expire" } | |
}, | |
{ | |
"rulePriority": 20, | |
"description": "For `master` tag, keep last 5 images", | |
"selection": { | |
"tagStatus": "tagged", | |
"tagPrefixList": ["master"], | |
"countType": "imageCountMoreThan", | |
"countNumber": 5 | |
}, | |
"action": { "type": "expire" } | |
}, | |
{ | |
"rulePriority": 990, | |
"description": "Only keep untagged images for 7 days", | |
"selection": { | |
"tagStatus": "untagged", | |
"countType": "sinceImagePushed", | |
"countUnit": "days", | |
"countNumber": 7 | |
}, | |
"action": { "type": "expire" } | |
}, | |
{ | |
"rulePriority": 1000, | |
"description": "Only keep tagged images for 15 days", | |
"selection": { | |
"tagStatus": "any", | |
"countType": "sinceImagePushed", | |
"countUnit": "days", | |
"countNumber": 15 | |
}, | |
"action": { "type": "expire" } | |
} | |
] | |
} |
all other images are those who have a tag, but not the protected ones, we should remove them if it's more than 15 days old.
What do you mean under protected ones? Which images are protected and by whom?
What do you mean under protected ones? Which images are protected and by whom?
The protected ones are those listed in 1 and 2.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
As of today(10th Aug, 2018), the life cycle policy in ECR is flawed:
imageCountMoreThan
andsinceImagePushed
to the same set of tags.tagPrefixList
is not really what most people expect it to be. See this gist for example.keep
action, currently it'sexpire
only.What I have gathered here is as close to what I had wished to achieve as possible:
Please note that you don't want to change that criteria in 1 to a
sinceImagePushed
based one, because if you image stay stale for some time, the image will get removed.A note on rule evaluation, according to the documentation, AWS will look at 1 first(priority 10 and 20), retain all the newest images under those tags, and mark all other images under those tags as expired. Then, it will look at 2(priority 990 here), find all untagged images, and mark old ones as expired. Last but not the least, it will look at 3(priority 1000 here), looking at all other images. At this stage, since we had matched those tags in 1 and those untagged ones in 2, all other images are those who have a tag, but not the protected ones, we should remove them if it's more than 15 days old.