diff --git a/archive/archive.go b/archive/archive.go index 44f2fe92d8..30562abaff 100644 --- a/archive/archive.go +++ b/archive/archive.go @@ -356,6 +356,10 @@ func TarWithOptions(srcPath string, options *TarOptions) (io.ReadCloser, error) return err } if matched { + if filepath.Clean(relFilePath) == "." { + utils.Errorf("Can't exclude whole path, excluding pattern: %s", exclude) + continue + } utils.Debugf("Skipping excluded path: %s", relFilePath) if f.IsDir() { return filepath.SkipDir diff --git a/integration-cli/docker_cli_build_test.go b/integration-cli/docker_cli_build_test.go index bf957ada84..302d559a29 100644 --- a/integration-cli/docker_cli_build_test.go +++ b/integration-cli/docker_cli_build_test.go @@ -1577,6 +1577,29 @@ func TestDockerignoringDockerfile(t *testing.T) { logDone("build - test .dockerignore of Dockerfile") } +func TestDockerignoringWholeDir(t *testing.T) { + name := "testbuilddockerignorewholedir" + defer deleteImages(name) + dockerfile := ` + FROM busybox + COPY . / + RUN [[ ! -e /.gitignore ]] + RUN [[ -f /Makefile ]]` + ctx, err := fakeContext(dockerfile, map[string]string{ + "Dockerfile": "FROM scratch", + "Makefile": "all:", + ".dockerignore": ".*\n", + }) + defer ctx.Close() + if err != nil { + t.Fatal(err) + } + if _, err = buildImageFromContext(name, ctx, true); err != nil { + t.Fatal(err) + } + logDone("build - test .dockerignore whole dir with .*") +} + func TestBuildLineBreak(t *testing.T) { name := "testbuildlinebreak" defer deleteImages(name)