mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #23111 from yongtang/20083-dockerignore-comment
Add support for comments in .dockerignore
This commit is contained in:
commit
9c1278b279
3 changed files with 47 additions and 1 deletions
|
@ -20,7 +20,12 @@ func ReadAll(reader io.ReadCloser) ([]string, error) {
|
|||
var excludes []string
|
||||
|
||||
for scanner.Scan() {
|
||||
pattern := strings.TrimSpace(scanner.Text())
|
||||
// Lines starting with # (comments) are ignored before processing
|
||||
pattern := scanner.Text()
|
||||
if strings.HasPrefix(pattern, "#") {
|
||||
continue
|
||||
}
|
||||
pattern = strings.TrimSpace(pattern)
|
||||
if pattern == "" {
|
||||
continue
|
||||
}
|
||||
|
|
|
@ -379,9 +379,13 @@ the working and the root directory. For example, the patterns
|
|||
in the `foo` subdirectory of `PATH` or in the root of the git
|
||||
repository located at `URL`. Neither excludes anything else.
|
||||
|
||||
If a line in `.dockerignore` file starts with `#` in column 1, then this line is
|
||||
considered as a comment and is ignored before interpreted by the CLI.
|
||||
|
||||
Here is an example `.dockerignore` file:
|
||||
|
||||
```
|
||||
# comment
|
||||
*/temp*
|
||||
*/*/temp*
|
||||
temp?
|
||||
|
@ -391,6 +395,7 @@ This file causes the following build behavior:
|
|||
|
||||
| Rule | Behavior |
|
||||
|----------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||
| `# comment` | Ignored. |
|
||||
| `*/temp*` | Exclude files and directories whose names start with `temp` in any immediate subdirectory of the root. For example, the plain file `/somedir/temporary.txt` is excluded, as is the directory `/somedir/temp`. |
|
||||
| `*/*/temp*` | Exclude files and directories starting with `temp` from any subdirectory that is two levels below the root. For example, `/somedir/subdir/temporary.txt` is excluded. |
|
||||
| `temp?` | Exclude files and directories in the root directory whose names are a one-character extension of `temp`. For example, `/tempa` and `/tempb` are excluded.
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue