Ver código fonte

delete containers during build after every step

This commit changes the way docker build cleans up containers.
Containers get cleaned up right away after they've been committed and
they've become an image.

When the build fails, only the last container of the failing step is
left behind.

Docker-DCO-1.1-Signed-off-by: Cristian Staretu <cristian.staretu@gmail.com> (github: unclejack)
unclejack 11 anos atrás
pai
commit
7931be5cba
1 arquivos alterados com 3 adições e 3 exclusões
  1. 3 3
      server/buildfile.go

+ 3 - 3
server/buildfile.go

@@ -69,6 +69,7 @@ func (b *buildFile) clearTmp(containers map[string]struct{}) {
 		if err := b.runtime.Destroy(tmp); err != nil {
 			fmt.Fprintf(b.outStream, "Error removing intermediate container %s: %s\n", utils.TruncateID(c), err.Error())
 		} else {
+			delete(containers, c)
 			fmt.Fprintf(b.outStream, "Removing intermediate container %s\n", utils.TruncateID(c))
 		}
 	}
@@ -780,14 +781,13 @@ func (b *buildFile) Build(context io.Reader) (string, error) {
 		}
 		if err := b.BuildStep(fmt.Sprintf("%d", stepN), line); err != nil {
 			return "", err
+		} else if b.rm {
+			b.clearTmp(b.tmpContainers)
 		}
 		stepN += 1
 	}
 	if b.image != "" {
 		fmt.Fprintf(b.outStream, "Successfully built %s\n", utils.TruncateID(b.image))
-		if b.rm {
-			b.clearTmp(b.tmpContainers)
-		}
 		return b.image, nil
 	}
 	return "", fmt.Errorf("No image was generated. This may be because the Dockerfile does not, like, do anything.\n")