mirror of
https://github.com/moby/moby.git
synced 2025-08-01 05:47:11 +03:00
Add support for comment in .dockerignore
This fix tries to address the issue raised in #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 #20083. Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
This commit is contained in:
@ -6755,3 +6755,39 @@ func (s *DockerSuite) TestBuildDeleteCommittedFile(c *check.C) {
|
||||
c.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// #20083
|
||||
func (s *DockerSuite) TestBuildDockerignoreComment(c *check.C) {
|
||||
name := "testbuilddockerignorecleanpaths"
|
||||
dockerfile := `
|
||||
FROM busybox
|
||||
ADD . /tmp/
|
||||
RUN sh -c "(ls -la /tmp/#1)"
|
||||
RUN sh -c "(! ls -la /tmp/#2)"
|
||||
RUN sh -c "(! ls /tmp/foo) && (! ls /tmp/foo2) && (ls /tmp/dir1/foo)"`
|
||||
ctx, err := fakeContext(dockerfile, map[string]string{
|
||||
"foo": "foo",
|
||||
"foo2": "foo2",
|
||||
"dir1/foo": "foo in dir1",
|
||||
"#1": "# file 1",
|
||||
"#2": "# file 2",
|
||||
".dockerignore": `# Visual C++ cache files
|
||||
# because we have git ;-)
|
||||
# The above comment is from #20083
|
||||
foo
|
||||
#dir1/foo
|
||||
foo2
|
||||
# The following is considered as comment as # is at the beginning
|
||||
#1
|
||||
# The following is not considered as comment as # is not at the beginning
|
||||
#2
|
||||
`,
|
||||
})
|
||||
if err != nil {
|
||||
c.Fatal(err)
|
||||
}
|
||||
defer ctx.Close()
|
||||
if _, err := buildImageFromContext(name, ctx, true); err != nil {
|
||||
c.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user