Merge pull request #35 from scrapinghub/exclude-with-patterns
Add patterns support for exclude-image-file
This commit is contained in:
commit
c2a424c30c
|
@ -84,7 +84,13 @@ being removed.
|
||||||
Path to a file which contains a list of images to exclude, one
|
Path to a file which contains a list of images to exclude, one
|
||||||
image tag per line.
|
image tag per line.
|
||||||
|
|
||||||
|
You also can use basic pattern matching to exclude images with generic tags.
|
||||||
|
|
||||||
|
.. code::
|
||||||
|
|
||||||
|
user/repositoryA:*
|
||||||
|
user/repositoryB:?.?
|
||||||
|
user/repositoryC-*:tag
|
||||||
|
|
||||||
dcstop
|
dcstop
|
||||||
------
|
------
|
||||||
|
|
|
@ -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
|
||||||
|
|
||||||
|
@ -90,7 +91,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)
|
||||||
|
|
||||||
|
|
|
@ -178,6 +178,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