Skip to content

Add multiarch building support for arm64 - #5039

Closed
lubinsz wants to merge 1 commit into
helm:masterfrom
lubinsz:master
Closed

lubinsz wants to merge 1 commit into
helm:masterfrom
lubinsz:master

Conversation

@lubinsz

@lubinsz lubinsz commented Dec 10, 2018

Copy link
Copy Markdown

Signed-off-by: Bin Lu [email protected]

@helm-bot helm-bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Dec 10, 2018
@lubinsz

lubinsz commented Dec 10, 2018 •

Copy link
Copy Markdown
Author

Currently, there is no multiarch building step for Arm64 platform.
So I added this step in the Makefile.
With this patch, we can use 'make docker-build-all' on x86 platform to cross-build docker images for different platforms(amd64, arm64).
In order to build container images for mult-arch platforms we rely on cross-compilers and QEMU.
We can use binfmt_misc to support this feature.
For more reference, please see following as reference:
https://lobradov.github.io/Building-docker-multiarch-images/
https://hub.docker.com/r/multiarch/qemu-user-static/

@helm-bot helm-bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Dec 10, 2018
@lubinsz

lubinsz commented Dec 10, 2018

Copy link
Copy Markdown
Author

@alicefr
Any comments on this?
Thanks.

@helm-bot helm-bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Dec 10, 2018
@alicefr

alicefr commented Dec 10, 2018 •

Copy link
Copy Markdown

@lubinsz thanks to open the PR. I have a couple of suggestions. Instead of using a Dockerfile per architecture, you can use --platform arch with docker build. However, it is still experimental and you need to set it true in the /etc/docker/daemon.json. If you don't want to copy the qemu-arch-static inside the container, you need a 4.8 or greater kernel and the flag F. See https://www.kernel.org/doc/html/latest/admin-guide/binfmt-misc.html.
If you register the binfmt_misc correctly, you can build a similar dockerfile:

FROM alpine

RUN apk add --no-cache curl

you can now build the arm image on x86 in this way:

docker build --platform=linux/arm64 -t image-example:arm64 .

In this way, you can generalize and use the same dockerfile for multiple architectures. It is enough to register the binfmt_misc and set --platform
Please, be aware that multiarch/qemu-user-static:register doesn't have the F flag. See https://github.com/multiarch/qemu-user-static/blob/22b0013668d2aed4a2cfd21650e85c664b1f21c6/register/qemu-binfmt-conf.sh#L351

@helm-bot helm-bot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Dec 11, 2018
@helm-bot helm-bot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Dec 11, 2018
@lubinsz

lubinsz commented Dec 11, 2018

Copy link
Copy Markdown
Author

@alicefr
Hi,
I have updated it according to your suggestions.
Please check it.

@alicefr

alicefr commented Dec 11, 2018 •

Copy link
Copy Markdown

hi, i guess you're missing the qemu-static inside the container. As you're registering with multiarch/qemu-user-static:register, you're not using the F flag and you need qemu-static inside the container. In any case, you need to install the qemu-arch-static

@alicefr

alicefr commented Dec 11, 2018 •

Copy link
Copy Markdown

Instead of using the docker image you could directly use the script qemu-binfmt-conf.sh from qemu. It has the persistent flag that adds the F flag.
For example:

 ./qemu-binfmt-conf.sh --qemu-path /usr/bin --qemu-suffix "-static" --persistent yes

@helm-bot helm-bot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Dec 12, 2018
@lubinszARM

Copy link
Copy Markdown

@alicefr
Done. Any comments?
Thanks.

@alicefr

alicefr commented Dec 12, 2018 •

Copy link
Copy Markdown

@lubinszARM it's ok for me. Then you decided to not use the F flag. I find that it's the most elegant solution because you don't have the qemu-static binary inside the docker image. Anyway, that solution has of course some restrictions. Then, if you decide to copy the qemu-static you could remove it at the end of the build time. In this way, you don't have the qemu-static inside the final image. I'd also suggest that you use the --squash flag (also experimental). Hence, you can squash all the generated layers into a single one and you shouldn't be able to see the qemu-*-static in the final image anymore. You generate a layer when you copy the qemu binary inside and when you remove it. Does it make sense? See the calico example https://github.com/projectcalico/node/blob/master/Dockerfile.arm64

@helm-bot helm-bot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Dec 12, 2018
@lubinszARM

Copy link
Copy Markdown

@alicefr
Thank you so much for your suggestion. :)
I have updated it according to your suggestions.

@alicefr

alicefr commented Dec 12, 2018

Copy link
Copy Markdown

Thanks to address the PR. It solves the problem also for other archs

@lubinszARM

Copy link
Copy Markdown

@alicefr
Can you merge it?
Thanks.

@helm-bot helm-bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jan 8, 2019
@helm-bot helm-bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jan 24, 2019
@lubinsz

lubinsz commented Jan 24, 2019

Copy link
Copy Markdown
Author

@bacongobbler @alicefr
I have reorganized the code according to the compilation method in Kubernetes.
Any comments?
Thanks.

Comment thread rootfs/Dockerfile Outdated
FROM alpine:3.7
FROM BASEIMAGE

CROSS_BUILD_COPY qemu-QEMUARCH-static /usr/bin/

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confused here. This is the docker file for the released image isn't it? It should not contain an emulator, as the image should run natively on the target arch.

In general, I'm also a bit confused by including an emulator at all. I thought golang could cross compile all by itself. Greping through the kubernetes code for qemu, they do have qemu in there, but from a superficial skimming of the code, only looks to be used to test the binaries, not build/ship them? Maybe I'm totally wrong.

@lubinsz lubinsz Jan 25, 2019 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @kfox1111
Thank you for your comments. :)

I have added a command to delete the emulator in the end of each Dockerfiles.

Regarding to your second question, you should notice the following line in each Dockerfile:
"RUN apk update && apk add ... "
It means, it needs to execute non-x86 instruction in docker multi-arch building step.
So the emulator in Dockerfile is mandatory.
Regarding to rook/ceph, we don't need to copy emulator in Dockerfile. Because we don't need to run any non-x86 instruction in docker multi-arch building step.
But for rook/nfs, the emulator in Dockerfile is mandatory. The reason for this problem is same as the problem in helm.
You can see that there are many commands in the Dockerfile of ‘rook/nfs' that need to use non-x86 instruction. Such as: 'dnf install', 'make' ...

You can test my patch in your x86 ubuntu environment.
The building will be failed if without the following line in Dockerfile:
"CROSS_BUILD_COPY qemu-QEMUARCH-static /usr/bin/"
The error should be like following:

Step 2/9 : RUN apk update && apk add ca-certificates socat && rm -rf /var/cache/apk/*
---> Running in 02f412954455
standard_init_linux.go:190: exec user process caused "no such file or directory"
The command '/bin/sh -c apk update && apk add ca-certificates socat && rm -rf /var/cache/apk/*' returned a non-zero code: 1
Makefile:120: recipe for target 'docker-build' failed

Introduction article: https://lobradov.github.io/Building-docker-multiarch-images/
Please see the section titled "Different Dockerfile per architecture" as reference.

In addition, I need to explain that these problems have nothing to do with golang cross compilation.
For helm, the problem is that it uses the following command in Dockerfile:
"RUN apk update && apk add ... "

For rook/nfs, the problem is that it uses the following command in Dockerfile:
"RUN dnf install ... make...."

If we only need to simply COPY the cross-compiled golang binary files in Dockerfile, we don't need to COPY the emulator in Dockerfile. Just like in rook/ceph.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... I see. thanks for the explanation.

removing the emulator in a subsequent layer will only hide it, not remove it. so it will still be shipped to the end devices anyway.

I was thinking the emulator was fairly sizeable, but it looks like its pretty small compared to tiller so it may not be too bad to ship to machines that never will use it.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a tricky problem @justincormack might have an idea other than the experimental version of Docker? In OpenFaaS we build for amd64, armhf, arm64 but with the two arm platforms built on a device and not via cloud CI. It's a huge pain so we may move to qemu like this.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove the emulator using a multi-stage build. Cross builds are kind of horrible compared to native, but better than no build...

@helm-bot helm-bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jan 25, 2019
@bacongobbler bacongobbler removed this from the 2.13.0 milestone Feb 2, 2019
@bacongobbler

Copy link
Copy Markdown
Member

removing from the 2.13 milestone given the current discussions/concerns

@alexellis

Copy link
Copy Markdown

Hi @bacongobbler are there any open concerns with the PR at the moment?

@vielmetti

Copy link
Copy Markdown

@lubinsz it looks like the Makefile has a conflict at the moment, perhaps needs a rebase?

@bacongobbler

Copy link
Copy Markdown
Member

Hi @bacongobbler are there any open concerns with the PR at the moment?

Yes. Please see #5039 (review).

@lubinsz

lubinsz commented Mar 5, 2019 •

Copy link
Copy Markdown
Author

Hi @bacongobbler are there any open concerns with the PR at the moment?

Yes. Please see #5039 (review).

@bacongobbler
I have reorganized the code according to the compilation method in Kubernetes.
Now, cross-building does not depends on any experimental features of docker.
Please check it.
The issue of #5039 has gone .

@helm-bot helm-bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Mar 11, 2019
@lubinsz

lubinsz commented Mar 11, 2019

Copy link
Copy Markdown
Author

@lubinsz it looks like the Makefile has a conflict at the moment, perhaps needs a rebase?

Done.

@lubinsz

lubinsz commented May 27, 2019

Copy link
Copy Markdown
Author

If I understand the PR, In order to build tiller images for amd64 as well as arm64, our CI infrastructure has to enable Docker's experimental features. I don't believe that's enabled by default on CircleCI. Can you check and see how we can enable experimental Docker features for Circle?

- setup_remote_docker:
version: 17.09.0-ce

Additionally, I'm not too sure how comfortable I feel about relying on unstable features for releasing production software. In the past, we've avoided relying on unstable features for our release pipeline. Do you know how long it may take until this becomes a stable feature of Docker? We may want to hold out and wait until it does to ensure that existing users of Helm aren't relying on experimental features.

Hi @bacongobbler
I have reorganized the code according to the compilation method in Kubernetes.
Now, cross-building does not depends on any experimental features of docker.

@hickeyma

Copy link
Copy Markdown
Contributor

@lubinsz Can you rebase and it should be ready again for review then?

@lubinsz

lubinsz commented May 28, 2019

Copy link
Copy Markdown
Author

@lubinsz Can you rebase and it should be ready again for review then?

Hi @hickeyma
Done.
To make it simple, I removed all my previously used 'sed' methods.
Instead, use the build arg in the Dockerfile.

@lubinsz

lubinsz commented Jun 5, 2019

Copy link
Copy Markdown
Author

ping @hickeyma @bacongobbler

@bacongobbler

Copy link
Copy Markdown
Member

Closing for the same reasons in #2649. For posterity:

As per the announcement on the mailing list, Helm 2.15.0 is the last release where we will be merging new features for Helm 2. Tiller has been removed in Helm 3 so I don't see us moving forward with this proposal, so I'm going to close this as something we do not plan to merge in the 2.15 timeframe.

That being said, the tiller-multiarch project has been providing amd64 tiller images for Helm 2, so I'd suggest focusing efforts on that project going forward. Thanks!

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

Labels

size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.