summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWanzhi Du <wanzhi09@gmail.com>2018-03-05 18:01:22 +0800
committerWanzhi Du <wanzhi09@gmail.com>2018-03-05 18:10:09 +0800
commit7a28ff351018eae9484451798c22db3c190547d0 (patch)
tree0edb12fd2096e408a5d306306158cb604f0e9b18
parent9b8e022fa1012cae381bb97823e30936877c57c3 (diff)
downloaddocker-py-7a28ff351018eae9484451798c22db3c190547d0.tar.gz
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>
-rw-r--r--docker/api/build.py2
-rw-r--r--tests/integration/api_build_test.py3
2 files changed, 3 insertions, 2 deletions
diff --git a/docker/api/build.py b/docker/api/build.py
index 56f1fcf..6dab14d 100644
--- a/docker/api/build.py
+++ b/docker/api/build.py
@@ -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
diff --git a/tests/integration/api_build_test.py b/tests/integration/api_build_test.py
index 4c2b992..a8c0279 100644
--- a/tests/integration/api_build_test.py
+++ b/tests/integration/api_build_test.py
@@ -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: