Skip to content

Commit

Permalink
Fix integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Priya Wadhwa committed Oct 19, 2018
1 parent 3fc43f4 commit efa3321
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
6 changes: 5 additions & 1 deletion cmd/executor/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
},
Expand Down Expand Up @@ -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)
}
}
Expand All @@ -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)
Expand Down
12 changes: 9 additions & 3 deletions integration/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -55,7 +55,7 @@ var argsMap = map[string][]string{
"Dockerfile_test_multistage": {"file=/foo2"},
}

var filesToIgnore = []string{"test/*"}
var filesToIgnore = []string{"test"}

// Arguments to build Dockerfiles with when building with docker
var additionalDockerFlagsMap = map[string][]string{
Expand Down Expand Up @@ -271,11 +271,17 @@ func (d *DockerFileBuilder) buildCachedImages(imageRepo, cacheRepo, dockerfilesP
}

func setupTestDir() error {
p := filepath.Join(testDirPath, "foo")
f, err := os.Create(p)
if err != nil {
return err
}
defer f.Close()
return os.MkdirAll(testDirPath, 0644)
}

func generateDockerIgnore() error {
f, err := os.Create(".dockerignore")
f, err := os.Create("context/.dockerignore")
if err != nil {
return err
}
Expand Down

0 comments on commit efa3321

Please sign in to comment.