1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

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 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 { if hit, err := b.probeCache(); err != nil {
return err return err
} else if hit { } else if hit {
return nil return nil
} }
// Actually copy the struct container, err := b.docker.ContainerCreate(types.ContainerCreateConfig{Config: b.runConfig})
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})
if err != nil { if err != nil {
return err return err
} }
@ -316,7 +318,7 @@ func workdir(b *Builder, args []string, attributes map[string]bool, original str
return err 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 // RUN some command yo

View file

@ -7394,6 +7394,10 @@ func (s *DockerSuite) TestBuildWorkdirCmd(c *check.C) {
FROM golang:1.7-alpine FROM golang:1.7-alpine
WORKDIR / WORKDIR /
` `
_, err := buildImage("testbuildworkdircmd", dockerFile, false) _, err := buildImage("testbuildworkdircmd", dockerFile, true)
c.Assert(err, checker.IsNil) 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)
} }