21
21
]
22
22
project = "gcr.io/o1labs-192920"
23
23
github_repo = "minaProtocol/mina"
24
+ batch_size = 10
25
+
24
26
25
27
def str2bool (v ):
26
28
if isinstance (v , bool ):
@@ -47,16 +49,19 @@ def str2bool(v):
47
49
commits_to_skip = list (map (lambda x : x .commit .sha [0 :7 ], repo .get_tags ()))
48
50
49
51
50
- def delete_image (tag ,dryrun ,reason ):
51
- image_prefix = tag ["digest" ][:15 ]
52
+ def delete_images (tags ,dryrun ,gcr_repository ,reason ):
52
53
if dryrun :
53
- print (f'[DRYRUN]: { gcr_repository } : deleting { image_prefix } because { reason } ' )
54
+ for tag in tags :
55
+ image_prefix = tag [:15 ]
56
+ print (f'[DRYRUN]: { gcr_repository } : deleting { image_prefix } because { reason } ' )
54
57
else :
55
- id = f'{ gcr_repository } @{ tag ["digest" ]} '
56
- print (f'{ gcr_repository } : deleting { image_prefix } because ${ reason } ' )
57
- cmd = ["gcloud" , "container" , "images" , "delete" , id ,"--quiet" , "--force-delete-tags" ]
58
- subprocess .run (cmd )
59
-
58
+ command = ["gcloud" , "container" , "images" , "delete" ]
59
+ for tag in tags :
60
+ image_prefix = tag [:15 ]
61
+ print (f'{ gcr_repository } : deleting { image_prefix } because { reason } ' )
62
+ command .append (f'{ gcr_repository } @{ tag } ' )
63
+ command .extend (["--quiet" , "--force-delete-tags" ])
64
+ subprocess .run (command )
60
65
61
66
for gcr_repository in gcr_repositories :
62
67
print (f"Cleaning { gcr_repository } repository... it may take a while" )
@@ -66,19 +71,28 @@ def delete_image(tag,dryrun,reason):
66
71
67
72
threshold = datetime .now ().date () - timedelta (days = args .age )
68
73
deleted = 0
74
+ to_be_deleted = []
69
75
for tag in tags :
70
76
github_tags = tag ["tags" ]
71
77
if not any (any (commit_to_skip in x for x in github_tags ) for commit_to_skip in commits_to_skip ):
72
78
timestamp = tag ["timestamp" ]
73
79
if timestamp is None :
74
- delete_image (tag ,args .dryrun ,f"image doesn't have timestamp property (which means it's very old) and not tagged with version" )
75
- deleted += 1
80
+ to_be_deleted .append (tag ["digest" ])
76
81
else :
77
82
date = datetime .strptime (timestamp ["datetime" ],"%Y-%m-%d %H:%M:%S%z" )
78
83
if date .date () < threshold :
79
- delete_image (tag ,args .dryrun ,f"is older than { args .age } days and not tagged with version" )
80
- deleted += 1
84
+ to_be_deleted .append (tag ["digest" ])
81
85
86
+ if len (to_be_deleted ) > batch_size :
87
+ delete_images (to_be_deleted ,args .dryrun ,gcr_repository ,f"is older than { args .age } days and not tagged with version" )
88
+ deleted += len (to_be_deleted )
89
+ to_be_deleted = []
90
+
91
+ if len (to_be_deleted ) > 0 :
92
+ delete_images (to_be_deleted ,args .dryrun ,gcr_repository ,f"is older than { args .age } days and not tagged with version" )
93
+ deleted += len (to_be_deleted )
94
+ to_be_deleted = []
95
+
82
96
total = len (tags )
83
97
84
98
suffix = "will be deleted in standard run" if args .dryrun else "deleted"
0 commit comments