docker / buildx

Docker CLI plugin for extended build capabilities with BuildKit
Apache License 2.0
3.55k stars 481 forks source link

proposal: use create --platform to set default platforms #326

Open tonistiigi opened 4 years ago

tonistiigi commented 4 years ago

Currently buildx create --platform can be used to set manual platforms for the builder instance. This is used to find a node for a specific platform if multiple nodes support it. Eg. your laptop supports arm via emulation but aws node supports it natively so you set aws node's platform manually to ensure arm workloads go there.

The proposal is to add an additional meaning to this field. If buildx build is used without a build specific --platform flag it could (instead of sending the request without a platform to the first node) build for all the platforms that were manually set on create. This allows to create a builder instance that creates multi-platform images by default.

@tiborvass @cpuguy83 @AkihiroSuda wdyt?

AkihiroSuda commented 4 years ago

SGTM

cpuguy83 commented 4 years ago

Just a thought, what if instead --platform=all is a shortcut for that does that as an opt-in?

tiborvass commented 4 years ago

For a second, forget about platforms, assume same platform everywhere.

I think that there are two ideal default behaviors for building on a builder with arbitrary set of nodes:

Today it's neither: we just select the first one in the list, but it may be useful to keep this in mind for future defaults.

Now if you add the platform dimension and consider the scheduling based on least busy policy, the only usecase I can think of is if users can both natively compile and cross compile their code, and want to mix expensive but fast architectures with cheaper but slower architectures, because they found a sweet spot tradeoff between time and cost they could only achieve with different architectures. This is basically platform-agnostic scheduling.

  1. do we care if we do not support that usecase at all and forever?
  2. if we do want to support it, can we think of a UX for it other than defaulting to such a niche case?
tiborvass commented 4 years ago

If 1. is no or 2. is yes then I don't think we need --platform=all and we can simply default to it.

cpuguy83 commented 4 years ago

I do not think a nodes capability to build a platform should be implicitly tied to a projects to desire to be built on those platforms.

tonistiigi commented 4 years ago

@cpuguy83 I agree but using --platform on create is not required for nodes capability to build a platform. If you don't set it, it will still be detected and works fine. So it is already a sort of opt-in action.

cpuguy83 commented 4 years ago

@tonistiigi Perahps so... What if a you can define the default list on the buildx context... and maybe an unset default is all the platforms?