Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support multi-dir wildcards in .dockerignore #1430

Closed
Lothiraldan opened this issue Jan 31, 2017 · 1 comment
Closed

Support multi-dir wildcards in .dockerignore #1430

Lothiraldan opened this issue Jan 31, 2017 · 1 comment

Comments

@Lothiraldan
Copy link

Docker-py don't seems compliant with the multi-dir wildcard syntax in .dockerignore.

The corresponding docker issue is moby/moby#13113 and the PR is moby/moby#17090.

It's painful especially for Python projects because we need several level of simple wildcards to ignore .pyc files (see this comment: moby/moby#13113 (comment)).

I've pushed a git repository to reproduce the issue: https://github.com/Lothiraldan/docker-py-wildcarddir-bug

Building it with the official docker client outputs:

$> docker build . --no-cache=true
Sending build context to Docker daemon 6.144 kB
Step 1/3 : FROM ubuntu:14.04
 ---> 4a725d3b3b1c
Step 2/3 : ADD . /code/
 ---> 2a6f8cf084e5
Removing intermediate container c2045ceb345c
Step 3/3 : RUN ls -aRL /code/
 ---> Running in 2b46dc94d237
/code/:
.
..
.dockerignore
Dockerfile
file.py
package

/code/package:
.
..
__init__.py
module.py
sub_package

/code/package/sub_package:
.
..
__init__.py
 ---> 6168100e2dd3
Removing intermediate container 2b46dc94d237
Successfully built 6168100e2dd3

Building it with docker-py outputs (using unreleased master version):

$> python3 build.py
Step 1/3 : FROM ubuntu:14.04
 ---> 4a725d3b3b1c
Step 2/3 : ADD . /code/
 ---> 3a994700e607
Step 3/3 : RUN ls -aRL /code/
 ---> Running in ced581812281
/code/:
.
..
.dockerignore
Dockerfile
build.py
file.py
file.pyc
package

/code/package:
.
..
__init__.py
module.py
sub_package

/code/package/sub_package:
.
..
__init__.py
__init__.pyc
 ---> 0b2c00b86ab6
Successfully built 0b2c00b86ab6

It seems that the docker PR replaced the equivalent of match_path (

def match_path(path, pattern):
pattern = pattern.rstrip('/' + os.path.sep)
if pattern:
pattern = os.path.relpath(pattern)
pattern_components = pattern.split(os.path.sep)
path_components = path.split(os.path.sep)[:len(pattern_components)]
return fnmatch('/'.join(path_components), pattern)
) by a regex here https://github.com/docker/docker/pull/17090/files#diff-d293110531a98dc2d3a48d6f48226c51R122.

I don't know if there is a better option to support it in Python. I've also checked https://pypi.python.org/pypi/glob2/0.5 as it seems to support it but the double-wildcard support ** is made recursively at the directory walking level and not the path matching level.

Python version: 3.5.2
OS: Mac OS X 10.11.6
Docker-py: master (b3ea1fb)

I'm planning to take some times trying to do a PR for the support.

@shin-
Copy link
Contributor

shin- commented Jan 31, 2017

Hi!

This is a known limitation of our implementation that is on our TODO list. See the original report: #1117

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants