Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for dot files in dockerignore #1122

Merged
merged 1 commit into from
Oct 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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