Fix cancel build doesn't remove the intermediate container
Signed-off-by: Lei Jitang <leijitang@huawei.com>
This commit is contained in:
parent
0f00c36d65
commit
9392de9dfe
1 changed files with 15 additions and 7 deletions
|
@ -557,8 +557,9 @@ func (b *Builder) run(c *daemon.Container) error {
|
||||||
go func() {
|
go func() {
|
||||||
select {
|
select {
|
||||||
case <-b.cancelled:
|
case <-b.cancelled:
|
||||||
logrus.Debugln("Build cancelled, killing container:", c.ID)
|
logrus.Debugln("Build cancelled, killing and removing container:", c.ID)
|
||||||
c.Kill()
|
c.Kill()
|
||||||
|
b.removeContainer(c.ID)
|
||||||
case <-finished:
|
case <-finished:
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
@ -582,14 +583,21 @@ func (b *Builder) run(c *daemon.Container) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b *Builder) removeContainer(c string) error {
|
||||||
|
rmConfig := &daemon.ContainerRmConfig{
|
||||||
|
ForceRemove: true,
|
||||||
|
RemoveVolume: true,
|
||||||
|
}
|
||||||
|
if err := b.docker.Remove(c, rmConfig); err != nil {
|
||||||
|
fmt.Fprintf(b.Stdout, "Error removing intermediate container %s: %v\n", stringid.TruncateID(c), err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (b *Builder) clearTmp() {
|
func (b *Builder) clearTmp() {
|
||||||
for c := range b.tmpContainers {
|
for c := range b.tmpContainers {
|
||||||
rmConfig := &daemon.ContainerRmConfig{
|
if err := b.removeContainer(c); err != nil {
|
||||||
ForceRemove: true,
|
|
||||||
RemoveVolume: true,
|
|
||||||
}
|
|
||||||
if err := b.docker.Remove(c, rmConfig); err != nil {
|
|
||||||
fmt.Fprintf(b.Stdout, "Error removing intermediate container %s: %v\n", stringid.TruncateID(c), err)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
delete(b.tmpContainers, c)
|
delete(b.tmpContainers, c)
|
||||||
|
|
Loading…
Reference in a new issue