Add patterns support for exclude-image-file
This commit is contained in:
parent
2375af1513
commit
cd4121cb59
|
@ -4,6 +4,7 @@ Remove old docker containers and images that are no longer in use.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
import argparse
|
import argparse
|
||||||
|
import fnmatch
|
||||||
import logging
|
import logging
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
@ -88,7 +89,10 @@ def filter_excluded_images(images, exclude_set):
|
||||||
image_tags = image_summary.get('RepoTags')
|
image_tags = image_summary.get('RepoTags')
|
||||||
if no_image_tags(image_tags):
|
if no_image_tags(image_tags):
|
||||||
return True
|
return True
|
||||||
return not set(image_tags) & exclude_set
|
for exclude_pattern in exclude_set:
|
||||||
|
if fnmatch.filter(image_tags, exclude_pattern):
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
return filter(include_image, images)
|
return filter(include_image, images)
|
||||||
|
|
||||||
|
|
|
@ -177,6 +177,47 @@ def test_filter_excluded_images():
|
||||||
assert list(actual) == expected
|
assert list(actual) == expected
|
||||||
|
|
||||||
|
|
||||||
|
def test_filter_excluded_images_advanced():
|
||||||
|
exclude_set = set([
|
||||||
|
'user/one:*',
|
||||||
|
'user/foo:tag*',
|
||||||
|
'user/repo-*:tag',
|
||||||
|
])
|
||||||
|
images = [
|
||||||
|
{
|
||||||
|
'RepoTags': ['<none>:<none>'],
|
||||||
|
'Id': 'babababababaabababab'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'RepoTags': ['user/one:latest', 'user/one:abcd']
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'RepoTags': ['user/foo:test']
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'RepoTags': ['user/foo:tag123']
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'RepoTags': ['user/repo-1:tag']
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'RepoTags': ['user/repo-2:tag']
|
||||||
|
},
|
||||||
|
|
||||||
|
]
|
||||||
|
expected = [
|
||||||
|
{
|
||||||
|
'RepoTags': ['<none>:<none>'],
|
||||||
|
'Id': 'babababababaabababab'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'RepoTags': ['user/foo:test'],
|
||||||
|
},
|
||||||
|
]
|
||||||
|
actual = docker_gc.filter_excluded_images(images, exclude_set)
|
||||||
|
assert list(actual) == expected
|
||||||
|
|
||||||
|
|
||||||
def test_is_image_old(image, now):
|
def test_is_image_old(image, now):
|
||||||
assert docker_gc.is_image_old(image, now)
|
assert docker_gc.is_image_old(image, now)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue