-
Notifications
You must be signed in to change notification settings - Fork 289
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
include/exclude directives can lead to directories that are not writable at build time #1419
Comments
First off, I agree that this is unintentional and thereby a bug. I do wonder if an alternative solution could be to update the filtering function to not filter out directories that contain files that would ultimately be included. It looks like we inherit some gitignore functionality from a library so it may not be as trivial as I make it sound but it may be worth exploring. The main benefit being that there's no post-processing necessary. |
I'd like to work on this if nobody else isn't.
I wanted to confirm if this is how the bug is triggered for For the # If include contains
include = ["testdir/abc/testfile", "dir2/file.txt"]
# Get parent dirs
parent_dirs = ["testdir", "abc", "dir2"]
# Add their respective gitignore entries to `fileFilter` I can start working on the |
@imnitishng It makes sense that your example of For So in pseudo terms it should really be more like this: # If include contains
include = ["testdir/abc/testfile", "dir2/file.txt"]
# Get parent dirs
parent_dirs = [
"./testdir/",
"./testdir/abc/",
"./dir2/",
] Let me know if you agree or if I'm missing something. |
Yea, the example I provided was quite vague, but I had the same idea in my mind. I will start working on this and create a draft PR for |
Hey @jromero, sure, something like:
should work though I can't test it right now |
@BenjaminSchubert ah, that's an interesting edge case. I feel conflicted by it. Is it considered a misconfiguration given that the nested file obviously needs the parent directories? Some options that come to mind:
I'm currently leaning towards 1) because the added complexity doesn't feel justified. If the intent of the user is to exclude everything in the Reference: https://stackoverflow.com/a/29932318 |
@jromero sorry for the delay in responding.
and that does work (well, technically git doesn't really care about directories at all). So if we wanted to consider it a misconfiguration, we should document and catch this case as the build goes, with a nice error message instead. I don't think "just letting it go through" is a nice user experience. I would more lean towards 2, or a potential number 4, which would be:
|
And I was wrong. I've played more with git, and it does look like
does ignore Which means, it's handled however incorrectly in pack... as it does add the file. At that point, I think an error with message might be the best bet |
When building an application using pack and specifying include and/or exclude, the permissions are not set correctly in some cases, and some directories might end up owned by root, which, in some cases, makes the build fail.
This is due to how docker works and can be reproduced by using docker solely.
I will focus on the
include
part of the equation here, but it is possible to trigger the same bug withexclude
.Reproduction using pack
Setup
In a directory, create a project:
This technically means that
testdir
is ignored, and will not be copied, however, you wanttestdir/testfile
, and thus, something will have to createthis
testdir
, to keep your hierarchy.Triggering the bug
Now, running
pack build --builder ${WHATEVER_BUILDER:paketobuildpacks/builder:tiny} test
, you will see the following:What did I expect?
testdir should be owned by
cnb:cnb
Triggering using Docker
This is not solely a problem with pack, it is rather how
docker cp
works.Again, using an empty directory, we can do:
Alternatives
In order not to hit this problem, this is what needs to be done:
This is error prone, hard to debug when it goes wrong, and ultimately not intuitive for users.
Fixing it
I am happy to provide a fix if we agree that this is a bug. However, I am not sure what is the best way of achieving this so I would need a bit of guidance.
My current idea would be to modify WriteDirToTar, and the corresponding entry for zip, to walk the path a first time, gather a list of everything needing copying, and then go over it a second time, inserting missing directories as needed.
Does that sound sound? A better way I would be missing?
Thanks!
The text was updated successfully, but these errors were encountered: