Image builder
With the image builder, the SDK builds a task’s container image inside your cluster instead of on the machine that runs flyte run. It runs a build-image task that sends the build to BuildKit and pushes the result to a registry. Before building, the SDK asks Self-Hosted Base whether the image already exists, so an image is built once and reused. Self-Hosted Base sets up the build task itself. You bring BuildKit and the registry, or, on a single-user or evaluation cluster, have the chart run both. Self-Hosted Base doesn’t depend on any of them to start.
Requirements
-
BuildKit, reachable from task pods. BuildKit runs privileged, or rootless on kernels 5.11 and later.
-
A registry that:
- BuildKit can push to without credentials;
- your nodes can pull from, at the same address BuildKit pushed to;
- Self-Hosted Base can read anonymously, possibly at a different address.
Registries that require credentials aren’t supported.
-
Access to the build task’s images. The
build-imagetask runs thebuild-imageimage and has BuildKit use thefrontend-v2image, both published by Union atghcr.io/unionai/imagebuilderwith each release, for amd64 and arm64. The chart uses them at itsappVersionunless you setimageBuilder.taskImages.tag. Nodes must be able to pullbuild-image, and BuildKitfrontend-v2. Without internet access, copy both to a registry of yours, at the chart’sappVersion, and point Self-Hosted Base at it:imageBuilder: taskImages: repository: registry.example.com/imagebuilder # holds build-image and frontend-v2
Run BuildKit and a registry with the chart
imageBuilder.bundled.enabled runs a BuildKit daemon and a registry in Self-Hosted Base’s namespace and points Self-Hosted Base at them:
imageBuilder:
enabled: true
bundled:
enabled: true- BuildKit runs privileged and on the node’s network, listening without TLS on port
imageBuilder.bundled.buildkit.hostPort(30234) of its node, behind a Service on port1234. - The registry listens on NodePort
imageBuilder.bundled.registry.nodePort(30000) of every node and accepts anonymous pushes. BuildKit pushes tolocalhost:30000/oneboxand nodes pull from there, since containerd and BuildKit accept plain HTTP forlocalhost. Self-Hosted Base checks for existing images at the registry’s in-cluster Service. - Images are kept on an
emptyDir, so they’re rebuilt after the registry restarts. SetimageBuilder.bundled.registry.storage(for example20Gi) to keep them on a PersistentVolumeClaim instead;helm uninstallleaves the claim behind.
Any of imageBuilder.buildkitURI, imageBuilder.repository, and imageBuilder.lookupURL you set yourself wins over the bundled address. lookupURL points at the bundled registry only while repository does.
Anything that can reach the bundled BuildKit can run builds as root on its node, and anything that can reach the registry can overwrite images. Don’t use them on a shared cluster.
Bring your own BuildKit and registry
On a shared cluster, run BuildKit rootless, and restrict access to it with a NetworkPolicy that admits only Self-Hosted Base’s namespace: the build-image task connects to BuildKit without client TLS, so a BuildKit that requires mutual TLS can’t be used. Use a registry with TLS. Then point Self-Hosted Base at them:
imageBuilder:
enabled: true
buildkitURI: tcp://buildkit.buildkit.svc:1234 # as task pods reach BuildKit
repository: registry.example.com/union # where nodes pull from
lookupURL: https://registry.example.com/union # where Self-Hosted Base checkslookupURL defaults to https://<repository>; set it when Self-Hosted Base reaches the registry at another address.
Either way, Self-Hosted Base sets up the image builder a few seconds after it starts, and again when its images change. There’s nothing to register by hand. The build task lives in the system project’s production domain, which matters only for troubleshooting (below).
Build an image
Use the remote builder for a run:
flyte --image-builder remote run my_task.py mainor set image.builder: remote in .flyte/config.yaml. The first run builds the image, which takes about half a minute for a small Python image, and later runs skip the build:
i Image localhost:30000/onebox/my-image:3892709e... already exists, skipping buildGotchas
| Symptom | Cause and fix |
|---|---|
remote image builder is not enabled |
The build-image task isn’t registered in system/production yet, or the CLI user can’t read that project. Self-Hosted Base registers it shortly after starting; while it can’t, its log says build-image task not registered yet and why. |
Builds fail with exit code 255 while BuildKit loads the frontend |
BuildKit can’t run the frontend-v2 image on its node’s architecture. With a mirror, copy the image with all its architectures (for example crane copy or docker buildx imagetools create), not just one. |
| Every run rebuilds | Self-Hosted Base can’t read the registry at imageBuilder.lookupURL, or the path differs from imageBuilder.repository. They must name the same repository. |
Task pods fail with ErrImagePull after a successful build |
Nodes can’t pull from imageBuilder.repository. It must resolve and be trusted from the node. |