Skip to content

cli/command/image: trim iidfile image ID and fail clearly when missing - #7279

Open
HarnageaGabriel wants to merge 1 commit into
docker:masterfrom
HarnageaGabriel:claude/sharp-leakey-1097af
Open

cli/command/image: trim iidfile image ID and fail clearly when missing#7279
HarnageaGabriel wants to merge 1 commit into
docker:masterfrom
HarnageaGabriel:claude/sharp-leakey-1097af

Conversation

@HarnageaGabriel

Copy link
Copy Markdown
  • What I did

When docker build --iidfile <file> is used, runBuild picks up the
resulting image ID from the daemon's aux message or, in quiet mode,
from the build output, and writes it to the file as-is.

That has two rough edges:

  • the quiet-mode value can carry surrounding whitespace / a trailing
    newline, which then lands in the iidfile and is misread by tools that
    consume it;
  • an all-whitespace value slipped past the old imageID == "" check and
    was written out as an effectively empty file.

This trims the value before use and treats an empty result as "no image
ID", returning a clear error rather than writing a broken file.

  • Related issue

Addresses the failure mode in #2971 ("cannot write /tmp/... because
server did not provide an image ID"), where parallel Compose builds
sharing an iidfile — or older daemons — could leave the CLI without an
ID. The CLI can't invent an ID it wasn't given, but it now fails
predictably and never leaves a bogus iidfile behind (the file is already
pre-removed before the build).

  • How to test
go test ./cli/command/image/ -run TestRunBuild

New tests:

  • TestRunBuildWithIidFileWritesImageID — an aux ID is written to the
    iidfile with no surrounding whitespace;

  • TestRunBuildWithoutImageIDReturnsError — no ID from the daemon yields
    an error and no iidfile is created.

  • Description for the changelog

Fix docker build --iidfile writing a stray newline into the image ID
file, and give a clear error when the daemon returns no image ID.

When building with `--iidfile`, the CLI takes the resulting image ID
either from the daemon's "aux" message or, in quiet mode, from the build
output, then writes it verbatim to the file.

Two problems with that:

- The quiet-mode value can carry surrounding whitespace/newlines, which
  then end up in the iidfile and get misread by downstream tooling.
- An all-whitespace value passed the previous `imageID == ""` guard and
  was written as a bogus (effectively empty) file.

Trim the value before using it and treat an empty result as "no image
ID", returning a clear error instead of writing a broken file. This is
the situation reported in docker#2971, where parallel builds sharing
an iidfile (or older daemons) could leave the CLI without an ID.

Signed-off-by: Gabriel Harnagea <gabriel.harnagea06@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant