소스 검색

Merge pull request #33824 from ijc/build-iidfile-with-squash

builder: Emit a BuildResult after squashing.
Vincent Demeester 8 년 전
부모
커밋
b8766fe793
2개의 변경된 파일34개의 추가작업 그리고 0개의 파일을 삭제
  1. 5 0
      api/server/backend/build/backend.go
  2. 29 0
      integration-cli/docker_cli_build_test.go

+ 5 - 0
api/server/backend/build/backend.go

@@ -55,6 +55,11 @@ func (b *Backend) Build(ctx context.Context, config backend.BuildConfig) (string
 		if imageID, err = squashBuild(build, b.imageComponent); err != nil {
 		if imageID, err = squashBuild(build, b.imageComponent); err != nil {
 			return "", err
 			return "", err
 		}
 		}
+		if config.ProgressWriter.AuxFormatter != nil {
+			if err = config.ProgressWriter.AuxFormatter.Emit(types.BuildResult{ID: imageID}); err != nil {
+				return "", err
+			}
+		}
 	}
 	}
 
 
 	stdout := config.ProgressWriter.StdoutFormatter
 	stdout := config.ProgressWriter.StdoutFormatter

+ 29 - 0
integration-cli/docker_cli_build_test.go

@@ -6459,3 +6459,32 @@ func (s *DockerSuite) TestBuildIidFileCleanupOnFail(c *check.C) {
 	c.Assert(err, check.NotNil)
 	c.Assert(err, check.NotNil)
 	c.Assert(os.IsNotExist(err), check.Equals, true)
 	c.Assert(os.IsNotExist(err), check.Equals, true)
 }
 }
+
+func (s *DockerSuite) TestBuildIidFileSquash(c *check.C) {
+	testRequires(c, ExperimentalDaemon)
+	tmpDir, err := ioutil.TempDir("", "TestBuildIidFileSquash")
+	if err != nil {
+		c.Fatal(err)
+	}
+	defer os.RemoveAll(tmpDir)
+	tmpIidFile := filepath.Join(tmpDir, "iidsquash")
+
+	name := "testbuildiidfilesquash"
+	// Use a Dockerfile with multiple stages to ensure we get the last one
+	cli.BuildCmd(c, name,
+		// This could be minimalBaseImage except
+		// https://github.com/moby/moby/issues/33823 requires
+		// `touch` to workaround.
+		build.WithDockerfile(`FROM busybox
+ENV FOO FOO
+ENV BAR BAR
+RUN touch /foop
+`),
+		cli.WithFlags("--iidfile", tmpIidFile, "--squash"))
+
+	id, err := ioutil.ReadFile(tmpIidFile)
+	c.Assert(err, check.IsNil)
+	d, err := digest.Parse(string(id))
+	c.Assert(err, check.IsNil)
+	c.Assert(d.String(), checker.Equals, getIDByName(c, name))
+}