Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Add Docker buildx multi-arch support #770

Open
mrsimpson opened this issue Mar 2, 2020 · 7 comments
Open

[Feature] Add Docker buildx multi-arch support #770

mrsimpson opened this issue Mar 2, 2020 · 7 comments

Comments

@mrsimpson
Copy link

In order to support the packaging of a function multi-platform docker images, the FaaS CLI build command needs to provide new options to select the target platforms

Expected Behaviour

Ability to pass a list of target platforms to the docker build.

Current Behaviour

There's no option to pass this parameter.

Possible Solution

Add a new parameter --platform to the build command.
The supported platforms (e. g. linux/amd64,linux/arm/v7) should be included in the faas-cli build --help
Experimental docker features (buildx/buildkit) should be enabled implicitly.

Context

While building multi-platform in a CI, the build needed to be triggered outside the faas-cli using native docker commands.

@alexellis
Copy link
Member

alexellis commented Jul 7, 2020

@utsavanand2 just asked me about this issue.

--platform relies on Buildkit being used (buildx is an interface to buildkit AFAIK) - with the tooling - we are trying not to couple tightly to container builders.

For instance, faas-cli build --shrinkwrap produces a generic build context that can be built by any container builder, but additional metadata like "platform" is not going to be supported.

I am also not sure whether Kaniko or other builds support this notion as of yet, it certainly won't work with openfaas cloud which uses the above shrink-wrap approach.

We recently added the ability to pass a build-arg - can you pass your platform value that way, or via an ENV-var? - this can be passed via CLI args and via stack.yml

To enable Buildkit, you can run DOCKER_BUILDKIT=1 faas-cli build for instance.

@alexellis
Copy link
Member

/set title: [Feature] Add Docker buildx multi-arch support

@derek derek bot changed the title Build for multi-platform [Feature] Add Docker buildx multi-arch support Oct 26, 2020
@alexellis
Copy link
Member

I spent some time prototyping this. There is a bit of a problem at present with the way that buildx vs docker works.

buildx for Multiplatform can't build to the local library, so must push to a registry to then be pulled back and used again. This is due to multi-arch manifests. See tweet

I prototyped this and hacked the faas-cli build command to do a push for three architectures, it worked as expected, however it ties builds to pushes, which breaks our concept of build/push/deploy (or "up")

I would welcome suggestions on how we move this forward from a user-experience point of view.

@alexellis
Copy link
Member

As a follow-up, buildx will need to be used to build each image separately, passing one architecture / platform at a time. At the push step, we will need to push each image, and then create a manifest against the target repository.

@colearendt
Copy link

colearendt commented Jul 1, 2022

This feature is important for M1 mac users who are deploying to non-arm architectures. In this case, it is important to build with the --platform linux/amd64 flag.

If the fix is any easier in the short term, I would welcome a single-valued --platform argument (i.e. can only build to one architecture at a time) or a generic --builder-arg command that passes arguments to the builder CLI itself (as opposed to build ARGs that are passed to the Dockerfile). This way the user has to manage the ergonomics themselves.

EDIT: I also think it would be nice to be able to set this in the yaml or env vars if possible too. 🤷 (Especially if there is a dedicated --platform argument)

@crispyricepc
Copy link

M1 Mac user here, was looking for a solution. At the moment my workaround is to set the DOCKER_DEFAULT_PLATFORM variable to linux/amd64. For example:

DOCKER_DEFAULT_PLATFORM=linux/amd64 faas-cli -f <cfg.yml> up

@alexellis
Copy link
Member

@crispyricepc you should just be able to write the following?

faas-cli publish --platform linux/amd64

And to be clear, you want to cross-compile to amd64 from your M1 right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants