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

Support cross-building / buildx #129

Open
LeifW opened this issue Jan 18, 2023 · 5 comments
Open

Support cross-building / buildx #129

LeifW opened this issue Jan 18, 2023 · 5 comments

Comments

@LeifW
Copy link

LeifW commented Jan 18, 2023

We want to publish Docker images for both x64 and arm64. Looks like sbt-native-packager added this in sbt/sbt-native-packager#1527 - seems to mostly be a matter of shelling out to docker buildx instead of docker build, with some other args?

@andrewhibbert
Copy link

If you run docker buildx install docker build will alias to docker buildx build. You'd then need to pass in flag of platform like this:

docker / buildOptions := BuildOptions(
  cache                        = false,
  removeIntermediateContainers = BuildOptions.Remove.Always,
  pullBaseImage                = BuildOptions.Pull.Always,
  additionalArguments          = Seq("--platform", "linux/amd64,linux/arm64")
)

Prior to this you need QEMU binaries you can get this via docker:

docker run --privileged --rm tonistiigi/binfmt --install all

And you'll need to setup and use a new instance:

docker buildx create --name multiarch --driver docker-container
docker buildx use --default --global multiarch

It is best to use --push in additionalArguments, but then you also need to tag it -t <repo:tag> and additionalArguments seems to only support strings

@nik-kashi
Copy link
Contributor

Hi @andrewhibbert
Thanks for the solution, but after applying these changes to my code I receive an error from the sbt-docker plugin which Could not parse Docker image id
related to this line: https://github.com/marcuslonnberg/sbt-docker/blob/master/src/main/scala/sbtdocker/DockerBuild.scala#L164

It seems that the steps of docker build and docker buildx build are different, so the parseImageId method can not discover the right image name

@andrewhibbert
Copy link

Sorry ignore this I've ended up using https://github.com/sbt/sbt-native-packager, see sbt/sbt-native-packager#1527. There is an example in https://github.com/sbt/sbt-native-packager/blob/master/test-project-docker/build.sbt

@nik-kashi
Copy link
Contributor

@marcuslonnberg Do you have any tips for me about what a good approach can be? Then I can try to create a PR for that

@marcus-drake
Copy link
Owner

@nik-kashi An approach to address this would be to extend the parseImageId function with another regexp that it can use to match and extract the Docker image ID. A PR would be welcomed 🙂

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

No branches or pull requests

4 participants