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

Makefile: add multiarch building support #203

Closed
wants to merge 1 commit into from

Conversation

lubinsz
Copy link

@lubinsz lubinsz commented Dec 17, 2018

Signed-off-by: Bin Lu bin.lu@arm.com

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Dec 17, 2018
@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Dec 17, 2018
@lubinsz lubinsz changed the title Add multiarch building support Makefile: add multiarch building support Dec 17, 2018
@lubinsz
Copy link
Author

lubinsz commented Dec 18, 2018

@marquiz
Any comments?

@marquiz
Copy link
Contributor

marquiz commented Jan 17, 2019

I understand the motivation behind this. But, there are some details I don't fully understand, and, I think the current implementation is a bit too hackish.

Some quick thoughts and questions:

  • First, what are the Docker requirements for this? At least my docker CE v17.09 does not support this?
  • What about buildah?
  • I think there should be more detailed checks to make sure that the build tool (only Docker?) supports multiple platforms.
  • If the build steps start to be complex, maybe those should be moved into a separate build.sh script or smth(?)
  • What is the idea behind using qemu-static? I dislike the blind "wgeting" of these and creating per-arch Dockerfiles, leaving the repo dirty.
  • Makefile could have one target per arch, possibly utilizing make's pattern rules?
  • Better error handling would be needed. I think it should error out if one build fails.

@lubinsz lubinsz force-pushed the pr_multi branch 5 times, most recently from 167ac83 to bf6c489 Compare January 25, 2019 08:15
@lubinsz
Copy link
Author

lubinsz commented Jan 25, 2019

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

@lubinsz lubinsz force-pushed the pr_multi branch 6 times, most recently from 97975fa to 102a089 Compare January 25, 2019 09:08
Copy link
Contributor

@marquiz marquiz left a comment

Choose a reason for hiding this comment

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

I think the patch could be streamlined still

Makefile Outdated Show resolved Hide resolved
Dockerfile Outdated Show resolved Hide resolved
Dockerfile Outdated Show resolved Hide resolved
Dockerfile Outdated
FROM debian:stretch-slim
FROM BASEIMAGE2

CROSS_BUILD_COPY qemu-QEMUARCH-static /usr/bin/
Copy link
Contributor

Choose a reason for hiding this comment

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

Again, could this be commented out, and, QEMUARCH turned into a build arg

Dockerfile Outdated Show resolved Hide resolved
Makefile Outdated Show resolved Hide resolved
Makefile Outdated Show resolved Hide resolved
Makefile Outdated
docker run --rm --privileged multiarch/qemu-user-static:register --reset
curl -sSL https://github.com/multiarch/qemu-user-static/releases/download/$(QEMUVERSION)/x86_64_qemu-$(QEMUARCH)-static.tar.gz | tar -xz -C ./
# Ensure we don't get surprised by umask settings
chmod 0755 qemu-$(QEMUARCH)-static
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be possible to run this inside the Dockerfile, or, put the temporary files in a separate build directory in order to minimize the dirtying of the git work dir?

Copy link
Author

Choose a reason for hiding this comment

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

Done.
I added a new layer in Dockerfile to get the qemu file.

Makefile Outdated Show resolved Hide resolved
@fejta-bot
Copy link

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label May 14, 2019
@lubinsz lubinsz force-pushed the pr_multi branch 4 times, most recently from 5b3a4e3 to 61a6c6f Compare May 23, 2019 10:32
@lubinsz
Copy link
Author

lubinsz commented May 23, 2019

@marquiz
Any comments?

Copy link
Contributor

@marquiz marquiz left a comment

Choose a reason for hiding this comment

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

Looks quite good, now, in my eyes. I think we could merge this after resolving the few comments I still have.

I think pulling qemu in a separate image is ok, definitely better than (re-)downloading it with every build.

Dockerfile Outdated Show resolved Hide resolved
Makefile Outdated Show resolved Hide resolved
Makefile Outdated Show resolved Hide resolved
@marquiz
Copy link
Contributor

marquiz commented Jun 4, 2019

/remove-lifecycle stale

@k8s-ci-robot k8s-ci-robot removed the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Jun 4, 2019
Optional, for example.
```
cd <project-root>
docker run --rm --privileged multiarch/qemu-user-static:register --reset
Copy link
Contributor

Choose a reason for hiding this comment

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

Would make pre-cross be better?

docker run --rm --privileged multiarch/qemu-user-static:register --reset
make image ARCH=arm64
```
Or, you can build all supported amd64/non-amd64 images together.
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd suggest Or, you can build all supported architectures with one command: or similar, drop the amd64 here...

docker run --rm --privileged multiarch/qemu-user-static:register --reset

# Building multi-arch docker images
images-all: pre-cross
Copy link
Contributor

Choose a reason for hiding this comment

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

I think pre-cross should be listed as a phony target, or, removed from here. With the former, we always would run pre-cross when building images-all which prolly is ok

@@ -593,6 +593,19 @@ cd <project-root>
make
```

**Build non-amd64 image on amd64:**<br>
Copy link
Contributor

Choose a reason for hiding this comment

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

NIT: this just looks a bit clumsy heading 😄

How about Multiarch builds or Build for target architectures or smth? If AMD64 is mentioned I think it should be capital case.

@marquiz
Copy link
Contributor

marquiz commented Aug 27, 2019

Hmm, now my test build fails with:

Step 18/24 : RUN go install   -ldflags "-s -w -X sigs.k8s.io/node-feature-discovery/pkg/version.version=$NFD_VERSION"   ./cmd/*
 ---> Running in f0534f7d6494
qemu: uncaught target signal 11 (Segmentation fault) - core dumped
Segmentation fault (core dumped)

Need to investigate this. I'd like to be able to run the build myself before merging 😄

@fejta-bot
Copy link

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Nov 25, 2019
@marquiz
Copy link
Contributor

marquiz commented Dec 12, 2019

I still have issues running make image on any other ARCH than amd64. I've tried with multiple different hardware and mutiple different OSes and on most systems the build gets stuck in the go install phase. However, I was able to successfully build it on Ubuntu 16.04 with Docker.io v18.09. I haven't had the time to look at the problem closer.

What system and docker version are you using to test this on?

Could you rebase this PR?

/remove-lifecycle stale

@k8s-ci-robot k8s-ci-robot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Dec 12, 2019
@k8s-ci-robot
Copy link
Contributor

@lubinsz: PR needs rebase.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

ARG IMAGEARCH
FROM alpine:3.9.2 as qemu
RUN apk add --no-cache curl
ARG QEMUVERSION=2.9.1
Copy link
Contributor

Choose a reason for hiding this comment

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

QEMU version needs to be update

Suggested change
ARG QEMUVERSION=2.9.1
ARG QEMUVERSION=4.1.1-1

@marquiz
Copy link
Contributor

marquiz commented Dec 13, 2019

OK, I think I cracked this one. QEMU version was too old and buggy. Used QEMUVERSION=4.1.1-1 and it started to work.

@lubinsz please rebase and apply that change and I think we can merge this.

@fejta-bot
Copy link

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Mar 12, 2020
@fejta-bot
Copy link

Stale issues rot after 30d of inactivity.
Mark the issue as fresh with /remove-lifecycle rotten.
Rotten issues close after an additional 30d of inactivity.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle rotten

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Apr 11, 2020
@marquiz
Copy link
Contributor

marquiz commented Apr 11, 2020

Please rebase

/remove-lifecycle rotten

@k8s-ci-robot k8s-ci-robot removed the lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. label Apr 11, 2020
@marquiz
Copy link
Contributor

marquiz commented May 19, 2020

ping @lubinsz

@pmundt
Copy link
Contributor

pmundt commented May 20, 2020

Since this PR was opened, Docker has also changed the way in which it does multiarch builds, now preferring the buildx extension, which amongst other things, takes care of wrapping the backing QEMU instances automatically. I suspect much of this could now be simplified by wrapping TARGETPLATFORM in the Dockerfile.

@pmundt
Copy link
Contributor

pmundt commented May 20, 2020

Following up on buildx builds, I can confirm that there are no source-level modifications required in order to do multi-arch builds. I've just successfully built and run amd64 and arm64 containers on the current git HEAD as-is:

https://hub.docker.com/repository/docker/adaptant/node-feature-discovery/tags?page=1

The change to the pstate file should be split out and applied separately.

@pmundt
Copy link
Contributor

pmundt commented May 21, 2020

Actually, I see that the pstate workaround has already been applied, so it's possible to close this PR.

@marquiz
Copy link
Contributor

marquiz commented May 26, 2020

Following up on buildx builds, I can confirm that there are no source-level modifications required in order to do multi-arch builds. I've just successfully built and run amd64 and arm64 containers on the current git HEAD as-is:

Thanks for the investigation and testing. This could be an option if amd64 builds are not affected, not on older docker versions or other builders like podman (or docker ce).

If you have time and wish to do so you could open another PR utilising buildx(?)

@pmundt
Copy link
Contributor

pmundt commented May 26, 2020

As I said, there are no source-level modifications required for buildx - it just works out of the box. The only thing I had to change was the addition of 32-bit ARM support, which was already merged in #322 . I could make a PR that documents it in the README, but to be honest, there is nothing special about its invocation within the NFD context, so the standard buildx instructions are more than sufficient.

@fejta-bot
Copy link

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Aug 24, 2020
@ArangoGutierrez
Copy link
Contributor

/close

@k8s-ci-robot
Copy link
Contributor

@ArangoGutierrez: Closed this PR.

In response to this:

/close

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants