From cb0a5e0a18283bb0807ec6714585809b510f90e7 Mon Sep 17 00:00:00 2001 From: Priya Wadhwa Date: Fri, 19 Oct 2018 14:55:56 -0700 Subject: [PATCH] Fix integration tests --- cmd/executor/cmd/root.go | 6 +++++- integration/images.go | 14 +++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/cmd/executor/cmd/root.go b/cmd/executor/cmd/root.go index 5bdeb0c872..dcbb48430f 100644 --- a/cmd/executor/cmd/root.go +++ b/cmd/executor/cmd/root.go @@ -63,7 +63,7 @@ var RootCmd = &cobra.Command{ return errors.Wrap(err, "error resolving source context") } if err := removeIgnoredFiles(); err != nil { - return errors.Wrap(err, "error removing ignored files from build context") + return errors.Wrap(err, "error removing .dockerignore files from build context") } return resolveDockerfilePath() }, @@ -198,9 +198,11 @@ func removeIgnoredFiles() error { for r, i := range ignore { ignore[r] = filepath.Clean(filepath.Join(opts.SrcContext, i)) } + // first, remove all files in .dockerignore err = filepath.Walk(opts.SrcContext, func(path string, fi os.FileInfo, _ error) error { if ignoreFile(path, ignore) { if err := os.RemoveAll(path); err != nil { + // don't return error, because this path could have been removed already logrus.Debugf("error removing %s from buildcontext", path) } } @@ -209,10 +211,12 @@ func removeIgnoredFiles() error { if err != nil { return err } + // then, remove .dockerignore path := filepath.Join(opts.SrcContext, ".dockerignore") return os.Remove(path) } +// ignoreFile returns true if the path matches any of the paths in ignore func ignoreFile(path string, ignore []string) bool { for _, i := range ignore { matched, err := filepath.Match(i, path) diff --git a/integration/images.go b/integration/images.go index 19d7a91d2a..1f392be571 100644 --- a/integration/images.go +++ b/integration/images.go @@ -37,7 +37,7 @@ const ( buildContextPath = "/workspace" cacheDir = "/workspace/cache" baseImageToCache = "gcr.io/google-appengine/debian9@sha256:1d6a9a6d106bd795098f60f4abb7083626354fa6735e81743c7f8cfca11259f0" - testDirPath = "test/dir/path" + testDirPath = "context/test" ) // Arguments to build Dockerfiles with, used for both docker and kaniko builds @@ -55,7 +55,7 @@ var argsMap = map[string][]string{ "Dockerfile_test_multistage": {"file=/foo2"}, } -var filesToIgnore = []string{"test/*"} +var filesToIgnore = []string{"context/test/*"} // Arguments to build Dockerfiles with when building with docker var additionalDockerFlagsMap = map[string][]string{ @@ -271,7 +271,15 @@ func (d *DockerFileBuilder) buildCachedImages(imageRepo, cacheRepo, dockerfilesP } func setupTestDir() error { - return os.MkdirAll(testDirPath, 0644) + if err := os.MkdirAll(testDirPath, 0750); err != nil { + return err + } + p := filepath.Join(testDirPath, "foo") + f, err := os.Create(p) + if err != nil { + return err + } + return f.Close() } func generateDockerIgnore() error {