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

Added QEMU support to cross build s390x image #6

Merged
merged 1 commit into from
May 27, 2022

Conversation

guirish
Copy link
Contributor

@guirish guirish commented Mar 28, 2022

Added QEMU support to cross build s390x image

@CLAassistant
Copy link

CLAassistant commented Mar 28, 2022

CLA assistant check
All committers have signed the CLA.

@huoqifeng
Copy link

@guirish thanks for raising the PR.
@caseydavenport may you help review this? I can confirm cross-platform build works well for s390x on a amd64 ubuntu 20.04 box, I tried it, here is the logs:

root@geodesic1:~/go/src/github.com/projectcalico/bpftool# uname -a
Linux xxx 5.4.0-109-generic #123-Ubuntu SMP Fri Apr 8 09:10:54 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
root@geodesic1:~/go/src/github.com/projectcalico/bpftool# pwd
/root/go/src/github.com/projectcalico/bpftool
root@geodesic1:~/go/src/github.com/projectcalico/bpftool# ARCH=s390x make image
# Make sure we re-pull the base image to pick up security fixes.
# Limit the build to use only one CPU, This helps to work around qemu bugs such as https://bugs.launchpad.net/qemu/+bug/1098729
docker build  --build-arg KERNEL_REF=v5.3 --build-arg KERNEL_REPO=git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git --cpuset-cpus 0 --pull -t calico/bpftool:v5.3-s390x -f Dockerfile.s390x .
Sending build context to Docker daemon  148.5kB
Step 1/14 : FROM alpine:3.11 as qemu
3.11: Pulling from library/alpine
Digest: sha256:bcae378eacedab83da66079d9366c8f5df542d7ed9ab23bf487e3e1a8481375d
Status: Image is up to date for alpine:3.11
 ---> a787cb986503
Step 2/14 : ARG QEMU_VERSION=6.1.0-8
 ---> Using cache
 ---> 112bb4822efc
Step 3/14 : ARG QEMU_ARCHS="s390x"
 ---> Using cache
 ---> f82b0a2c34b1
Step 4/14 : RUN apk --update add curl
 ---> Using cache
 ---> 16312a59055c
Step 5/14 : RUN curl -L https://github.com/multiarch/qemu-user-static/releases/download/v${QEMU_VERSION}/qemu-${QEMU_ARCHS}-static.tar.gz | tar zxvf - -C /usr/bin &&    chmod +x /usr/bin/qemu-s390x-static
 ---> Using cache
 ---> e3745cb24673
Step 6/14 : FROM s390x/debian:buster-slim as bpftool-build
buster-slim: Pulling from s390x/debian
Digest: sha256:4686d70ade80f2a41465e1b860e35ecf8eeaf2c3ac70c773dc03a21978c85d92
Status: Image is up to date for s390x/debian:buster-slim
 ---> 3b649080a399
Step 7/14 : ARG KERNEL_REPO=git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
 ---> Using cache
 ---> 3da36d50cba2
Step 8/14 : ARG KERNEL_REF=master
 ---> Using cache
 ---> 7ef015135ab4
Step 9/14 : COPY --from=qemu /usr/bin/qemu-s390x-static /usr/bin/
 ---> Using cache
 ---> 7f4d595ac3a9
Step 10/14 : RUN apt-get update && apt-get upgrade -y && apt-get install -y --no-install-recommends     gpg gpg-agent libelf-dev libmnl-dev libc-dev iptables libgcc-8-dev     bash-completion binutils binutils-dev make git curl     ca-certificates xz-utils gcc pkg-config bison flex build-essential && apt-get purge --auto-remove && apt-get clean
 ---> Using cache
 ---> 2cfdd0455777
Step 11/14 : WORKDIR /tmp
 ---> Using cache
 ---> a18cf3e8bb42
Step 12/14 : RUN git clone --depth 1 -b $KERNEL_REF $KERNEL_REPO && cd linux/tools/bpf/bpftool/ && sed -i '/CFLAGS += -O2/a CFLAGS += -static' Makefile && sed -i 's/LIBS = -lelf $(LIBBPF)/LIBS = -lelf -lz $(LIBBPF)/g' Makefile && printf 'feature-libbfd=0\nfeature-libelf=1\nfeature-bpf=1\nfeature-libelf-mmap=1' >> FEATURES_DUMP.bpftool && FEATURES_DUMP=`pwd`/FEATURES_DUMP.bpftool make -j `getconf _NPROCESSORS_ONLN` && strip bpftool && ldd bpftool 2>&1 | grep -q -e "Not a valid dynamic program" 	-e "not a dynamic executable" || 	( echo "Error: bpftool is not statically linked"; false ) && mv bpftool /usr/bin && rm -rf /tmp/linux
 ---> Using cache
 ---> cf0fe9f0331f
Step 13/14 : FROM scratch
 --->
Step 14/14 : COPY --from=bpftool-build /usr/bin/bpftool /bpftool
 ---> Using cache
 ---> 7ae0c91c5d59
Successfully built 7ae0c91c5d59
Successfully tagged calico/bpftool:v5.3-s390x

I think we'll need build images following in order: bpftool -> go-build -> calico.
The PRs in other project will be changed accordingly.

@caseydavenport caseydavenport merged commit 552ddfe into projectcalico:master May 27, 2022
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

Successfully merging this pull request may close these issues.

4 participants