mirror of https://github.com/docker/docs.git
Merge pull request #13611 from duglin/Issue13417a
Allow .dockerignore to ignore everything
This commit is contained in:
commit
aa8d8fdc0c
|
@ -175,7 +175,7 @@ func (cli *DockerCli) CmdBuild(args ...string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := utils.ValidateContextDirectory(root, excludes); err != nil {
|
if err := utils.ValidateContextDirectory(root, excludes); err != nil {
|
||||||
return fmt.Errorf("Error checking context is accessible: '%s'. Please check permissions and try again.", err)
|
return fmt.Errorf("Error checking context: '%s'.", err)
|
||||||
}
|
}
|
||||||
options := &archive.TarOptions{
|
options := &archive.TarOptions{
|
||||||
Compression: archive.Uncompressed,
|
Compression: archive.Uncompressed,
|
||||||
|
|
|
@ -1722,8 +1722,8 @@ func (s *DockerSuite) TestBuildWithInaccessibleFilesInContext(c *check.C) {
|
||||||
c.Fatalf("output should've contained the string: no permission to read from but contained: %s", out)
|
c.Fatalf("output should've contained the string: no permission to read from but contained: %s", out)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !strings.Contains(out, "Error checking context is accessible") {
|
if !strings.Contains(out, "Error checking context") {
|
||||||
c.Fatalf("output should've contained the string: Error checking context is accessible")
|
c.Fatalf("output should've contained the string: Error checking context")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
@ -1759,8 +1759,8 @@ func (s *DockerSuite) TestBuildWithInaccessibleFilesInContext(c *check.C) {
|
||||||
c.Fatalf("output should've contained the string: can't access %s", out)
|
c.Fatalf("output should've contained the string: can't access %s", out)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !strings.Contains(out, "Error checking context is accessible") {
|
if !strings.Contains(out, "Error checking context") {
|
||||||
c.Fatalf("output should've contained the string: Error checking context is accessible")
|
c.Fatalf("output should've contained the string: Error checking context\ngot:%s", out)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -3651,13 +3651,50 @@ func (s *DockerSuite) TestBuildDockerignoringWholeDir(c *check.C) {
|
||||||
".gitignore": "",
|
".gitignore": "",
|
||||||
".dockerignore": ".*\n",
|
".dockerignore": ".*\n",
|
||||||
})
|
})
|
||||||
|
c.Assert(err, check.IsNil)
|
||||||
defer ctx.Close()
|
defer ctx.Close()
|
||||||
if err != nil {
|
|
||||||
c.Fatal(err)
|
|
||||||
}
|
|
||||||
if _, err = buildImageFromContext(name, ctx, true); err != nil {
|
if _, err = buildImageFromContext(name, ctx, true); err != nil {
|
||||||
c.Fatal(err)
|
c.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
c.Assert(ctx.Add(".dockerfile", "*"), check.IsNil)
|
||||||
|
if _, err = buildImageFromContext(name, ctx, true); err != nil {
|
||||||
|
c.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
c.Assert(ctx.Add(".dockerfile", "."), check.IsNil)
|
||||||
|
if _, err = buildImageFromContext(name, ctx, true); err != nil {
|
||||||
|
c.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
c.Assert(ctx.Add(".dockerfile", "?"), check.IsNil)
|
||||||
|
if _, err = buildImageFromContext(name, ctx, true); err != nil {
|
||||||
|
c.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *DockerSuite) TestBuildDockerignoringBadExclusion(c *check.C) {
|
||||||
|
name := "testbuilddockerignorewholedir"
|
||||||
|
dockerfile := `
|
||||||
|
FROM busybox
|
||||||
|
COPY . /
|
||||||
|
RUN [[ ! -e /.gitignore ]]
|
||||||
|
RUN [[ -f /Makefile ]]`
|
||||||
|
ctx, err := fakeContext(dockerfile, map[string]string{
|
||||||
|
"Dockerfile": "FROM scratch",
|
||||||
|
"Makefile": "all:",
|
||||||
|
".gitignore": "",
|
||||||
|
".dockerignore": "!\n",
|
||||||
|
})
|
||||||
|
c.Assert(err, check.IsNil)
|
||||||
|
defer ctx.Close()
|
||||||
|
if _, err = buildImageFromContext(name, ctx, true); err == nil {
|
||||||
|
c.Fatalf("Build was supposed to fail but didn't")
|
||||||
|
}
|
||||||
|
|
||||||
|
if err.Error() != "failed to build the image: Error checking context: 'Illegal exclusion pattern: !'.\n" {
|
||||||
|
c.Fatalf("Incorrect output, got:%q", err.Error())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DockerSuite) TestBuildLineBreak(c *check.C) {
|
func (s *DockerSuite) TestBuildLineBreak(c *check.C) {
|
||||||
|
|
|
@ -40,7 +40,6 @@ func CleanPatterns(patterns []string) ([]string, [][]string, bool, error) {
|
||||||
}
|
}
|
||||||
if Exclusion(pattern) {
|
if Exclusion(pattern) {
|
||||||
if len(pattern) == 1 {
|
if len(pattern) == 1 {
|
||||||
logrus.Errorf("Illegal exclusion pattern: %s", pattern)
|
|
||||||
return nil, nil, false, errors.New("Illegal exclusion pattern: !")
|
return nil, nil, false, errors.New("Illegal exclusion pattern: !")
|
||||||
}
|
}
|
||||||
exceptions = true
|
exceptions = true
|
||||||
|
@ -94,7 +93,6 @@ func OptimizedMatches(file string, patterns []string, patDirs [][]string) (bool,
|
||||||
|
|
||||||
match, err := filepath.Match(pattern, file)
|
match, err := filepath.Match(pattern, file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Errorf("Error matching: %s (pattern: %s)", file, pattern)
|
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,6 +112,7 @@ func OptimizedMatches(file string, patterns []string, patDirs [][]string) (bool,
|
||||||
if matched {
|
if matched {
|
||||||
logrus.Debugf("Skipping excluded path: %s", file)
|
logrus.Debugf("Skipping excluded path: %s", file)
|
||||||
}
|
}
|
||||||
|
|
||||||
return matched, nil
|
return matched, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue