Skip to content

Conversation

@bossmc
Copy link
Contributor

@bossmc bossmc commented Aug 19, 2021

See #621. I needed this in order to script logic of the following structure (where I didn't want to use a temporary file on disk for --iidfile):

$ image=$(docker build --quiet .)
$ docker run $image

This worked unless someone had installed buildx in place of docker build (as I had 😛 ) in which case the image was an empty string and the docker run failed catastrophically.

@bossmc
Copy link
Contributor Author

bossmc commented Aug 20, 2021

@tonistiigi - Thanks for the review, I've updated the change (to pass the digest back to the main command driver and manipulate stdout there).

Possibly this is slightly presumptuous - it assumes that the target is called default and that the Exporter will add a containerimage.digest field. The former is already assumed earlier in buildTargets and the latter is assumed in build.Build so I think these are safe assumptions/guaranteed.

}

if in.quiet && in.progress != "auto" && in.progress != "quiet" {
return errors.Errorf("progress=%s and quiet cannot be used together", in.progress)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this should be an error. Maybe -q just overrides. Thinking of scripts where different components add their flags.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My thinking was that explicitly asking for "fancy output"/"streamed output" and "no output" was user-error and should be rejected, can a component add a new --progress type?.

I allowed the user to pass --progress=quiet -q which is (possibly surprisingly) different to passing --progress=quiet on its own (the former doesn't print the digest at the end), since that's not contradictory.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought for a case where --progress=plain is used to not detect tty and then another part does not want progress at all.

@tonistiigi tonistiigi requested a review from crazy-max September 2, 2021 21:11
respMu.Unlock()
if len(res) == 1 {
digest := res[0].ExporterResponse["containerimage.digest"]
if opt.ImageIDFile != "" {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe error out if digest is empty

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previous code would have written an empty file to --iidfile in this case, changing that to an error would be an externally visible change.

In fact, looking at the code now, none of the changes in this file are actually needed, they're just a refactor due to me originally printing the digest here (and hence pulling the digest out for printing/writing to the --iidfile).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe best in this case would be to always set -o type=image if image id is to be exported, either with iidfile, or q. And error if another conflicting output is already set. This can be follow-up though as strictly related.

@tonistiigi tonistiigi merged commit b05c313 into docker:master Sep 3, 2021
@bossmc bossmc deleted the support-quiet branch September 3, 2021 18:04
@codazzo
Copy link

codazzo commented Oct 20, 2021

Thanks for implementing this feature! I was wondering if a release which includes it is in the pipeline?

[UPDATE 2021-11-05] Shipped! https://github.com/docker/buildx/releases/tag/v0.7.0-rc1

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.

5 participants