buildkit icon indicating copy to clipboard operation
buildkit copied to clipboard

dockerfile: expose TARGETSTAGE as builtin argument

Open tonistiigi opened this issue 1 year ago • 7 comments

closes https://github.com/docker/buildx/issues/2646

Allows capturing what build stage is currently being built for patterns with better base stage reuse.

tonistiigi avatar Oct 16 '24 19:10 tonistiigi

This probably needs documentation changes to add this to the list of builtin args? 😅

thaJeztah avatar Oct 16 '24 19:10 thaJeztah

@ByteNybbler, any input on the comments above?

tonistiigi avatar Oct 18 '24 04:10 tonistiigi

Yes, thank you so much for working on this! I'm very excited to have access to this feature!

ByteNybbler avatar Oct 18 '24 16:10 ByteNybbler

Would setting a value by default (if not set) make it harder to do constructs where the user wants to set a default value? echo ${TARGETSTAGE:-development} (or similar constructs)

thaJeztah avatar Oct 18 '24 17:10 thaJeztah

Would setting a value by default (if not set) make it harder to do constructs where the user wants to set a default value? echo ${TARGETSTAGE:-development} (or similar constructs)

Yeah, but if you look at the current TARGET* BUILD* default args then they are also always guaranteed to have a defined value. So I think it is more consistent this way, where it is always set by the builder and not left for the user to initialize in any case.

tonistiigi avatar Oct 18 '24 17:10 tonistiigi

The only time TARGETSTAGE could ever use some possible default value (at least for how I'm imagining this will work) would be when the final build stage is unnamed in the Dockerfile. If the user wants to control the "default" value of TARGETSTAGE, they can do that by giving the final build stage an appropriate name in the Dockerfile, since the final build stage is what docker build targets by default when no --target option is provided. TARGETSTAGE should match the name of that target.

ByteNybbler avatar Oct 18 '24 18:10 ByteNybbler

Updated to read the default stage name from Dockerfile if not passed by the user.

tonistiigi avatar Oct 19 '24 00:10 tonistiigi