When building images, some platform-specific configurations are often required. For example, when working with uv, arm* builds require some flags to be set to prevent CPU thrashing during dependency installation.
How does one apply platform-specific changes to multiu-platform build stages in the Docker Bake HCL/yaml syntax?
You have to implement the logic somewhere and even if you do it in a bake file, you would need to implement something in the Dockerfile to make it possible. For example you can use a build argument in a Dockerfile and use it in a command like:
FROM alpine:latest
ARG PLATFORM_FLAGS
RUN echo mycommand "$PLATFORM_FLAGS" --common-flag1 --common-flag2 > /command.txt
CMD ["cat", "/command.txt"]
You could also change the condition to rely on built in variables like BAKE_LOCAL_PLATFORM but it would not help on macOS while building linux container images, because the local platfomrm would be your client’s platfom