Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion docker/api/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,9 @@ def build(self, path=None, tag=None, quiet=False, fileobj=None,
exclude = None
if os.path.exists(dockerignore):
with open(dockerignore, 'r') as f:
exclude = list(filter(bool, f.read().splitlines()))
exclude = list(filter(
bool, [l.strip() for l in f.read().splitlines()]
))
context = utils.tar(
path, exclude=exclude, dockerfile=dockerfile, gzip=gzip
)
Expand Down
22 changes: 22 additions & 0 deletions tests/integration/api_build_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,28 @@ def test_build_gzip_encoding(self):

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

def test_build_with_dockerfile_empty_lines(self):
base_dir = tempfile.mkdtemp()
self.addCleanup(shutil.rmtree, base_dir)
with open(os.path.join(base_dir, 'Dockerfile'), 'w') as f:
f.write('FROM busybox\n')
with open(os.path.join(base_dir, '.dockerignore'), 'w') as f:
f.write('\n'.join([
' ',
'',
'\t\t',
'\t ',
]))

stream = self.client.build(
path=base_dir, stream=True, decode=True, nocache=True
)

lines = []
for chunk in stream:
lines.append(chunk)
assert 'Successfully built' in lines[-1]['stream']

def test_build_gzip_custom_encoding(self):
with self.assertRaises(errors.DockerException):
self.client.build(path='.', gzip=True, encoding='text/html')