Browse code

Allow .dockerignore to ignore everything

Change CLI error msg because it was too specific and didn't make sense
when there were errors not related to inaccessible files.

Removed some log.Error() calls since they're not really errors we should
log. Returning the error will be enough.

Closes: #13417

Signed-off-by: Doug Davis <dug@us.ibm.com>

Doug Davis authored on 2015/05/30 11:38:56
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
 	}
... ...
@@ -3676,15 +3676,52 @@ func (s *DockerSuite) TestBuildDockerignoringWholeDir(c *check.C) {
3676 3676
 		".gitignore":    "",
3677 3677
 		".dockerignore": ".*\n",
3678 3678
 	})
3679
+	c.Assert(err, check.IsNil)
3679 3680
 	defer ctx.Close()
3680
-	if err != nil {
3681
+	if _, err = buildImageFromContext(name, ctx, true); err != nil {
3682
+		c.Fatal(err)
3683
+	}
3684
+
3685
+	c.Assert(ctx.Add(".dockerfile", "*"), check.IsNil)
3686
+	if _, err = buildImageFromContext(name, ctx, true); err != nil {
3687
+		c.Fatal(err)
3688
+	}
3689
+
3690
+	c.Assert(ctx.Add(".dockerfile", "."), check.IsNil)
3691
+	if _, err = buildImageFromContext(name, ctx, true); err != nil {
3681 3692
 		c.Fatal(err)
3682 3693
 	}
3694
+
3695
+	c.Assert(ctx.Add(".dockerfile", "?"), check.IsNil)
3683 3696
 	if _, err = buildImageFromContext(name, ctx, true); err != nil {
3684 3697
 		c.Fatal(err)
3685 3698
 	}
3686 3699
 }
3687 3700
 
3701
+func (s *DockerSuite) TestBuildDockerignoringBadExclusion(c *check.C) {
3702
+	name := "testbuilddockerignorewholedir"
3703
+	dockerfile := `
3704
+        FROM busybox
3705
+		COPY . /
3706
+		RUN [[ ! -e /.gitignore ]]
3707
+		RUN [[ -f /Makefile ]]`
3708
+	ctx, err := fakeContext(dockerfile, map[string]string{
3709
+		"Dockerfile":    "FROM scratch",
3710
+		"Makefile":      "all:",
3711
+		".gitignore":    "",
3712
+		".dockerignore": "!\n",
3713
+	})
3714
+	c.Assert(err, check.IsNil)
3715
+	defer ctx.Close()
3716
+	if _, err = buildImageFromContext(name, ctx, true); err == nil {
3717
+		c.Fatalf("Build was supposed to fail but didn't")
3718
+	}
3719
+
3720
+	if err.Error() != "failed to build the image: Error checking context: 'Illegal exclusion pattern: !'.\n" {
3721
+		c.Fatalf("Incorrect output, got:%q", err.Error())
3722
+	}
3723
+}
3724
+
3688 3725
 func (s *DockerSuite) TestBuildLineBreak(c *check.C) {
3689 3726
 	name := "testbuildlinebreak"
3690 3727
 	_, 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