Merge pull request #35 from scrapinghub/exclude-with-patterns

Add patterns support for exclude-image-file
This commit is contained in:
Kyle Anderson 2016-10-10 09:43:35 -07:00 committed by GitHub
commit c2a424c30c
3 changed files with 52 additions and 1 deletions

View File

@ -84,7 +84,13 @@ being removed.
Path to a file which contains a list of images to exclude, one
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
------

View File

@ -4,6 +4,7 @@ Remove old docker containers and images that are no longer in use.
"""
import argparse
import fnmatch
import logging
import sys
@ -90,7 +91,10 @@ def filter_excluded_images(images, exclude_set):
image_tags = image_summary.get('RepoTags')
if no_image_tags(image_tags):
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)

View File

@ -178,6 +178,47 @@ def test_filter_excluded_images():
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):
assert docker_gc.is_image_old(image, now)