-
Notifications
You must be signed in to change notification settings - Fork 380
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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It concerns me a bit that this isn't exact. Is there any possibility that we could end up excluding files that shouldn't be excluded, or does the bug you link exclusively mean that we will include some files we maybe shouldn't? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @minrk : In the issue I reported, and in most of the use cases, this will only mean we will forget to exclude some files which were meant to be excluded. The only use case when a file that is not meant to be excluded is excluded, is when But in the both these use cases, the |
||
|
||
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
.dockerignore
and ignore.gitignore
. Should we follow that pattern? I'd rather be as close to exact for whatdocker build
would 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
repo2docker
wants to be transparent to the user then, adding a separate.dockerignore
might add to the confusion. You could add conditionals to check if both.dockerignore
and.gitignore
exist, and prioritize the.dockerignore
, but if the repository just has a.gitignore
then you use that instead.