Browse code

Merge pull request #13611 from duglin/Issue13417a

Allow .dockerignore to ignore everything

Jessie Frazelle authored on 2015/06/02 07:59:57
Showing 3 changed files
... ...
@@ -175,7 +175,7 @@ func (cli *DockerCli) CmdBuild(args ...string) error {
175 175
 		}
176 176
 
177 177
 		if err := utils.ValidateContextDirectory(root, excludes); err != nil {
178
-			return fmt.Errorf("Error checking context is accessible: '%s'. Please check permissions and try again.", err)
178
+			return fmt.Errorf("Error checking context: '%s'.", err)
179 179
 		}
180 180
 		options := &archive.TarOptions{
181 181
 			Compression:     archive.Uncompressed,
... ...
@@ -1722,8 +1722,8 @@ func (s *DockerSuite) TestBuildWithInaccessibleFilesInContext(c *check.C) {
1722 1722
 			c.Fatalf("output should've contained the string: no permission to read from but contained: %s", out)
1723 1723
 		}
1724 1724
 
1725
-		if !strings.Contains(out, "Error checking context is accessible") {
1726
-			c.Fatalf("output should've contained the string: Error checking context is accessible")
1725
+		if !strings.Contains(out, "Error checking context") {
1726
+			c.Fatalf("output should've contained the string: Error checking context")
1727 1727
 		}
1728 1728
 	}
1729 1729
 	{
... ...
@@ -1759,8 +1759,8 @@ func (s *DockerSuite) TestBuildWithInaccessibleFilesInContext(c *check.C) {
1759 1759
 			c.Fatalf("output should've contained the string: can't access %s", out)
1760 1760
 		}
1761 1761
 
1762
-		if !strings.Contains(out, "Error checking context is accessible") {
1763
-			c.Fatalf("output should've contained the string: Error checking context is accessible")
1762
+		if !strings.Contains(out, "Error checking context") {
1763
+			c.Fatalf("output should've contained the string: Error checking context\ngot:%s", out)
1764 1764
 		}
1765 1765
 
1766 1766
 	}
... ...
@@ -3651,15 +3651,52 @@ func (s *DockerSuite) TestBuildDockerignoringWholeDir(c *check.C) {
3651 3651
 		".gitignore":    "",
3652 3652
 		".dockerignore": ".*\n",
3653 3653
 	})
3654
+	c.Assert(err, check.IsNil)
3654 3655
 	defer ctx.Close()
3655
-	if err != nil {
3656
+	if _, err = buildImageFromContext(name, ctx, true); err != nil {
3657
+		c.Fatal(err)
3658
+	}
3659
+
3660
+	c.Assert(ctx.Add(".dockerfile", "*"), check.IsNil)
3661
+	if _, err = buildImageFromContext(name, ctx, true); err != nil {
3662
+		c.Fatal(err)
3663
+	}
3664
+
3665
+	c.Assert(ctx.Add(".dockerfile", "."), check.IsNil)
3666
+	if _, err = buildImageFromContext(name, ctx, true); err != nil {
3656 3667
 		c.Fatal(err)
3657 3668
 	}
3669
+
3670
+	c.Assert(ctx.Add(".dockerfile", "?"), check.IsNil)
3658 3671
 	if _, err = buildImageFromContext(name, ctx, true); err != nil {
3659 3672
 		c.Fatal(err)
3660 3673
 	}
3661 3674
 }
3662 3675
 
3676
+func (s *DockerSuite) TestBuildDockerignoringBadExclusion(c *check.C) {
3677
+	name := "testbuilddockerignorewholedir"
3678
+	dockerfile := `
3679
+        FROM busybox
3680
+		COPY . /
3681
+		RUN [[ ! -e /.gitignore ]]
3682
+		RUN [[ -f /Makefile ]]`
3683
+	ctx, err := fakeContext(dockerfile, map[string]string{
3684
+		"Dockerfile":    "FROM scratch",
3685
+		"Makefile":      "all:",
3686
+		".gitignore":    "",
3687
+		".dockerignore": "!\n",
3688
+	})
3689
+	c.Assert(err, check.IsNil)
3690
+	defer ctx.Close()
3691
+	if _, err = buildImageFromContext(name, ctx, true); err == nil {
3692
+		c.Fatalf("Build was supposed to fail but didn't")
3693
+	}
3694
+
3695
+	if err.Error() != "failed to build the image: Error checking context: 'Illegal exclusion pattern: !'.\n" {
3696
+		c.Fatalf("Incorrect output, got:%q", err.Error())
3697
+	}
3698
+}
3699
+
3663 3700
 func (s *DockerSuite) TestBuildLineBreak(c *check.C) {
3664 3701
 	name := "testbuildlinebreak"
3665 3702
 	_, err := buildImage(name,
... ...
@@ -40,7 +40,6 @@ func CleanPatterns(patterns []string) ([]string, [][]string, bool, error) {
40 40
 		}
41 41
 		if Exclusion(pattern) {
42 42
 			if len(pattern) == 1 {
43
-				logrus.Errorf("Illegal exclusion pattern: %s", pattern)
44 43
 				return nil, nil, false, errors.New("Illegal exclusion pattern: !")
45 44
 			}
46 45
 			exceptions = true
... ...
@@ -94,7 +93,6 @@ func OptimizedMatches(file string, patterns []string, patDirs [][]string) (bool,
94 94
 
95 95
 		match, err := filepath.Match(pattern, file)
96 96
 		if err != nil {
97
-			logrus.Errorf("Error matching: %s (pattern: %s)", file, pattern)
98 97
 			return false, err
99 98
 		}
100 99
 
... ...
@@ -114,6 +112,7 @@ func OptimizedMatches(file string, patterns []string, patDirs [][]string) (bool,
114 114
 	if matched {
115 115
 		logrus.Debugf("Skipping excluded path: %s", file)
116 116
 	}
117
+
117 118
 	return matched, nil
118 119
 }
119 120