Skip to content

Commit

Permalink
Merge pull request moby#33824 from ijc/build-iidfile-with-squash
Browse files Browse the repository at this point in the history
builder: Emit a BuildResult after squashing.
  • Loading branch information
Vincent Demeester authored Jun 30, 2017
2 parents 82390eb + 9777ec3 commit b8766fe
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
5 changes: 5 additions & 0 deletions api/server/backend/build/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ func (b *Backend) Build(ctx context.Context, config backend.BuildConfig) (string
if imageID, err = squashBuild(build, b.imageComponent); err != nil {
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
Expand Down
29 changes: 29 additions & 0 deletions integration-cli/docker_cli_build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6459,3 +6459,32 @@ func (s *DockerSuite) TestBuildIidFileCleanupOnFail(c *check.C) {
c.Assert(err, check.NotNil)
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))
}

0 comments on commit b8766fe

Please sign in to comment.