Upadte archive.ReplaceFileTarWrapper() to not expect a sorted archive

Improve test coverage of ReplaceFileTarWrapper()

Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
Daniel Nephin 2017-04-05 18:25:29 -04:00
parent 596cd38a6e
commit b30ad6dc6e
1 changed files with 12 additions and 12 deletions

View File

@ -218,13 +218,14 @@ func runBuild(dockerCli *command.DockerCli, options buildOptions) error {
return errors.Errorf("Error checking context: '%s'.", err) return errors.Errorf("Error checking context: '%s'.", err)
} }
// If .dockerignore mentions .dockerignore or the Dockerfile // If .dockerignore mentions .dockerignore or the Dockerfile then make
// then make sure we send both files over to the daemon // sure we send both files over to the daemon because Dockerfile is,
// because Dockerfile is, obviously, needed no matter what, and // obviously, needed no matter what, and .dockerignore is needed to know
// .dockerignore is needed to know if either one needs to be // if either one needs to be removed. The daemon will remove them
// removed. The daemon will remove them for us, if needed, after it // if necessary, after it parses the Dockerfile. Ignore errors here, as
// parses the Dockerfile. Ignore errors here, as they will have been // they will have been caught by validateContextDirectory above.
// 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 { if keep, _ := fileutils.Matches(".dockerignore", excludes); keep {
excludes = append(excludes, "!.dockerignore") excludes = append(excludes, "!.dockerignore")
} }
@ -384,17 +385,16 @@ func addDockerfileToBuildContext(dockerfileCtx io.ReadCloser, buildCtx io.ReadCl
if h == nil { if h == nil {
h = hdrTmpl h = hdrTmpl
} }
extraIgnore := randomName + "\n"
b := &bytes.Buffer{} b := &bytes.Buffer{}
if content != nil { if content != nil {
_, err := b.ReadFrom(content) if _, err := b.ReadFrom(content); err != nil {
if err != nil {
return nil, nil, err return nil, nil, err
} }
} else { } else {
extraIgnore += ".dockerignore\n" b.WriteString(".dockerignore")
} }
b.Write([]byte("\n" + extraIgnore)) b.WriteString("\n" + randomName + "\n")
return h, b.Bytes(), nil return h, b.Bytes(), nil
}, },
}) })