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

Dockerfiles: Improve cross building. #1941

Merged
merged 1 commit into from
Aug 10, 2023
Merged

Conversation

eiffel-fl
Copy link
Member

Previously to this commit, it was possible to cross build the images from amd64 to arm64.
With this commit, cross building can now be done in any direction:

  1. From amd64 to arm64.
  2. From arm64 to amd64.

@eiffel-fl
Copy link
Member Author

Before this commit, it was not possible to build ig-linux-amd64 from and arm64 computer:

francis-arm64-vm@francis-arm64-vmvm:~/inspektor-gadget$ lscpu | head -1
Architecture:                    aarch64
francis-arm64-vm@francis-arm64-vmvm:~/inspektor-gadget$ git branch
  francis/cross-building
* main
francis-arm64-vm@francis-arm64-vmvm:~/inspektor-gadget$
francis-arm64-vm@francis-arm64-vmvm:~/inspektor-gadget$ make ig-linux-amd64
...
 => ERROR [builder 7/7] RUN  export CGO_ENABLED=1 ;  if [ "amd64" = 'arm64' ] ; then   export CC=aarch64-linux-gnu-gcc ;   export PKG_CONFIG_PATH=/usr/lib/aarch64-  10.4s
------
 > [builder 7/7] RUN    export CGO_ENABLED=1 ;  if [ "amd64" = 'arm64' ] ; then                 export CC=aarch64-linux-gnu-gcc ;               export PKG_CONFIG_PATH=/usr/lib/aarch64-linux-gnu/pkgconfig ;      fi ;    GOOS=linux GOARCH=amd64 go build                -ldflags "-X main.version=v0.19.0-19-gf34d53e8 -extldflags '-static'"     -o ig-linux-amd64                github.com/inspektor-gadget/inspektor-gadget/cmd/ig:
2.965 # runtime/cgo
2.965 gcc: error: unrecognized command-line option '-m64'
------
ERROR: failed to solve: executor failed running [/bin/sh -c export CGO_ENABLED=1 ;      if [ "${TARGETARCH}" = 'arm64' ] ; then                 export CC=aarch64-linux-gnu-gcc ;          export PKG_CONFIG_PATH=/usr/lib/aarch64-linux-gnu/pkgconfig ;   fi ;    GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build          -ldflags "-X main.version=${VERSION} -extldflags '-static'"                -o ig-${TARGETOS}-${TARGETARCH}                 github.com/inspektor-gadget/inspektor-gadget/cmd/ig]: exit code: 1
make: *** [Makefile:98: ig-linux-amd64] Error 1

It is now possible:

francis-arm64-vm@francis-arm64-vmvm:~/inspektor-gadget$ git branch
* francis/cross-building
  main
francis-arm64-vm@francis-arm64-vmvm:~/inspektor-gadget$ lscpu | head -1
Architecture:                    aarch64
francis-arm64-vm@francis-arm64-vmvm:~/inspektor-gadget$ make ig-linux-amd64
...
francis-arm64-vm@francis-arm64-vmvm:~/inspektor-gadget$ file ig-linux-amd64 
ig-linux-amd64: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), statically linked, BuildID[sha1]=bbeaf0544a48bff8f8d530a055258a3485113f31, for GNU/Linux 3.2.0, with debug_info, not stripped
francis-arm64-vm@francis-arm64-vmvm:~/inspektor-gadget$ exit
logout
Connection to IP closed.
$ sftp francis-arm64-vm@IP                                                            francis/test-scaling *% u=
Connected to IP.
sftp> get inspektor-gadget/ig-linux-amd64
Fetching /home/francis-arm64-vm/inspektor-gadget/ig-linux-amd64 to ig-linux-amd64
ig-linux-amd64                                                                                                                           100%   98MB  18.6MB/s   00:05    
sftp> bye
$ sudo ./ig-linux-amd64 trace exec --host                                                     francis/test-scaling *% u=
RUNTIME.CONTAINERNAME                                   PID        PPID       COMM             RET ARGS                                                                    
                                                        103102     91022      runc             0   /usr/bin/runc --root /var/run/docker/runtime-runc/moby --log /run/conta…
                                                        103111     103102     exe              0   /proc/self/exe init                                                     
wizardly_mclaren                                        103113     103102     sh               0   /bin/sh -c /etc/jupyter/docker_healthcheck.py || exit 1                 
wizardly_mclaren                                        103119     103113     docker_healthch  0   /etc/jupyter/docker_healthcheck.py                                      
wizardly_mclaren                                        103119     103113     python3          0   /opt/conda/bin/python3 /etc/jupyter/docker_healthcheck.py               

Copy link
Member

@burak-ok burak-ok left a comment

Choose a reason for hiding this comment

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

Looks good.

One comment is that ig-tests.Dockerfile also has a condition based on arm64. So maybe there we should also support arm64->amd64 compiling aswell to be aligned?

Previously to this commit, it was possible to cross build the images from amd64
to arm64.
With this commit, cross building can now be done in any direction:
1. From amd64 to arm64.
2. From arm64 to amd64.

Signed-off-by: Francis Laniel <flaniel@linux.microsoft.com>
@eiffel-fl
Copy link
Member Author

One comment is that ig-tests.Dockerfile also has a condition based on arm64. So maybe there we should also support arm64->amd64 compiling aswell to be aligned?

Good catch! I added the same logic there!

I will just check the result on AKS and ARO before merging.

@eiffel-fl
Copy link
Member Author

Everything is green, let's merge it!
Thank you for the review!

@eiffel-fl eiffel-fl merged commit 7d163d7 into main Aug 10, 2023
95 checks passed
@eiffel-fl eiffel-fl deleted the francis/cross-building branch August 10, 2023 10:29
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.

None yet

2 participants