From b30ad6dc6e29179abcf2c8b409c534b53ab18103 Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Wed, 5 Apr 2017 18:25:29 -0400 Subject: [PATCH] Upadte archive.ReplaceFileTarWrapper() to not expect a sorted archive Improve test coverage of ReplaceFileTarWrapper() Signed-off-by: Daniel Nephin --- command/image/build.go | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/command/image/build.go b/command/image/build.go index 965acb4b51..5268cbc254 100644 --- a/command/image/build.go +++ b/command/image/build.go @@ -218,13 +218,14 @@ func runBuild(dockerCli *command.DockerCli, options buildOptions) error { return errors.Errorf("Error checking context: '%s'.", err) } - // If .dockerignore mentions .dockerignore or the Dockerfile - // then make sure we send both files over to the daemon - // because Dockerfile is, obviously, needed no matter what, and - // .dockerignore is needed to know if either one needs to be - // removed. The daemon will remove them for us, if needed, after it - // parses the Dockerfile. Ignore errors here, as they will have been - // caught by validateContextDirectory above. + // If .dockerignore mentions .dockerignore or the Dockerfile then make + // sure we send both files over to the daemon because Dockerfile is, + // obviously, needed no matter what, and .dockerignore is needed to know + // if either one needs to be removed. The daemon will remove them + // if necessary, after it parses the Dockerfile. Ignore errors here, as + // they will have been caught by validateContextDirectory above. + // Excludes are used instead of includes to maintain the order of files + // in the archive. if keep, _ := fileutils.Matches(".dockerignore", excludes); keep { excludes = append(excludes, "!.dockerignore") } @@ -384,17 +385,16 @@ func addDockerfileToBuildContext(dockerfileCtx io.ReadCloser, buildCtx io.ReadCl if h == nil { h = hdrTmpl } - extraIgnore := randomName + "\n" + b := &bytes.Buffer{} if content != nil { - _, err := b.ReadFrom(content) - if err != nil { + if _, err := b.ReadFrom(content); err != nil { return nil, nil, err } } else { - extraIgnore += ".dockerignore\n" + b.WriteString(".dockerignore") } - b.Write([]byte("\n" + extraIgnore)) + b.WriteString("\n" + randomName + "\n") return h, b.Bytes(), nil }, })