cli/command/image: trim iidfile image ID and fail clearly when missing - #7279
Open
HarnageaGabriel wants to merge 1 commit into
Open
cli/command/image: trim iidfile image ID and fail clearly when missing#7279HarnageaGabriel wants to merge 1 commit into
HarnageaGabriel wants to merge 1 commit into
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When
docker build --iidfile <file>is used,runBuildpicks up theresulting image ID from the daemon's
auxmessage or, in quiet mode,from the build output, and writes it to the file as-is.
That has two rough edges:
newline, which then lands in the iidfile and is misread by tools that
consume it;
imageID == ""check andwas 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.
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).
New tests:
TestRunBuildWithIidFileWritesImageID— anauxID is written to theiidfile with no surrounding whitespace;
TestRunBuildWithoutImageIDReturnsError— no ID from the daemon yieldsan error and no iidfile is created.
Description for the changelog
Fix
docker build --iidfilewriting a stray newline into the image IDfile, and give a clear error when the daemon returns no image ID.