File tree Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Original file line number Diff line number Diff line change 3
3
"""
4
4
from argparse import ArgumentParser
5
5
from datetime import timedelta
6
+ import re
6
7
7
8
from dateutil import parser
8
9
from docker import Client
@@ -40,6 +41,13 @@ def parse_args():
40
41
default = 3 ,
41
42
help = "Keep this many images of each kind" ,
42
43
)
44
+ parser .add_argument (
45
+ "--keep-regex" ,
46
+ type = str ,
47
+ nargs = '*' ,
48
+ default = list (),
49
+ help = "Python regex of tag names to keep." ,
50
+ )
43
51
parser .add_argument (
44
52
"--only" ,
45
53
"-o" ,
@@ -163,10 +171,17 @@ def clean_images(client, args):
163
171
# group by name
164
172
images_by_name = {}
165
173
for image in images :
174
+ if any (
175
+ any ([re .match (pattern , tag ) for pattern in args .keep_regex ])
176
+ for tag in image ["RepoTags" ]
177
+ ):
178
+ continue
179
+
166
180
for tag in image ["RepoTags" ]:
167
181
image_name = normalize_tag_name (tag )
168
182
if args .only and args .only != image_name :
169
183
continue
184
+
170
185
images_by_name .setdefault (image_name , set ()).add (image ["Id" ])
171
186
172
187
for image_name , image_ids in images_by_name .items ():
You can’t perform that action at this time.
0 commit comments