skaffold icon indicating copy to clipboard operation
skaffold copied to clipboard

[RFC] Support Bazel platform mappings

Open aran opened this issue 2 years ago • 1 comments

This is a proof of concept/RFC to support Bazel platforms in skaffold.

Skaffold uses github.com/opencontainers/image-spec/specs-go/v1 and containerd strings like "linux/amd64" or "linux/arm64/v7" to represent platforms.

Bazel's platform system uses bazel targets to define platforms (https://bazel.build/extending/platforms). While there are common cpu and os definitions available, each Bazel project defines its own target platforms (!)

Currently, when skaffold invokes bazel, skaffold's platform information is not passed to Bazel. Bazel defaults to the host platform, unless the target skaffold is building explicitly specifies a platform.

This change allows a build-level setting for configuring Bazel and defines a platform mapping from Skaffold platforms to Bazel platforms. The Bazel artifact builder then passes the --platforms flag to Bazel if applicable.

This allows a Bazel + Skaffold project to flexibly target multiple platforms.

This PR is intended to start a discussion w/ the Skaffold team on whether this should be supported and if so, how it should be implemented. If there's interest we can discuss moving forward from there. This doesn't include any tests or documentation, and is not intended to be merged as-is.

aran avatar Feb 07 '24 05:02 aran

Looking for some feedback on whether I should drop this change, continue with some modifications to the approach, or continue as-is. Let me know! Thanks.

aran avatar Feb 14 '24 22:02 aran

@renzodavid9 This is the PR we discussed in the Skaffold office hours call at end of Feb. Would be great to get your feedback if you have a chance. Thanks!

aran avatar Mar 13 '24 00:03 aran

Hey @aran,

I'll get familiar with the Bazel platforms to understand more about how they work. Also I'll check if we need to do changes in other parts of Skaffold in order to fully support this. Thanks!

renzodavid9 avatar Mar 13 '24 21:03 renzodavid9

If this looks ok from an API and rough approach standpoint, I can look into details, tests, compliance with Skaffold project standards, etc.

One open edge case question would be how to handle if someone passes --platforms to BazelArtifact BuildArgs as well as PlatformMappings.

Another one would be whether include any special handling for hierarchical skaffold platforms like 'linux/arm64/v8'.

Let me know, thanks!

aran avatar Mar 14 '24 20:03 aran

@renzodavid9 I updated the PR title and top-level comment to meet project guidelines. This is now ready for review.

  • Changes to the configuration are documented to spec.
  • Generated code is checked in.
  • Added unit test.
  • Updated examples/bazel and its duplicate in integration/examples/bazel. These I tested manually.
  • Filed an issue which this closes for project tracking.

aran avatar Mar 22 '24 23:03 aran

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 63.21%. Comparing base (290280e) to head (03f8acc). Report is 1130 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #9300      +/-   ##
==========================================
- Coverage   70.48%   63.21%   -7.28%     
==========================================
  Files         515      642     +127     
  Lines       23150    32989    +9839     
==========================================
+ Hits        16317    20853    +4536     
- Misses       5776    10527    +4751     
- Partials     1057     1609     +552     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar Mar 26 '24 18:03 codecov[bot]