3

Since I'm developing on an M1 mac, my Docker builds will build ARM. I want to build x86_64 images which I know I can build with the --platform flag but I want to do that with my Skaffold configuration.

Wytrzymały Wiktor
  • 11,492
  • 5
  • 29
  • 37

3 Answers3

3

Thanks to @p10l putting me on the right track, I was able to figure it out. Skaffold can't set the platform using the Docker Engine API, so we need to pass --platform=linux/x86_64 to the command line by setting useDockerCLI to true and adding cliFlags to our Docker configuration.

apiVersion: skaffold/v2beta26
kind: Config
build:
  # ... other unrelated config ...
  artifacts:
    - image: my-image
      context: ./
      docker:
        cliFlags:
          - --platform=linux/x86_64 
  local:
    useDockerCLI: true # the only way to set platform is with cliFlags so we need to enable the Docker CLI
  • Works like a charm for me aswell on a m1 mac - without complicated configs etc. Works also with helm involved. Thanks – Daniel Eberl Dec 21 '21 at 11:31
1

Whoever is coming here from google and confront this problem, skaffold almost finished developing multi-arch support but as the version of v1.39.1, you can use

skaffold run --platform linux/amd64

or simply to configure it in skaffold.yaml file

confiq
  • 2,795
  • 1
  • 26
  • 43
0

Skaffold has buildCommand field to which you can pass a custom script.
So, for example

...
build:
  artifacts:
  - image: "foo"
    context: .
    custom:
      buildCommand: ./build.sh
...

build.sh

docker buildx build \
  --platform linux/amd64
  ... # any other flags

Disclaimer: Everything below is a speculation. I'm currently unable to test this, but I'm sure someone will correct me if I'm wrong.

There is also build.artifacts.docker field (currently in beta). It may be possible to use this field to pass arguments to Docker build.

...
build:
  artifacts:
  - image: "foo"
    context: .
    docker:
      dockerfile: <Dockerfile relative to workspace>
      target: <Dockerfile target name to build>
      buildArgs:
        platform: linux/amd64
  local:
    useDockerCLI: true #this is needed to use docker build CLI rather than Docker Engine API

It may also be required to set buildx as a default builder for Docker. This can be achieved with

docker buildx install