-
Notifications
You must be signed in to change notification settings - Fork 18.6k
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
Add support for comments in .dockerignore #23111
Conversation
cc @duglin @thaJeztah. |
Probably people will expect inline comments to work as well, but I'm not sure. |
@LK4D4 yeah I guess, but git didn't support inline coment for a while, depending on the diffculty, I think having only lines comment is a good start. |
@@ -21,7 +21,8 @@ func ReadAll(reader io.ReadCloser) ([]string, error) { | |||
|
|||
for scanner.Scan() { | |||
pattern := strings.TrimSpace(scanner.Text()) | |||
if pattern == "" { | |||
// Blank lines or lines starting with # are ignored. | |||
if pattern == "" || strings.HasPrefix(pattern, "#") { |
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.
the strings.HasPrefix(
.. should be before we trim spaces, otherwise we're not consistent with the description;
# this is a comment
# this is now also considered a comment
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.
I'm ok with either. I always thought it was odd that Dockerfiles didn't support spaces before comments.
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.
Thanks @thaJeztah @duglin I updated the pull request. Now only lines starting with #
(at position 1) are considered as comments.
I'm fine with having just this as a start; Dockerfile's also only support comments if they start at position 1. Supporting inline comments doesn't look complicated if we accept that paths cannot contain pattern = strings.SplitN(pattern, "#", 2)[0] @vdemeester @LK4D4 wdyt? |
Supporting inline comments seems a bad thing for something as simple as this, let's just do the simplest thing and accept comments only if the first character is |
Ok, let's go with that option for now (as mentioned, it's also consistent with the Dockerfile syntax). Should we address #23111 (comment)? I'm a bit in doubt as it's inconsistent with the way Dockerfiles are parsed, although the documentation mentions;
So I'm a bit in doubt as to what the most sensible approach is |
I think the preprocessing step should only take place on non comment lines, so the description should be first comments are removed then the current processing takes place. |
# because we have git ;-) | ||
# The above comment is from #20083 | ||
./foo | ||
#dir1//foo |
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.
why the double / ?
Let's keep the test simple and just make it #dir1/foo
to make sure its really ignored.
And if you do end up supporting spaces before "#" then please include that in the test too.
And you should probably add one where "#" is in the middle of the line - to make sure we don't read it as a comment.
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.
Thanks @duglin. The pull request has been updated with simplified filename. Also two files starting with #
(one #1
and another #2
) have been added to test #
in the middle case.
33cfd76
to
1088c92
Compare
Thanks @LK4D4 @vdemeester @duglin @thaJeztah @justincormack for the review. The pull request has been updated. Now only lines starting with In addition, I updated the test by adding a couple of files with file name Please let me know if there are any issues. |
@@ -20,6 +20,10 @@ func ReadAll(reader io.ReadCloser) ([]string, error) { | |||
var excludes []string | |||
|
|||
for scanner.Scan() { | |||
// Lines starting with # (comments) are ignored before processing | |||
if strings.HasPrefix(scanner.Text(), "#") { |
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.
its a minor performance (stylistic) thing, but can you change this so that its:
pattern := scanner.Text()
if strings.HasPrefix(pattern, "#") { ... }
pattern = strings.TrimSpace(pattern)
So that we're not calling scanner.Text() more than once?
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.
Thanks @duglin the pull request has been updated.
1088c92
to
414d175
Compare
The failure in windowsTP5 seems to be real. I would guess it is related to the I don't have a setup in windowsTP5 locally yet. But I will try to do some investigation on this issue.
|
4e83bc2
to
162aecb
Compare
1f60786
to
babf71a
Compare
The issue in TP5 should have been fixed. |
Where did janky go? |
Took a day off, possibly Leeroy (@GordonTheTurtle) didn't get a call. I'll rebuild |
LGTM if janky reappears and is ok. |
Thanks @thaJeztah @duglin. I also noticed that documentation always fails, not just for this PR but possibly for any PR related to documentation change: And the documentation error always points to
I am not familiar with how Docker's Jenkins build for documentation works so not sure how to fix it. |
@yongtang yes, It looks like the CI settings changed and now fail instead of "warn" for some errors. That link error looks to be in another repository, so should probably be fixed in the "distribution" repository. |
This fix tries to address the issue raised in moby#20083 where comment is not supported in `.dockerignore`. This fix updated the processing of `.dockerignore` so that any lines starting with `#` are ignored, which is similiar to the behavior of `.gitignore`. Related documentation has been updated. Additional tests have been added to cover the changes. This fix fixes moby#20083. Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
babf71a
to
8913dac
Compare
Thanks @thaJeztah @duglin. The pull request has been rebased and the documentation issue seems to have been fixed. Please let me know if there are any other issues. |
LGTM 🐮 |
Moving to doc review /cc @thaJeztah |
docs LGTM gccgo timed out |
docs LGTM it is, merging 👼 |
- What I did
This fix tries to address the issue raised in #20083 where comment is not supported in
.dockerignore
.- How I did it
This fix updated the processing of
.dockerignore
so that any lines starting with#
are ignored, which is similiar to the behavior of.gitignore
.Related documentation has been updated.
- How to verify it
Additional tests have been added to cover the changes.
- Description for the changelog
Add support for comments (lines starting with
#
) in .dockerignore.- A picture of a cute animal (not mandatory but encouraged)
This fix fixes #20083.
Signed-off-by: Yong Tang yong.tang.github@outlook.com