Ignore comment line from the .dockerignore file

This fixed the bug that test comment line in .dockerignore file as ignore rule
bug.

Add test for "# comment" patterns in .dockerignore.

Signed-off-by: Wanzhi Du <wanzhi09@gmail.com>
This commit is contained in:
Wanzhi Du 2018-03-05 18:01:22 +08:00
parent 9b8e022fa1
commit 7a28ff3510
2 changed files with 3 additions and 2 deletions

View File

@ -143,7 +143,7 @@ class BuildApiMixin(object):
if os.path.exists(dockerignore):
with open(dockerignore, 'r') as f:
exclude = list(filter(
bool, [l.strip() for l in f.read().splitlines()]
lambda x: x != '' and x[0] != '#', [l.strip() for l in f.read().splitlines()]
))
context = utils.tar(
path, exclude=exclude, dockerfile=dockerfile, gzip=gzip

View File

@ -61,7 +61,8 @@ class BuildTest(BaseAPIIntegrationTest):
'Dockerfile',
'.dockerignore',
'!ignored/subdir/excepted-file',
'', # empty line
'', # empty line,
'#', # comment line
]))
with open(os.path.join(base_dir, 'not-ignored'), 'w') as f: