-
Notifications
You must be signed in to change notification settings - Fork 494
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(driver/kubernetes): support mount buildkit.toml and qemu installing
Signed-off-by: Morlay <[email protected]>
- Loading branch information
Showing
9 changed files
with
266 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
docs/reference/buildx_create_for_multi_arch_build_in_k8s.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# Buildx create for multi-arch builds in k8s | ||
|
||
## With QEMU emulation | ||
|
||
```console | ||
$ KUBECONFIG=${KUBECONFIG} \ | ||
docker buildx create \ | ||
--name=builder \ | ||
--platform=linux/amd64,linux/arm64 \ | ||
--driver=kubernetes \ | ||
--driver-opt=namespace=buildkit,withqemu=true | ||
``` | ||
|
||
### Known Issues | ||
|
||
QEUM is only work well for `executing`, but for `compiling`, it wil be very slow and may be panic. | ||
|
||
In the mode, if still want to compile binaries in docker. | ||
please use `FROM --platform=${BUILDPLATFORM}` to disable QEUM for compiling stage. | ||
|
||
Example for golang: | ||
``` | ||
FROM --platform=${BUILDPLATFORM} golang:1.6 as builder | ||
ARG TARGETARCH | ||
RUN GOARCH=${TARGETARCH} go build -o /bin/app-linux-${TARGETARCH} ./path/to/cmd/app | ||
FROM scratch | ||
ARG TARGETARCH | ||
COPY --from=builder /bin/app-linux-${TARGETARCH} /bin/app | ||
``` | ||
|
||
## With native nodes | ||
|
||
```console | ||
# create builder `builder` and add native x86_64 node | ||
$ KUBECONFIG=${KUBECONFIG} \ | ||
docker buildx create \ | ||
--name=builder \ | ||
--platform=linux/amd64 \ | ||
--node=builder-amd64 \ | ||
--driver=kubernetes \ | ||
--driver-opt=namespace=buildkit,nodeselector="beta.kubernetes.io/arch=amd64" | ||
|
||
# append node to same builder with native aarch64 node | ||
$ KUBECONFIG=${KUBECONFIG} \ | ||
docker buildx create \ | ||
--name=builder --append \ | ||
--platform=linux/arm64 \ | ||
--node=builder-arm64 \ | ||
--driver=kubernetes \ | ||
--driver-opt=namespace=buildkit,nodeselector="beta.kubernetes.io/arch=arm64" | ||
``` | ||
|
||
* `KUBECONFIG` could be different. | ||
* `buildx create` executing on a pod of multi-arch cluster, `KUBECONFIG` could be unset, but make sure the pod `serviceAccount` could access `deplopments,pods,configmaps` of assigned `namespace` | ||
|
||
### Known Issues | ||
|
||
In this mode, docker build for different arch on matched native host. | ||
The build time may be longer. | ||
Even `FROM --platform=${BUILDPLATFORM}` defined, all stages will build for each arch. | ||
|
||
However, it is totally native. | ||
Projects, witch needs to build on native system, will be happy with the mode. | ||
|
||
## Tips | ||
|
||
Once `buildx create` in k8s, the created deployments will not be removed until `buildx rm` called. | ||
So we could set `RUN --mount=type=cache` for sharing common caches for different projects. | ||
|
||
However, For nodejs user. | ||
Don't shared `npm` or `yarn` global caches (`pnpm` will be better), restoring caches may be slower than reinstalling. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.