Skip to content

Commit

Permalink
chore: remove kaniko from supported multi-platform builders
Browse files Browse the repository at this point in the history
  • Loading branch information
twelvemo committed Jun 24, 2024
1 parent 8a9b299 commit c99f9b8
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 7 deletions.
1 change: 0 additions & 1 deletion core/src/plugins/container/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,6 @@ export function getDockerBuildFlags(
if (targetStage) {
args.push("--target", targetStage)
}

for (const platform of platforms || []) {
args.push("--platform", platform)
}
Expand Down
4 changes: 4 additions & 0 deletions core/src/plugins/container/cloudbuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ const cloudBuilderAvailability = new LRUCache<string, CloudBuilderAvailability>(

// public API
export const cloudBuilder = {
isConfigured(ctx: PluginContext) {
const { isCloudBuilderEnabled } = getConfiguration(ctx)
return isCloudBuilderEnabled
},
/**
* @returns false if Cloud Builder is not configured or not available, otherwise it returns the availability (a required parameter for withBuilder)
*/
Expand Down
4 changes: 2 additions & 2 deletions core/src/plugins/container/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ export const publishContainerBuild: BuildActionHandler<"publish", ContainerBuild
const containerCtx = ctx as ContainerPluginContext
const localImageId = action.getOutput("localImageId")
const remoteImageId = containerHelpers.getPublicImageId(action, tagOverride)
const cloudBuilderUsed = await cloudBuilder.getAvailability(containerCtx, action)
const cloudBuilderConfigured = cloudBuilder.isConfigured(containerCtx)
const dockerBuildExtraFlags = action.getSpec("extraFlags")

// If cloud builder is used or --push flag is set explicitly, use regctl to copy the image.
// This does not require to pull the image locally.
if (cloudBuilderUsed.available || dockerBuildExtraFlags?.includes("--push")) {
if (cloudBuilderConfigured || dockerBuildExtraFlags?.includes("--push")) {
const regctlCopyCommand = ["image", "copy", localImageId, remoteImageId]
log.info({ msg: `Publishing image ${remoteImageId}` })
await containerHelpers.regctlCli({ cwd: action.getBuildPath(), args: regctlCopyCommand, log, ctx })
Expand Down
4 changes: 4 additions & 0 deletions core/src/plugins/kubernetes/container/build/buildkit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,10 @@ export function getBuildkitFlags(action: Resolved<ContainerBuildAction>) {
args.push("--opt", "target=" + spec.targetStage)
}

for (const platform of spec.platforms || []) {
args.push("--opt", "platform=" + platform)
}

args.push(...(spec.extraFlags || []))

return args
Expand Down
10 changes: 10 additions & 0 deletions core/src/plugins/kubernetes/container/build/kaniko.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,16 @@ export const kanikoBuild: BuildHandler = async (params) => {
const deploymentImageId = outputs.deploymentImageId
const dockerfile = spec.dockerfile || defaultDockerfileName

const platforms = action.getSpec().platforms
if (platforms && platforms.length > 1) {
throw new ConfigurationError({
message: dedent`Failed building ${styles.bold(action.name)}.
Kaniko does not support multi-platform builds.
Please consider a build method that supports multi-platform builds.
See: https://docs.garden.io/other-plugins/container#multi-platform-builds`,
})
}

let { authSecret } = await ensureUtilDeployment({
ctx,
provider,
Expand Down
4 changes: 2 additions & 2 deletions core/src/plugins/kubernetes/container/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ export const k8sPublishContainerBuild: BuildActionHandler<"publish", ContainerBu
const k8sCtx = ctx as KubernetesPluginContext
const provider = k8sCtx.provider

const cloudBuilderUsed = await cloudBuilder.getAvailability(k8sCtx, action)
const cloudBuilderConfigured = cloudBuilder.isConfigured(k8sCtx)

const localImageId = action.getOutput("localImageId")
const deploymentRegistryImageId = action.getOutput("deploymentImageId")
const remoteImageId = containerHelpers.getPublicImageId(action, tagOverride)

// For in-cluster building or cloud builder, use regctl to copy the image.
// This does not require to pull the image locally.
if (provider.config.buildMode !== "local-docker" || cloudBuilderUsed.available) {
if (provider.config.buildMode !== "local-docker" || cloudBuilderConfigured) {
const regctlCopyCommand = ["image", "copy", deploymentRegistryImageId, remoteImageId]
log.info({ msg: `Publishing image ${remoteImageId}` })
await containerHelpers.regctlCli({ cwd: action.getBuildPath(), args: regctlCopyCommand, log, ctx })
Expand Down
2 changes: 1 addition & 1 deletion docs/k8s-plugins/guides/in-cluster-building.md
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,7 @@ spec:
platforms: ["linux/amd64", "linux/arm64"]
```

Multi-platform builds are available for both `cluster-buildkit` and `kaniko`.
Multi-platform builds are available for both `cluster-buildkit` only. Note that `kaniko` is *not* supported.

## Publishing images

Expand Down
4 changes: 3 additions & 1 deletion docs/other-plugins/container.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ spec:
```

Garden interacts with several local and remote builders. Currently support for multi-platform builds varies based on the builder backend.
The following build backends support multi-platform builds out of the box: `garden-cloudbuilder`, `cluster-buildkit`, `kaniko`.
The following build backends support multi-platform builds out of the box: `garden-cloudbuilder`, `cluster-buildkit`.

In-cluster building with `kaniko` does *not* support multi-platform builds.

The `local-docker` build backend requires some additional configurations. Docker Desktop users can enable the experimental containerd image store to also store multi-platform images locally. All other local docker solutions e.g. orbstack, podman currently need a custom buildx builder of type `docker-container`. Documemtation for both can be found here https://docs.docker.com/build/building/multi-platform.
If your local docker image store does not support storing multi-platform images, consider configuring an environment where you only build single platform images when building locally e.g.:
Expand Down

0 comments on commit c99f9b8

Please sign in to comment.