From 855dee7dbdf4fc1d8b6d0c42d78a2d32a5bfafb7 Mon Sep 17 00:00:00 2001 From: David Gageot Date: Wed, 25 Apr 2018 09:20:02 +0200 Subject: [PATCH 1/4] Improve Docker dependencies code Fixes #386 --- pkg/skaffold/bazel/bazel.go | 5 +- pkg/skaffold/build/deps.go | 3 +- pkg/skaffold/docker/context.go | 8 +- pkg/skaffold/docker/parse.go | 132 ++++++++++++++++-------------- pkg/skaffold/docker/parse_test.go | 33 +++++--- pkg/skaffold/util/tar.go | 16 +--- pkg/skaffold/util/util.go | 62 -------------- pkg/skaffold/util/util_test.go | 61 -------------- 8 files changed, 99 insertions(+), 221 deletions(-) diff --git a/pkg/skaffold/bazel/bazel.go b/pkg/skaffold/bazel/bazel.go index fac5a8fce6f..cc0a7261a9c 100644 --- a/pkg/skaffold/bazel/bazel.go +++ b/pkg/skaffold/bazel/bazel.go @@ -19,7 +19,6 @@ package bazel import ( "fmt" "os/exec" - "path/filepath" "strings" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/v1alpha2" @@ -52,9 +51,7 @@ func (*BazelDependencyResolver) GetDependencies(a *v1alpha2.Artifact) ([]string, continue } - dep := filepath.Join(a.Workspace, depToPath(l)) - - deps = append(deps, dep) + deps = append(deps, depToPath(l)) } return deps, nil } diff --git a/pkg/skaffold/build/deps.go b/pkg/skaffold/build/deps.go index 363df67f313..ec98d977024 100644 --- a/pkg/skaffold/build/deps.go +++ b/pkg/skaffold/build/deps.go @@ -18,6 +18,7 @@ package build import ( "fmt" + "path/filepath" "sort" "strings" @@ -119,7 +120,7 @@ func pathsForArtifact(a *v1alpha2.Artifact) ([]string, error) { logrus.Debugf("Ignoring %s for artifact dependencies", dep) continue } - filteredDeps = append(filteredDeps, dep) + filteredDeps = append(filteredDeps, filepath.Join(a.Workspace, dep)) } return filteredDeps, nil } diff --git a/pkg/skaffold/docker/context.go b/pkg/skaffold/docker/context.go index 7d6b267c6f0..32167c4aa32 100644 --- a/pkg/skaffold/docker/context.go +++ b/pkg/skaffold/docker/context.go @@ -25,12 +25,8 @@ import ( "github.com/pkg/errors" ) -func contextTarPaths(dockerfilePath string, context string) ([]string, error) { - return GetDockerfileDependencies(dockerfilePath, context) -} - func CreateDockerTarContext(w io.Writer, dockerfilePath, context string) error { - paths, err := contextTarPaths(dockerfilePath, context) + paths, err := GetDockerfileDependencies(dockerfilePath, context) if err != nil { return errors.Wrap(err, "getting relative tar paths") } @@ -41,7 +37,7 @@ func CreateDockerTarContext(w io.Writer, dockerfilePath, context string) error { } func CreateDockerTarGzContext(w io.Writer, dockerfilePath, context string) error { - paths, err := contextTarPaths(dockerfilePath, context) + paths, err := GetDockerfileDependencies(dockerfilePath, context) if err != nil { return errors.Wrap(err, "getting relative tar paths") } diff --git a/pkg/skaffold/docker/parse.go b/pkg/skaffold/docker/parse.go index d576d390116..4ae0be45bb1 100644 --- a/pkg/skaffold/docker/parse.go +++ b/pkg/skaffold/docker/parse.go @@ -22,14 +22,12 @@ import ( "fmt" "io" "os" - "path" "path/filepath" "sort" "strings" "sync" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/v1alpha2" - "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" "github.com/google/go-containerregistry/v1" "github.com/docker/docker/builder/dockerignore" @@ -57,11 +55,9 @@ func (d *DockerfileDepResolver) GetDependencies(a *v1alpha2.Artifact) ([]string, return GetDockerfileDependencies(a.DockerArtifact.DockerfilePath, a.Workspace) } -// GetDockerfileDependencies parses a dockerfile and returns the full paths -// of all the source files that the resulting docker image depends on. -func GetDockerfileDependencies(dockerfilePath, workspace string) ([]string, error) { +func readDockerfile(workspace, dockerfilePath string) ([]string, error) { path := filepath.Join(workspace, dockerfilePath) - f, err := util.Fs.Open(path) + f, err := os.Open(path) if err != nil { return nil, errors.Wrapf(err, "opening dockerfile: %s", path) } @@ -91,7 +87,7 @@ func GetDockerfileDependencies(dockerfilePath, workspace string) ([]string, erro for _, value := range r.AST.Children { switch value.Value { case add, copy: - processCopy(workspace, value, depMap, envs) + processCopy(value, depMap, envs) case env: envs[value.Next.Value] = value.Next.Next.Value } @@ -109,30 +105,86 @@ func GetDockerfileDependencies(dockerfilePath, workspace string) ([]string, erro dispatchInstructions(res) - deps := []string{} + var deps []string for dep := range depMap { deps = append(deps, dep) } logrus.Infof("Found dependencies for dockerfile %s", deps) - expandedDeps, err := util.ExpandPaths(workspace, deps) + return deps, nil +} + +func GetDockerfileDependencies(dockerfilePath, workspace string) ([]string, error) { + deps, err := readDockerfile(workspace, dockerfilePath) if err != nil { - return nil, errors.Wrap(err, "expanding dockerfile paths") + return nil, err } - logrus.Infof("deps %s", expandedDeps) - if !util.StrSliceContains(expandedDeps, path) { - expandedDeps = append(expandedDeps, path) + // Read patterns to ignore + var excludes []string + dockerignorePath := filepath.Join(workspace, ".dockerignore") + if _, err := os.Stat(dockerignorePath); !os.IsNotExist(err) { + r, err := os.Open(dockerignorePath) + if err != nil { + return nil, err + } + defer r.Close() + + excludes, err = dockerignore.ReadAll(r) + if err != nil { + return nil, err + } + } + + // Walk the workspace + files := make(map[string]bool) + for _, dep := range deps { + filepath.Walk(filepath.Join(workspace, dep), func(fpath string, info os.FileInfo, err error) error { + if err != nil { + return err + } + + relPath, err := filepath.Rel(workspace, fpath) + if err != nil { + return err + } + + ignored, err := fileutils.Matches(relPath, excludes) + if err != nil { + return err + } + + if info.IsDir() && ignored { + return filepath.SkipDir + } + + if !info.IsDir() && !ignored { + files[relPath] = true + } + + return nil + }) } - // Look for .dockerignore. - ignorePath := filepath.Join(workspace, ".dockerignore") - filteredDeps, err := ApplyDockerIgnore(expandedDeps, ignorePath) + // Add dockerfile? + m, err := fileutils.Matches(dockerfilePath, excludes) if err != nil { - return nil, errors.Wrap(err, "applying dockerignore") + return nil, err + } + if !m { + files[dockerfilePath] = true + } + + // Ignore .dockerignore + delete(files, ".dockerignore") + + var dependencies []string + for file := range files { + dependencies = append(dependencies, file) } + sort.Strings(dependencies) - return filteredDeps, nil + return dependencies, nil } func PortsFromDockerfile(r io.Reader) ([]string, error) { @@ -242,7 +294,7 @@ func retrieveRemoteConfig(identifier string) (*v1.ConfigFile, error) { return img.ConfigFile() } -func processCopy(workspace string, value *parser.Node, paths map[string]struct{}, envs map[string]string) error { +func processCopy(value *parser.Node, paths map[string]struct{}, envs map[string]string) error { slex := shell.NewLex('\\') for { // Skip last node, since it is the destination, and stop if we arrive at a comment @@ -259,8 +311,7 @@ func processCopy(workspace string, value *parser.Node, paths map[string]struct{} return nil } if !strings.HasPrefix(src, "http://") && !strings.HasPrefix(src, "https://") { - dep := path.Join(workspace, src) - paths[dep] = struct{}{} + paths[src] = struct{}{} } else { logrus.Debugf("Skipping watch on remote dependency %s", src) } @@ -286,42 +337,3 @@ func hasMultiStageFlag(flags []string) bool { } return false } - -func ApplyDockerIgnore(paths []string, dockerIgnorePath string) ([]string, error) { - absPaths, err := util.RelPathToAbsPath(paths) - if err != nil { - return nil, errors.Wrap(err, "getting absolute path of dependencies") - } - excludes := []string{} - if _, err := util.Fs.Stat(dockerIgnorePath); !os.IsNotExist(err) { - r, err := util.Fs.Open(dockerIgnorePath) - if err != nil { - return nil, err - } - defer r.Close() - - excludes, err = dockerignore.ReadAll(r) - if err != nil { - return nil, err - } - excludes = append(excludes, ".dockerignore") - } - - absPathExcludes, err := util.RelPathToAbsPath(excludes) - if err != nil { - return nil, errors.Wrap(err, "getting absolute path of docker ignored paths") - } - - filteredDeps := []string{} - for _, d := range absPaths { - m, err := fileutils.Matches(d, absPathExcludes) - if err != nil { - return nil, err - } - if !m { - filteredDeps = append(filteredDeps, d) - } - } - sort.Strings(filteredDeps) - return filteredDeps, nil -} diff --git a/pkg/skaffold/docker/parse_test.go b/pkg/skaffold/docker/parse_test.go index 851b6b6bdfa..74e6e316f4e 100644 --- a/pkg/skaffold/docker/parse_test.go +++ b/pkg/skaffold/docker/parse_test.go @@ -18,15 +18,15 @@ package docker import ( "fmt" + "io/ioutil" + "os" "path/filepath" "strings" "testing" - "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" "github.com/GoogleContainerTools/skaffold/testutil" "github.com/google/go-containerregistry/v1" - "github.com/spf13/afero" ) const copyDockerfile = ` @@ -159,7 +159,7 @@ func TestGetDockerfileDependencies(t *testing.T) { description: "add dependency", dockerfile: addDockerfile, workspace: "docker", - expected: []string{"docker/Dockerfile", "docker/nginx.conf"}, + expected: []string{"Dockerfile", "nginx.conf"}, }, { description: "bad read", @@ -204,11 +204,18 @@ func TestGetDockerfileDependencies(t *testing.T) { expected: []string{"Dockerfile", "file", "server.go", "test.conf", "worker.go"}, }, { - description: "dockerignore with context in parent directory test", + description: "dockerignore with non canonical workspace", dockerfile: contextDockerfile, workspace: "docker/../docker", dockerIgnore: true, - expected: []string{}, + expected: []string{"Dockerfile", "nginx.conf"}, + }, + { + description: "dockerignore with context in parent directory", + dockerfile: contextDockerfile, + workspace: "docker/..", + dockerIgnore: true, + expected: []string{"Dockerfile", "file", "server.go", "test.conf", "worker.go"}, }, { description: "onbuild test", @@ -231,24 +238,24 @@ func TestGetDockerfileDependencies(t *testing.T) { for _, test := range tests { t.Run(test.description, func(t *testing.T) { - defer func(fs afero.Fs) { util.Fs = fs }(util.Fs) - util.Fs = afero.NewMemMapFs() + tmpDir, cleanup := testutil.TempDir(t) + defer cleanup() - util.Fs.MkdirAll("docker", 0750) + os.MkdirAll(filepath.Join(tmpDir, "docker"), 0750) for _, file := range []string{"docker/nginx.conf", "docker/bar", "server.go", "test.conf", "worker.go", "bar", "file"} { - afero.WriteFile(util.Fs, file, []byte(""), 0644) + ioutil.WriteFile(filepath.Join(tmpDir, file), []byte(""), 0644) } + workspace := filepath.Join(tmpDir, test.workspace) if !test.badReader { - afero.WriteFile(util.Fs, filepath.Join(test.workspace, "Dockerfile"), []byte(test.dockerfile), 0644) + ioutil.WriteFile(filepath.Join(workspace, "Dockerfile"), []byte(test.dockerfile), 0644) } if test.dockerIgnore { - afero.WriteFile(util.Fs, ".dockerignore", []byte(dockerIgnore), 0644) - afero.WriteFile(util.Fs, filepath.Join("docker", ".dockerignore"), []byte(dockerIgnore), 0644) + ioutil.WriteFile(filepath.Join(workspace, ".dockerignore"), []byte(dockerIgnore), 0644) } - deps, err := GetDockerfileDependencies("Dockerfile", test.workspace) + deps, err := GetDockerfileDependencies("Dockerfile", workspace) testutil.CheckErrorAndDeepEqual(t, test.shouldErr, err, test.expected, deps) }) } diff --git a/pkg/skaffold/util/tar.go b/pkg/skaffold/util/tar.go index 6cfe023e74e..3c6995e831d 100644 --- a/pkg/skaffold/util/tar.go +++ b/pkg/skaffold/util/tar.go @@ -31,22 +31,10 @@ func CreateTar(w io.Writer, root string, paths []string) error { tw := tar.NewWriter(w) defer tw.Close() - absContext, err := filepath.Abs(root) - if err != nil { - return err - } for _, p := range paths { - absPath, err := filepath.Abs(p) - if err != nil { - return err - } - - tarPath, err := filepath.Rel(absContext, absPath) - if err != nil { - return err - } + tarPath := filepath.ToSlash(filepath.Join(root, p)) - if err := addFileToTar(p, filepath.ToSlash(tarPath), tw); err != nil { + if err := addFileToTar(tarPath, p, tw); err != nil { return err } diff --git a/pkg/skaffold/util/util.go b/pkg/skaffold/util/util.go index 69982b517c9..eb41b0672dc 100644 --- a/pkg/skaffold/util/util.go +++ b/pkg/skaffold/util/util.go @@ -22,7 +22,6 @@ import ( "io/ioutil" "net/http" "os" - "path" "sort" "strings" @@ -66,56 +65,6 @@ func StrSliceContains(sl []string, s string) bool { return false } -func RelPathToAbsPath(relPaths []string) ([]string, error) { - baseFs := afero.NewBasePathFs(Fs, "").(*afero.BasePathFs) - - absPath := []string{} - for _, p := range relPaths { - a := afero.FullBaseFsPath(baseFs, p) - absPath = append(absPath, a) - } - return absPath, nil -} - -// ExpandPaths uses a filepath.Match to expand paths according to wildcards. -// It requires a workspace directory, which is walked and tested for wildcard matches -// It is used by the dockerfile parser and you most likely want to use ExpandPathsGlob -func ExpandPaths(workspace string, paths []string) ([]string, error) { - expandedPaths := map[string]struct{}{} - for _, p := range paths { - // If the path contains a filepath.Match wildcard, we have to walk the workspace - // and find any matches to that pattern - if containsWildcards(p) { - logrus.Debugf("COPY or ADD directive with wildcard %s", p) - if err := afero.Walk(Fs, workspace, func(fpath string, info os.FileInfo, err error) error { - if match, _ := path.Match(p, fpath); !match { - return nil - } - if err := addFileOrDir(Fs, fpath, info, expandedPaths); err != nil { - return errors.Wrap(err, "adding file or directory") - } - return nil - }); err != nil { - return nil, errors.Wrap(err, "walking wildcard path") - } - continue - } - // If the path does not contain a wildcard, recursively add the directory or individual file - info, err := Fs.Stat(p) - if err != nil { - return nil, errors.Wrap(err, "getting file info") - } - if err := addFileOrDir(Fs, p, info, expandedPaths); err != nil { - return nil, errors.Wrap(err, "adding file or directory") - } - } - ret := []string{} - for ep := range expandedPaths { - ret = append(ret, ep) - } - return ret, nil -} - // ExpandPathsGlob expands paths according to filepath.Glob patterns // Returns a list of unique files that match the glob patterns passed in. func ExpandPathsGlob(paths []string) ([]string, error) { @@ -177,17 +126,6 @@ func addDir(fs afero.Fs, dir string, expandedPaths map[string]struct{}) error { return nil } -func containsWildcards(path string) bool { - for i := 0; i < len(path); i++ { - ch := path[i] - // These are the wildcards that correspond to filepath.Match - if ch == '*' || ch == '?' || ch == '[' { - return true - } - } - return false -} - // BoolPtr returns a pointer to a bool func BoolPtr(b bool) *bool { o := b diff --git a/pkg/skaffold/util/util_test.go b/pkg/skaffold/util/util_test.go index 22200ce9ec0..6548bced3a3 100644 --- a/pkg/skaffold/util/util_test.go +++ b/pkg/skaffold/util/util_test.go @@ -17,7 +17,6 @@ limitations under the License. package util import ( - "sort" "testing" "github.com/GoogleContainerTools/skaffold/testutil" @@ -62,66 +61,6 @@ func TestSupportedKubernetesFormats(t *testing.T) { } } -func TestExpandDeps(t *testing.T) { - var tests = []struct { - description string - in []string - out []string - shouldErr bool - }{ - { - description: "add single files", - in: []string{"test/a", "test/b", "test/c"}, - out: []string{"test/a", "test/b", "test/c"}, - }, - { - description: "add directory", - in: []string{"test"}, - out: []string{"test/a", "test/b", "test/c"}, - }, - { - description: "add directory trailing slash", - in: []string{"test/"}, - out: []string{"test/a", "test/b", "test/c"}, - }, - { - description: "file not exist", - in: []string{"test/d"}, - shouldErr: true, - }, - { - description: "add wildcard star", - in: []string{"*"}, - out: []string{"test/a", "test/b", "test/c"}, - }, - { - description: "add wildcard any character", - in: []string{"test/?"}, - out: []string{"test/a", "test/b", "test/c"}, - }, - } - - defer func(fs afero.Fs) { Fs = fs }(Fs) - Fs = afero.NewMemMapFs() - - Fs.MkdirAll("test", 0755) - files := []string{"test/a", "test/b", "test/c"} - for _, name := range files { - afero.WriteFile(Fs, name, []byte(""), 0644) - } - - for _, test := range tests { - t.Run(test.description, func(t *testing.T) { - actual, err := ExpandPaths(".", test.in) - // Sort both slices for reproducibility - sort.Strings(actual) - sort.Strings(test.out) - - testutil.CheckErrorAndDeepEqual(t, test.shouldErr, err, test.out, actual) - }) - } -} - func TestExpandPathsGlob(t *testing.T) { defer func(fs afero.Fs) { Fs = fs }(Fs) Fs = afero.NewMemMapFs() From 48fcab333d663597edc7a62de253e52ea9762959 Mon Sep 17 00:00:00 2001 From: David Gageot Date: Wed, 25 Apr 2018 15:41:10 +0200 Subject: [PATCH 2/4] Generate data for the test Signed-off-by: David Gageot --- pkg/skaffold/docker/context_test.go | 42 +++++++++++++++++------------ 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/pkg/skaffold/docker/context_test.go b/pkg/skaffold/docker/context_test.go index 3c089c7d0b0..de76cc7d28a 100644 --- a/pkg/skaffold/docker/context_test.go +++ b/pkg/skaffold/docker/context_test.go @@ -19,51 +19,59 @@ package docker import ( "archive/tar" "io" + "io/ioutil" + "os" + "path/filepath" "testing" - "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" - "github.com/pkg/errors" + "github.com/GoogleContainerTools/skaffold/testutil" ) func TestDockerContext(t *testing.T) { + tmpDir, cleanup := testutil.TempDir(t) + defer cleanup() + + os.Mkdir(filepath.Join(tmpDir, "files"), 0750) + ioutil.WriteFile(filepath.Join(tmpDir, "files", "ignored.txt"), []byte(""), 0644) + ioutil.WriteFile(filepath.Join(tmpDir, "files", "included.txt"), []byte(""), 0644) + ioutil.WriteFile(filepath.Join(tmpDir, ".dockerignore"), []byte("**/ignored.txt"), 0644) + ioutil.WriteFile(filepath.Join(tmpDir, "Dockerfile"), []byte("FROM alpine\nCOPY ./files /files"), 0644) + ioutil.WriteFile(filepath.Join(tmpDir, "ignored.txt"), []byte(""), 0644) + reader, writer := io.Pipe() go func() { - err := CreateDockerTarContext(writer, "Dockerfile", "../../../testdata/docker") + err := CreateDockerTarContext(writer, "Dockerfile", tmpDir) if err != nil { - writer.CloseWithError(errors.Wrap(err, "creating docker context")) - panic(err) + writer.CloseWithError(err) + } else { + writer.Close() } - writer.Close() }() - var files []string + files := make(map[string]bool) tr := tar.NewReader(reader) for { header, err := tr.Next() - if err == io.EOF { break } if err != nil { - panic(errors.Wrap(err, "reading tar headers")) + t.Fatal(err) } - files = append(files, header.Name) + files[header.Name] = true } - if util.StrSliceContains(files, "ignored.txt") { + if files["ignored.txt"] { t.Error("File ignored.txt should have been excluded, but was not") } - - if util.StrSliceContains(files, "files/ignored.txt") { + if files["files/ignored.txt"] { t.Error("File files/ignored.txt should have been excluded, but was not") } - - if !util.StrSliceContains(files, "files/included.txt") { + if !files["files/included.txt"] { t.Error("File files/included.txt should have been included, but was not") } - - if !util.StrSliceContains(files, "Dockerfile") { + if !files["Dockerfile"] { t.Error("File Dockerfile should have been included, but was not") } } From c6b1701867984fbaa98247abe37ab858d6550073 Mon Sep 17 00:00:00 2001 From: David Gageot Date: Wed, 25 Apr 2018 15:54:12 +0200 Subject: [PATCH 3/4] Simplify ExpandPathsGlob code Signed-off-by: David Gageot --- pkg/skaffold/util/util.go | 47 +++++++++++---------------------------- 1 file changed, 13 insertions(+), 34 deletions(-) diff --git a/pkg/skaffold/util/util.go b/pkg/skaffold/util/util.go index eb41b0672dc..8f74eef4acf 100644 --- a/pkg/skaffold/util/util.go +++ b/pkg/skaffold/util/util.go @@ -26,7 +26,6 @@ import ( "strings" "github.com/pkg/errors" - "github.com/sirupsen/logrus" "github.com/spf13/afero" ) @@ -68,13 +67,14 @@ func StrSliceContains(sl []string, s string) bool { // ExpandPathsGlob expands paths according to filepath.Glob patterns // Returns a list of unique files that match the glob patterns passed in. func ExpandPathsGlob(paths []string) ([]string, error) { - expandedPaths := map[string]struct{}{} + expandedPaths := make(map[string]bool) for _, p := range paths { if _, err := Fs.Stat(p); err == nil { // This is a file reference, so just add it - expandedPaths[p] = struct{}{} + expandedPaths[p] = true continue } + files, err := afero.Glob(Fs, p) if err != nil { return nil, errors.Wrap(err, "glob") @@ -84,16 +84,20 @@ func ExpandPathsGlob(paths []string) ([]string, error) { } for _, f := range files { - fi, err := Fs.Stat(f) + err := afero.Walk(Fs, f, func(path string, info os.FileInfo, err error) error { + if !info.IsDir() { + expandedPaths[path] = true + } + + return nil + }) if err != nil { - return nil, err - } - if err := addFileOrDir(Fs, f, fi, expandedPaths); err != nil { - return nil, errors.Wrap(err, "adding file or dir") + return nil, errors.Wrap(err, "filepath walk") } } } - ret := []string{} + + var ret []string for k := range expandedPaths { ret = append(ret, k) } @@ -101,31 +105,6 @@ func ExpandPathsGlob(paths []string) ([]string, error) { return ret, nil } -func addFileOrDir(fs afero.Fs, ref string, info os.FileInfo, expandedPaths map[string]struct{}) error { - if info.IsDir() { - return addDir(fs, ref, expandedPaths) - } - expandedPaths[ref] = struct{}{} - return nil -} - -func addDir(fs afero.Fs, dir string, expandedPaths map[string]struct{}) error { - logrus.Debugf("Recursively adding %s", dir) - if err := afero.Walk(fs, dir, func(path string, info os.FileInfo, err error) error { - if info == nil { - return nil - } - if info.IsDir() { - return nil - } - expandedPaths[path] = struct{}{} - return nil - }); err != nil { - return errors.Wrap(err, "filepath walk") - } - return nil -} - // BoolPtr returns a pointer to a bool func BoolPtr(b bool) *bool { o := b From 7468876085d26ce531bc9654368c92db4a715260 Mon Sep 17 00:00:00 2001 From: David Gageot Date: Thu, 17 May 2018 19:10:39 +0200 Subject: [PATCH 4/4] Add test for #386 Signed-off-by: David Gageot --- pkg/skaffold/docker/context_test.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pkg/skaffold/docker/context_test.go b/pkg/skaffold/docker/context_test.go index de76cc7d28a..5b69d76ddca 100644 --- a/pkg/skaffold/docker/context_test.go +++ b/pkg/skaffold/docker/context_test.go @@ -34,9 +34,10 @@ func TestDockerContext(t *testing.T) { os.Mkdir(filepath.Join(tmpDir, "files"), 0750) ioutil.WriteFile(filepath.Join(tmpDir, "files", "ignored.txt"), []byte(""), 0644) ioutil.WriteFile(filepath.Join(tmpDir, "files", "included.txt"), []byte(""), 0644) - ioutil.WriteFile(filepath.Join(tmpDir, ".dockerignore"), []byte("**/ignored.txt"), 0644) + ioutil.WriteFile(filepath.Join(tmpDir, ".dockerignore"), []byte("**/ignored.txt\nalsoignored.txt"), 0644) ioutil.WriteFile(filepath.Join(tmpDir, "Dockerfile"), []byte("FROM alpine\nCOPY ./files /files"), 0644) ioutil.WriteFile(filepath.Join(tmpDir, "ignored.txt"), []byte(""), 0644) + ioutil.WriteFile(filepath.Join(tmpDir, "alsoignored.txt"), []byte(""), 0644) reader, writer := io.Pipe() go func() { @@ -65,6 +66,9 @@ func TestDockerContext(t *testing.T) { if files["ignored.txt"] { t.Error("File ignored.txt should have been excluded, but was not") } + if files["alsoignored.txt"] { + t.Error("File alsoignored.txt should have been excluded, but was not") + } if files["files/ignored.txt"] { t.Error("File files/ignored.txt should have been excluded, but was not") }