瀏覽代碼

builder/dockerfile: remove containerManager.removeContainer()

This was just a very thin wrapper for backend.ContainerRm(), and the
error it returned was not handled, so moving this code inline.

Moving it inline also allows differentiating the error message to
distinguish the "removing all intermediate containers" from "removing container"
(when cancelling a build).

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Sebastiaan van Stijn 3 年之前
父節點
當前提交
03a8188a9a
共有 1 個文件被更改,包括 6 次插入14 次删除
  1. 6 14
      builder/dockerfile/containerbackend.go

+ 6 - 14
builder/dockerfile/containerbackend.go

@@ -62,7 +62,10 @@ func (c *containerManager) Run(ctx context.Context, cID string, stdout, stderr i
 		case <-ctx.Done():
 		case <-ctx.Done():
 			log.G(ctx).Debugln("Build cancelled, killing and removing container:", cID)
 			log.G(ctx).Debugln("Build cancelled, killing and removing container:", cID)
 			c.backend.ContainerKill(cID, "")
 			c.backend.ContainerKill(cID, "")
-			c.removeContainer(cID, stdout)
+			err = c.backend.ContainerRm(cID, &backend.ContainerRmConfig{ForceRemove: true, RemoveVolume: true})
+			if err != nil {
+				_, _ = fmt.Fprintf(stdout, "Removing container %s: %v\n", stringid.TruncateID(cID), err)
+			}
 			cancelErrCh <- errCancelled
 			cancelErrCh <- errCancelled
 		case <-finished:
 		case <-finished:
 			cancelErrCh <- nil
 			cancelErrCh <- nil
@@ -122,22 +125,11 @@ func (e *statusCodeError) StatusCode() int {
 	return e.code
 	return e.code
 }
 }
 
 
-func (c *containerManager) removeContainer(containerID string, stdout io.Writer) error {
-	rmConfig := &backend.ContainerRmConfig{
-		ForceRemove:  true,
-		RemoveVolume: true,
-	}
-	if err := c.backend.ContainerRm(containerID, rmConfig); err != nil {
-		fmt.Fprintf(stdout, "Error removing intermediate container %s: %v\n", stringid.TruncateID(containerID), err)
-		return err
-	}
-	return nil
-}
-
 // RemoveAll containers managed by this container manager
 // RemoveAll containers managed by this container manager
 func (c *containerManager) RemoveAll(stdout io.Writer) {
 func (c *containerManager) RemoveAll(stdout io.Writer) {
 	for containerID := range c.tmpContainers {
 	for containerID := range c.tmpContainers {
-		if err := c.removeContainer(containerID, stdout); err != nil {
+		if err := c.backend.ContainerRm(containerID, &backend.ContainerRmConfig{ForceRemove: true, RemoveVolume: true}); err != nil {
+			_, _ = fmt.Fprintf(stdout, "Removing intermediate container %s: %v\n", stringid.TruncateID(containerID), err)
 			return
 			return
 		}
 		}
 		delete(c.tmpContainers, containerID)
 		delete(c.tmpContainers, containerID)