Skip to content

Commit

Permalink
Merge pull request #1122 from dgageot/fix-1110
Browse files Browse the repository at this point in the history
Support for dot files in dockerignore
  • Loading branch information
dgageot authored Oct 9, 2018
2 parents 22667e2 + 7f47223 commit 0cfc833
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
4 changes: 4 additions & 0 deletions pkg/skaffold/docker/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 32 additions & 4 deletions pkg/skaffold/docker/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,11 @@ FROM base as dist
FROM DIST as prod
`

const copyAll = `
FROM nginx
COPY . /
`

type fakeImageFetcher struct {
fetched []string
}
Expand Down Expand Up @@ -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"},
},
{
Expand All @@ -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"},
},
{
Expand Down Expand Up @@ -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, "")
}

Expand Down

0 comments on commit 0cfc833

Please sign in to comment.