Skip to content

Commit bf5e770

Browse files
authored
Merge pull request #1853 from docker/1852-dockerignore
Ignore dockerignore lines that contain only whitespace
2 parents 190d95c + bf06a36 commit bf5e770

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

docker/api/build.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,9 @@ def build(self, path=None, tag=None, quiet=False, fileobj=None,
145145
exclude = None
146146
if os.path.exists(dockerignore):
147147
with open(dockerignore, 'r') as f:
148-
exclude = list(filter(bool, f.read().splitlines()))
148+
exclude = list(filter(
149+
bool, [l.strip() for l in f.read().splitlines()]
150+
))
149151
context = utils.tar(
150152
path, exclude=exclude, dockerfile=dockerfile, gzip=gzip
151153
)

tests/integration/api_build_test.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,28 @@ def test_build_gzip_encoding(self):
352352

353353
assert 'Successfully built' in lines[-1]['stream']
354354

355+
def test_build_with_dockerfile_empty_lines(self):
356+
base_dir = tempfile.mkdtemp()
357+
self.addCleanup(shutil.rmtree, base_dir)
358+
with open(os.path.join(base_dir, 'Dockerfile'), 'w') as f:
359+
f.write('FROM busybox\n')
360+
with open(os.path.join(base_dir, '.dockerignore'), 'w') as f:
361+
f.write('\n'.join([
362+
' ',
363+
'',
364+
'\t\t',
365+
'\t ',
366+
]))
367+
368+
stream = self.client.build(
369+
path=base_dir, stream=True, decode=True, nocache=True
370+
)
371+
372+
lines = []
373+
for chunk in stream:
374+
lines.append(chunk)
375+
assert 'Successfully built' in lines[-1]['stream']
376+
355377
def test_build_gzip_custom_encoding(self):
356378
with self.assertRaises(errors.DockerException):
357379
self.client.build(path='.', gzip=True, encoding='text/html')

0 commit comments

Comments
 (0)