Bazel
Bazel is a fast, scalable, multi-language, and extensible build system.
Skaffold can help build artifacts using Bazel locally; after Bazel finishes building container images, they will be loaded into the local Docker daemon.
Configuration
To use Bazel, bazel
field to each artifact you specify in the
artifacts
part of the build
section, and use the build type local
.
context
should be a path containing the bazel files
(WORKSPACE
and BUILD
). The following options can optionally be configured:
Option | Description | Default |
---|---|---|
target |
Required bazel build target to run. |
|
args |
additional args to pass to bazel build . |
[] |
platforms |
configure the –platforms flag for bazel build based on the configured skaffold target platform. |
|
Not any Bazel target can be used
The target specified must produce a .tar bundle compatible with docker load. See https://github.com/bazelbuild/rules_docker#using-with-docker-locallyExample
The following build
section instructs Skaffold to build a
Docker image gcr.io/k8s-skaffold/example
with Bazel:
build:
artifacts:
- image: gcr.io/k8s-skaffold/example
bazel:
target: //:example.tar
The following build
section shows how to use Skaffold’s
cross-platform support to pass --platforms
to Bazel. In this
example, the Bazel project defines the //platforms:linux-x86_64
//platforms:linux-arm64
targets. Skaffold will pass --platforms=//platforms:linux-x86_64
to bazel build
if its target build platform matches linux/amd64
, --platforms=//platforms:linux-arm64
if its target build platform matches linux/arm64
, and will not pass --platforms
otherwise.
build:
artifacts:
- image: gcr.io/k8s-skaffold/example
bazel:
target: //:example.tar
platforms:
- platform: linux/amd64
target: //platforms:linux-x86_64
- platform: linux/arm64
target: //platforms:linux-arm64
Note that Skaffold does not support intelligently selecting the most specific
variant for platforms with variants. For example, specifying linux/arm64
and linux/arm64/v8
will not work. In this example it would be better to
specify linux/arm64/v7
and linux/arm64/v8
instead.