-
Notifications
You must be signed in to change notification settings - Fork 2k
feat(ecr): add lifecycle policy to clean up untagged images #6296
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
base: dev
Are you sure you want to change the base?
Conversation
|
+1 as workaround, following can be applied to sst.config.ts async run() {
new aws.ecr.LifecyclePolicy("sst-asset-lifecycle", {
repository: "sst-asset", //ECR name from SST bootstrap
policy: JSON.stringify({
"rules": [
{
"rulePriority": 1,
"description": "Expire untagged images pushed over 30 days ago",
"selection": {
"tagStatus": "untagged",
"countType": "sinceImagePushed",
"countUnit": "days",
"countNumber": 30
},
"action": {"type": "expire"}
}
]
}),
});
}, |
|
i'm wondering if this should be more explicit. something like: const vpc = new sst.aws.Vpc("MyVpc");
const cluster = new sst.aws.Cluster("MyCluster", { vpc });
new sst.aws.Service("MyService", {
cluster,
image: {
context: "./app",
dockerfile: "Dockerfile",
expiresIn: "30 days"
}
});what do you think? |
|
yes, this is much better. with enums like "x days", "on push", etc. |
|
exactly! @ekaya97 do any of you wanna give it a try? |
|
@vimtor I'll take care of it tonight! |
|
couple questions:
|
|
probably if we do it by service/task we should add a unique tag based on the component's name and create the lifecycle targeting it. maybe there's another way but that's the only one that comes to mind atm |
Hi everyone,
I ran into a semi-big issue while developing my ECS service. My containers are pretty heavy (multiple gigs) and I did a sanity check inside ECR to make see what kind of storage I am looking at.
Low and behold I noticed there are dozens of images that never get deleted.
This PR adds a lifecycle policy to ECR that expires untagged images, which as far as I can tell are what we can safely remove.
I do forsee a problem with rollbacks since SST uses the digest to attache the image to the task.
I am happy to take input on the exact lifecycle policy to use, I understand this is a pretty big change since it adds to the bootstrap. I tested it and its working:
My change will essentially gives 30 days of rollback time. We could also change the rule to at least keep x number of untagged images. Note: We can only target untagged images with one rule.
I do believe this is very important since ECR storage is pretty expensive at 0.10$ per GB Month.
cheers,
marv