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

Add support for comments in .dockerignore #23111

Merged
merged 1 commit into from
Jun 3, 2016

Conversation

yongtang
Copy link
Member

- 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

@yongtang
Copy link
Member Author

cc @duglin @thaJeztah.

@LK4D4
Copy link
Contributor

LK4D4 commented May 31, 2016

Probably people will expect inline comments to work as well, but I'm not sure.

@vdemeester
Copy link
Member

@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, "#") {
Copy link
Member

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

Copy link
Contributor

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.

Copy link
Member Author

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.

@thaJeztah
Copy link
Member

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?

@thaJeztah thaJeztah added this to the 1.12.0 milestone May 31, 2016
@justincormack
Copy link
Contributor

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 #.

@thaJeztah
Copy link
Member

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;

A preprocessing step removes leading and trailing whitespace

So I'm a bit in doubt as to what the most sensible approach is

@justincormack
Copy link
Contributor

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
Copy link
Contributor

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.

Copy link
Member Author

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.

@yongtang yongtang force-pushed the 20083-dockerignore-comment branch from 33cfd76 to 1088c92 Compare May 31, 2016 14:18
@yongtang
Copy link
Member Author

Thanks @LK4D4 @vdemeester @duglin @thaJeztah @justincormack for the review. The pull request has been updated.

Now only lines starting with # (at position 1) are considered as comments and are ignored.

In addition, I updated the test by adding a couple of files with file name #1 and #2. This is to test the case of # in the middle of the line (which is not considered as comment and is not ignored therefore).

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(), "#") {
Copy link
Contributor

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?

Copy link
Member Author

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.

@yongtang yongtang force-pushed the 20083-dockerignore-comment branch from 1088c92 to 414d175 Compare May 31, 2016 15:01
@yongtang
Copy link
Member Author

yongtang commented Jun 1, 2016

The failure in windowsTP5 seems to be real. I would guess it is related to the (ls /tmp/#1) and Windows may not recognize #.

I don't have a setup in windowsTP5 locally yet. But I will try to do some investigation on this issue.

15:29:05 FAIL: docker_cli_build_test.go:6745: DockerSuite.TestBuildDockerignoreComment
15:29:05 
15:29:05 docker_cli_build_test.go:6774:
15:29:05     c.Fatal(err)
15:29:05 ... Error: failed to build the image: Sending build context to Docker daemon 5.632 kB

15:29:05 Step 1 : FROM busybox
15:29:05  ---> 70c337fe05f8
15:29:05 Step 2 : ADD . /tmp/
15:29:05  ---> b47bf1e14ad7
15:29:05 Removing intermediate container bf8b6e903af4
15:29:05 Step 3 : RUN sh -c "(! ls /tmp/foo) && (! ls /tmp/foo2) && (ls /tmp/dir1/foo) && (ls /tmp/#1) && (! ls /tmp/#2)"
15:29:05  ---> Running in 0277780112c5
15:29:05 ls: /tmp/foo2: No such file or directory
15:29:05 The command 'cmd /S /C sh -c "(! ls /tmp/foo) && (! ls /tmp/foo2) && (ls /tmp/dir1/foo) && (ls /tmp/#1) && (! ls /tmp/#2)"' returned a non-zero code: 255
15:29:05 
15:29:05 

@yongtang yongtang force-pushed the 20083-dockerignore-comment branch 6 times, most recently from 4e83bc2 to 162aecb Compare June 2, 2016 04:25
@yongtang yongtang force-pushed the 20083-dockerignore-comment branch 3 times, most recently from 1f60786 to babf71a Compare June 2, 2016 13:37
@yongtang
Copy link
Member Author

yongtang commented Jun 2, 2016

The issue in TP5 should have been fixed.

@duglin
Copy link
Contributor

duglin commented Jun 2, 2016

Where did janky go?

@thaJeztah
Copy link
Member

Took a day off, possibly Leeroy (@GordonTheTurtle) didn't get a call. I'll rebuild

@duglin
Copy link
Contributor

duglin commented Jun 2, 2016

LGTM if janky reappears and is ok.

@yongtang
Copy link
Member Author

yongtang commented Jun 2, 2016

Thanks @thaJeztah @duglin.

I also noticed that documentation always fails, not just for this PR but possibly for any PR related to documentation change:

#23192
#23195
#23107

And the documentation error always points to

ERROR: 2016/06/02 05:39:15 content_renderer.go:56: LinkResolver: No page found for "/docker-trusted-registry/overview.md" on page "registry/index.md".

I am not familiar with how Docker's Jenkins build for documentation works so not sure how to fix it.

@thaJeztah
Copy link
Member

@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>
@yongtang yongtang force-pushed the 20083-dockerignore-comment branch from babf71a to 8913dac Compare June 3, 2016 02:11
@yongtang
Copy link
Member Author

yongtang commented Jun 3, 2016

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.

@vdemeester
Copy link
Member

LGTM 🐮

@vdemeester
Copy link
Member

Moving to doc review /cc @thaJeztah

@thaJeztah
Copy link
Member

docs LGTM

gccgo timed out

@vdemeester
Copy link
Member

docs LGTM it is, merging 👼

@vdemeester vdemeester merged commit 9c1278b into moby:master Jun 3, 2016
@yongtang yongtang deleted the 20083-dockerignore-comment branch June 3, 2016 12:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

.dockerignore does not fully ignore comments
7 participants