From 7f472236e9d20364d3a8608e447af9224b91bad0 Mon Sep 17 00:00:00 2001 From: David Gageot Date: Mon, 8 Oct 2018 18:12:44 +0200 Subject: [PATCH] Support for dot files in dockerignore Fixes #1110 Signed-off-by: David Gageot --- pkg/skaffold/docker/parse.go | 4 ++++ pkg/skaffold/docker/parse_test.go | 36 +++++++++++++++++++++++++++---- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/pkg/skaffold/docker/parse.go b/pkg/skaffold/docker/parse.go index 80d9b7a320b..581a42675d8 100644 --- a/pkg/skaffold/docker/parse.go +++ b/pkg/skaffold/docker/parse.go @@ -304,6 +304,10 @@ func GetDependencies(workspace string, a *latest.DockerArtifact) ([]string, erro if err := godirwalk.Walk(absDep, &godirwalk.Options{ Unsorted: true, Callback: func(fpath string, info *godirwalk.Dirent) error { + if fpath == absDep { + return nil + } + relPath, err := filepath.Rel(workspace, fpath) if err != nil { return err diff --git a/pkg/skaffold/docker/parse_test.go b/pkg/skaffold/docker/parse_test.go index d47a24b577d..61b432de45e 100644 --- a/pkg/skaffold/docker/parse_test.go +++ b/pkg/skaffold/docker/parse_test.go @@ -168,6 +168,11 @@ FROM base as dist FROM DIST as prod ` +const copyAll = ` +FROM nginx +COPY . / +` + type fakeImageFetcher struct { fetched []string } @@ -284,7 +289,7 @@ func TestGetDependencies(t *testing.T) { dockerfile: copyDirectory, ignore: "bar\ndocker/*", workspace: ".", - expected: []string{"Dockerfile", "file", "server.go", "test.conf", "worker.go"}, + expected: []string{".dot", "Dockerfile", "file", "server.go", "test.conf", "worker.go"}, fetched: []string{"nginx"}, }, { @@ -303,19 +308,42 @@ func TestGetDependencies(t *testing.T) { expected: []string{"Dockerfile", "nginx.conf"}, fetched: []string{"nginx"}, }, + { + description: "ignore none", + dockerfile: copyAll, + workspace: ".", + expected: []string{".dot", "Dockerfile", "bar", filepath.Join("docker", "bar"), filepath.Join("docker", "nginx.conf"), "file", "server.go", "test.conf", "worker.go"}, + fetched: []string{"nginx"}, + }, + { + description: "ignore dotfiles", + dockerfile: copyAll, + workspace: ".", + ignore: ".*", + expected: []string{"Dockerfile", "bar", filepath.Join("docker", "bar"), filepath.Join("docker", "nginx.conf"), "file", "server.go", "test.conf", "worker.go"}, + fetched: []string{"nginx"}, + }, + { + description: "ignore dotfiles (root syntax)", + dockerfile: copyAll, + workspace: ".", + ignore: "/.*", + expected: []string{"Dockerfile", "bar", filepath.Join("docker", "bar"), filepath.Join("docker", "nginx.conf"), "file", "server.go", "test.conf", "worker.go"}, + fetched: []string{"nginx"}, + }, { description: "dockerignore with context in parent directory", dockerfile: copyDirectory, workspace: "docker/..", ignore: "bar\ndocker/*\n*.go", - expected: []string{"Dockerfile", "file", "test.conf"}, + expected: []string{".dot", "Dockerfile", "file", "test.conf"}, fetched: []string{"nginx"}, }, { description: "onbuild test", dockerfile: onbuild, workspace: ".", - expected: []string{"Dockerfile", "bar", filepath.Join("docker", "bar"), filepath.Join("docker", "nginx.conf"), "file", "server.go", "test.conf", "worker.go"}, + expected: []string{".dot", "Dockerfile", "bar", filepath.Join("docker", "bar"), filepath.Join("docker", "nginx.conf"), "file", "server.go", "test.conf", "worker.go"}, fetched: []string{"golang:onbuild"}, }, { @@ -419,7 +447,7 @@ func TestGetDependencies(t *testing.T) { RetrieveImage = imageFetcher.fetch defer func() { RetrieveImage = retrieveImage }() - for _, file := range []string{"docker/nginx.conf", "docker/bar", "server.go", "test.conf", "worker.go", "bar", "file"} { + for _, file := range []string{"docker/nginx.conf", "docker/bar", "server.go", "test.conf", "worker.go", "bar", "file", ".dot"} { tmpDir.Write(file, "") }