Skip to content

Commit 7a28ff3

Browse files
committed
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 <[email protected]>
1 parent 9b8e022 commit 7a28ff3

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

docker/api/build.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ def build(self, path=None, tag=None, quiet=False, fileobj=None,
143143
if os.path.exists(dockerignore):
144144
with open(dockerignore, 'r') as f:
145145
exclude = list(filter(
146-
bool, [l.strip() for l in f.read().splitlines()]
146+
lambda x: x != '' and x[0] != '#', [l.strip() for l in f.read().splitlines()]
147147
))
148148
context = utils.tar(
149149
path, exclude=exclude, dockerfile=dockerfile, gzip=gzip

tests/integration/api_build_test.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ def test_build_with_dockerignore(self):
6161
'Dockerfile',
6262
'.dockerignore',
6363
'!ignored/subdir/excepted-file',
64-
'', # empty line
64+
'', # empty line,
65+
'#', # comment line
6566
]))
6667

6768
with open(os.path.join(base_dir, 'not-ignored'), 'w') as f:

0 commit comments

Comments
 (0)