Bläddra i källkod

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 år sedan
förälder
incheckning
03a8188a9a
1 ändrade filer med 6 tillägg och 14 borttagningar
  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():
 			log.G(ctx).Debugln("Build cancelled, killing and removing container:", 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
 		case <-finished:
 			cancelErrCh <- nil
@@ -122,22 +125,11 @@ func (e *statusCodeError) StatusCode() int {
 	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
 func (c *containerManager) RemoveAll(stdout io.Writer) {
 	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
 		}
 		delete(c.tmpContainers, containerID)