-
Couldn't load subscription status.
- Fork 381
Addresses #268 : local builds should respect .gitignore #269
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
Changes from 1 commit
bc4d148
7d96e95
86a1f8e
a9a917f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |
| import io | ||
| import os | ||
| import re | ||
| import pathspec | ||
| import logging | ||
| import docker | ||
|
|
||
|
|
@@ -349,7 +350,21 @@ def _filter_tar(tar): | |
| src_path = os.path.join(os.path.dirname(__file__), *src_parts) | ||
| tar.add(src_path, src, filter=_filter_tar) | ||
|
|
||
| tar.add('.', 'src/', filter=_filter_tar) | ||
| _exclude_tar = None | ||
| if os.path.exists(".gitignore"): | ||
| gitignore_fh = open(".gitignore") | ||
| ignorespec = pathspec.PathSpec.from_lines('gitignore', gitignore_fh) | ||
|
|
||
| def _exclude_tar(filepath): | ||
| # Conditionally exclude files based on the pathspecs mentioned | ||
| # in the `.gitignore` file. | ||
| # Note that, the behaviour of this function is not **exactly** | ||
| # same to the way `git` excludes files based on `.gitignore`. | ||
| # | ||
| # https://github.com/cpburnz/python-path-specification/issues/19 | ||
| return ignorespec.match_file(filepath) | ||
|
||
|
|
||
| tar.add('.', 'src/', exclude=_exclude_tar, filter=_filter_tar) | ||
|
|
||
| tar.close() | ||
| tarf.seek(0) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you use a context manager here so that the file gets closed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typical docker builds use a separate
.dockerignoreand ignore.gitignore. Should we follow that pattern? I'd rather be as close to exact for whatdocker buildwould normally do as we can.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@betatim : sure, I will push in another commit with a bit of refactoring, and also the tests.
@minrk : Thats more of a usability question. If
repo2dockerwants to be transparent to the user then, adding a separate.dockerignoremight add to the confusion. You could add conditionals to check if both.dockerignoreand.gitignoreexist, and prioritize the.dockerignore, but if the repository just has a.gitignorethen you use that instead.