With Buildkit, don't pull docker images needlessly.
When using Docker with Buildkit and inline cache information enabled, docker build will pull image layers to use as cache on demand. As a result, unconditionally pulling the cache is both superfluous and slower, so let's not do that.
I would, but the suggested changes do not produce the desired behaviour. There is no situation where removing the cache-from argument does what we want, and that is what the suggested changes do. Please let me know if there's something from my previous comment that isn't clear about this, or if you have a different suggestion.
the code in my comment is pseudo code, so please feel free to adjust the logic as needed. The request is to break out into a helper function to improve readability (bonus points for adding a unit test) to help make the code easier to understand.
Sure, I can move the pre-pull determination into a helper function.