File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed
Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change 66 type Tag ,
77 RepositoryNotFoundException ,
88 GetAuthorizationTokenCommand ,
9+ PutLifecyclePolicyCommand ,
910} from "@aws-sdk/client-ecr" ;
1011import { STSClient , AssumeRoleCommand } from "@aws-sdk/client-sts" ;
1112import { tryCatch } from "@trigger.dev/core" ;
@@ -234,6 +235,30 @@ async function createEcrRepository({
234235 throw new Error ( `Failed to create ECR repository: ${ repositoryName } ` ) ;
235236 }
236237
238+ // When the `cache` tag is mutated, the old cache images are untagged.
239+ // This policy matches those images and expires them to avoid bloating the repository.
240+ await ecr . send (
241+ new PutLifecyclePolicyCommand ( {
242+ repositoryName : result . repository . repositoryName ,
243+ registryId : result . repository . registryId ,
244+ lifecyclePolicyText : JSON . stringify ( {
245+ rules : [
246+ {
247+ rulePriority : 1 ,
248+ description : "Expire untagged images older than 3 days" ,
249+ selection : {
250+ tagStatus : "untagged" ,
251+ countType : "sinceImagePushed" ,
252+ countUnit : "days" ,
253+ countNumber : 3 ,
254+ } ,
255+ action : { type : "expire" } ,
256+ } ,
257+ ] ,
258+ } ) ,
259+ } )
260+ ) ;
261+
237262 return result . repository ;
238263}
239264
You can’t perform that action at this time.
0 commit comments