Skip to content

Commit 9c2b4e1

Browse files
committed
Use same split rules for Dockerfile as other include/exclude patterns
Signed-off-by: Joffrey F <[email protected]>
1 parent 4c263ee commit 9c2b4e1

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

docker/utils/build.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,21 @@ def exclude_paths(root, patterns, dockerfile=None):
3131
if dockerfile is None:
3232
dockerfile = 'Dockerfile'
3333

34+
def split_path(p):
35+
return [pt for pt in re.split(_SEP, p) if pt and pt != '.']
36+
3437
def normalize(p):
3538
# Leading and trailing slashes are not relevant. Yes,
3639
# "foo.py/" must exclude the "foo.py" regular file. "."
3740
# components are not relevant either, even if the whole
3841
# pattern is only ".", as the Docker reference states: "For
3942
# historical reasons, the pattern . is ignored."
40-
split = [pt for pt in re.split(_SEP, p) if pt and pt != '.']
4143
# ".." component must be cleared with the potential previous
4244
# component, regardless of whether it exists: "A preprocessing
4345
# step [...] eliminates . and .. elements using Go's
4446
# filepath.".
4547
i = 0
48+
split = split_path(p)
4649
while i < len(split):
4750
if split[i] == '..':
4851
del split[i]
@@ -62,7 +65,7 @@ def normalize(p):
6265
# Exclude empty patterns such as "." or the empty string.
6366
filter(lambda p: p[1], patterns),
6467
# Always include the Dockerfile and .dockerignore
65-
[(True, dockerfile.split('/')), (True, ['.dockerignore'])]))))
68+
[(True, split_path(dockerfile)), (True, ['.dockerignore'])]))))
6669
return set(walk(root, patterns))
6770

6871

tests/unit/utils_test.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -698,6 +698,11 @@ def test_exclude_custom_dockerfile(self):
698698
['*'], dockerfile='foo/Dockerfile3'
699699
) == convert_paths(set(['foo/Dockerfile3', '.dockerignore']))
700700

701+
# https://github.com/docker/docker-py/issues/1956
702+
assert self.exclude(
703+
['*'], dockerfile='./foo/Dockerfile3'
704+
) == convert_paths(set(['foo/Dockerfile3', '.dockerignore']))
705+
701706
def test_exclude_dockerfile_child(self):
702707
includes = self.exclude(['foo/'], dockerfile='foo/Dockerfile3')
703708
assert convert_path('foo/Dockerfile3') in includes

0 commit comments

Comments
 (0)