Skip to content

Commit b660f21

Browse files
committed
Merge pull request #6 from ava-dylang/preserved-images
Keep tag by regex
2 parents 48c40e8 + c172628 commit b660f21

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

dockerrotate/main.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"""
44
from argparse import ArgumentParser
55
from datetime import timedelta
6+
import re
67

78
from dateutil import parser
89
from docker import Client
@@ -40,6 +41,13 @@ def parse_args():
4041
default=3,
4142
help="Keep this many images of each kind",
4243
)
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+
)
4351
parser.add_argument(
4452
"--only",
4553
"-o",
@@ -163,10 +171,17 @@ def clean_images(client, args):
163171
# group by name
164172
images_by_name = {}
165173
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+
166180
for tag in image["RepoTags"]:
167181
image_name = normalize_tag_name(tag)
168182
if args.only and args.only != image_name:
169183
continue
184+
170185
images_by_name.setdefault(image_name, set()).add(image["Id"])
171186

172187
for image_name, image_ids in images_by_name.items():

0 commit comments

Comments
 (0)