Skip to content

Commit

Permalink
build: trim trailing whitespace from dockerignore entries (#2733)
Browse files Browse the repository at this point in the history
fix(dockerignore): trim trailing whitespace

Signed-off-by: Clément Loiselet <[email protected]>
  • Loading branch information
kalioz authored Jul 29, 2022
1 parent 868e996 commit 3ee3a24
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions docker/utils/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ def __init__(self, pattern_str):
@classmethod
def normalize(cls, p):

# Remove trailing spaces
p = p.strip()

# Leading and trailing slashes are not relevant. Yes,
# "foo.py/" must exclude the "foo.py" regular file. "."
# components are not relevant either, even if the whole
Expand Down
9 changes: 9 additions & 0 deletions tests/integration/api_build_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ def test_build_with_dockerignore(self):
'ignored',
'Dockerfile',
'.dockerignore',
' ignored-with-spaces ', # check that spaces are trimmed
'!ignored/subdir/excepted-file',
'! ignored/subdir/excepted-with-spaces '
'', # empty line,
'#*', # comment line
]))
Expand All @@ -111,6 +113,9 @@ def test_build_with_dockerignore(self):
with open(os.path.join(base_dir, '#file.txt'), 'w') as f:
f.write('this file should not be ignored')

with open(os.path.join(base_dir, 'ignored-with-spaces'), 'w') as f:
f.write("this file should be ignored")

subdir = os.path.join(base_dir, 'ignored', 'subdir')
os.makedirs(subdir)
with open(os.path.join(subdir, 'file'), 'w') as f:
Expand All @@ -119,6 +124,9 @@ def test_build_with_dockerignore(self):
with open(os.path.join(subdir, 'excepted-file'), 'w') as f:
f.write("this file should not be ignored")

with open(os.path.join(subdir, 'excepted-with-spaces'), 'w') as f:
f.write("this file should not be ignored")

tag = 'docker-py-test-build-with-dockerignore'
stream = self.client.build(
path=base_dir,
Expand All @@ -136,6 +144,7 @@ def test_build_with_dockerignore(self):

assert sorted(list(filter(None, logs.split('\n')))) == sorted([
'/test/#file.txt',
'/test/ignored/subdir/excepted-with-spaces',
'/test/ignored/subdir/excepted-file',
'/test/not-ignored'
])
Expand Down

0 comments on commit 3ee3a24

Please sign in to comment.