Fix workdir cache invalidation

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
(cherry picked from commit e160860054)
Signed-off-by: Victor Vieux <vieux@docker.com>
This commit is contained in:
Tonis Tiigi 2017-01-06 11:55:37 -08:00 committed by Victor Vieux
parent b2e12626c7
commit 7c8511236c
2 changed files with 13 additions and 7 deletions

View file

@ -297,17 +297,19 @@ func workdir(b *Builder, args []string, attributes map[string]bool, original str
}
b.runConfig.Image = b.image
cmd := b.runConfig.Cmd
comment := "WORKDIR " + b.runConfig.WorkingDir
// reset the command for cache detection
b.runConfig.Cmd = strslice.StrSlice(append(getShell(b.runConfig), "#(nop) "+comment))
defer func(cmd strslice.StrSlice) { b.runConfig.Cmd = cmd }(cmd)
if hit, err := b.probeCache(); err != nil {
return err
} else if hit {
return nil
}
// Actually copy the struct
workdirConfig := *b.runConfig
workdirConfig.Cmd = strslice.StrSlice(append(getShell(b.runConfig), fmt.Sprintf("#(nop) WORKDIR %s", b.runConfig.WorkingDir)))
container, err := b.docker.ContainerCreate(types.ContainerCreateConfig{Config: &workdirConfig})
container, err := b.docker.ContainerCreate(types.ContainerCreateConfig{Config: b.runConfig})
if err != nil {
return err
}
@ -316,7 +318,7 @@ func workdir(b *Builder, args []string, attributes map[string]bool, original str
return err
}
return b.commit(container.ID, b.runConfig.Cmd, "WORKDIR "+b.runConfig.WorkingDir)
return b.commit(container.ID, cmd, comment)
}
// RUN some command yo

View file

@ -7394,6 +7394,10 @@ func (s *DockerSuite) TestBuildWorkdirCmd(c *check.C) {
FROM golang:1.7-alpine
WORKDIR /
`
_, err := buildImage("testbuildworkdircmd", dockerFile, false)
_, err := buildImage("testbuildworkdircmd", dockerFile, true)
c.Assert(err, checker.IsNil)
_, out, err := buildImageWithOut("testbuildworkdircmd", dockerFile, true)
c.Assert(err, checker.IsNil)
c.Assert(strings.Count(out, "Using cache"), checker.Equals, 1)
}