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

Feature Request: Support static builds #342

Open
t3hmrman opened this Issue May 27, 2018 · 5 comments

Comments

3 participants
@t3hmrman

t3hmrman commented May 27, 2018

Running on Container Linux, I recently built kata-runtime in an Alpine linux container so I could use it as a static binary, all it required was changing the go build command to the following:

go build --ldflags '-linkmode external -extldflags "-static"' -i -o $@

Could building statically be supported natively in the Makefile? Maybe a variable like GO_BUILD_OPTS could be introduce additional options, and then another variable or different target entirely for doing static builds?

After moving the generated binary to the Container Linux machine, it seems to be working OK:

core@localhost ~ $ ./kata-runtime kata-check
INFO[0000] CPU property found                            description="Intel Architecture CPU" name=GenuineIntel pid=2437 source=runtime type=attribute                                                                                                                           
INFO[0000] CPU property found                            description=SSE4.1 name=sse4_1 pid=2437 source=runtime type=flag
INFO[0000] CPU property found                            description="Virtualization support" name=vmx pid=2437 source=runtime type=flag
INFO[0000] CPU property found                            description="64Bit CPU" name=lm pid=2437 source=runtime type=flag
INFO[0000] kernel property found                         description="Kernel-based Virtual Machine" name=kvm pid=2437 source=runtime type=module                                                                                                                                 
INFO[0000] kernel property found                         description="Intel KVM" name=kvm_intel pid=2437 source=runtime type=module
WARN[0000] kernel module parameter has unexpected value  description="Intel KVM" expected=Y name=kvm_intel parameter=nested pid=2437 source=runtime type=module value=N                                                                                                          
INFO[0000] Kernel property value correct                 description="Intel KVM" expected=Y name=kvm_intel parameter=unrestricted_guest pid=2437 source=runtime type=module value=Y                                                                                              
INFO[0000] kernel property found                         description="Host kernel accelerator for virtio" name=vhost pid=2437 source=runtime type=module                                                                                                                         
INFO[0000] kernel property found                         description="Host kernel accelerator for virtio network" name=vhost_net pid=2437 source=runtime type=module                                                                                                             
INFO[0000] System is capable of running Kata Containers  name=kata-runtime pid=2437 source=runtime

I haven't gotten to make a OCI bundle or run it behind containerd/frakti yet but will update when I do.

@egernst

This comment has been minimized.

Show comment
Hide comment
@egernst
Contributor

egernst commented Jun 19, 2018

@caoruidong

This comment has been minimized.

Show comment
Hide comment
@caoruidong

caoruidong Aug 30, 2018

Contributor

go build --ldflags '-linkmode external -extldflags "-static"' -i -o $@

This command doesn't work for me.

 # github.com/kata-containers/runtime/cli
/tmp/go-link-199539456/000001.o: In function `_cgo_b0c710f30cfd_C2func_getaddrinfo':
/tmp/go-build/net/_obj/cgo-gcc-prolog:46: warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/libpthread.a(libpthread.o): In function `sem_open':
(.text+0x6a23): warning: the use of `mktemp' is dangerous, better use `mkstemp'
Contributor

caoruidong commented Aug 30, 2018

go build --ldflags '-linkmode external -extldflags "-static"' -i -o $@

This command doesn't work for me.

 # github.com/kata-containers/runtime/cli
/tmp/go-link-199539456/000001.o: In function `_cgo_b0c710f30cfd_C2func_getaddrinfo':
/tmp/go-build/net/_obj/cgo-gcc-prolog:46: warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/libpthread.a(libpthread.o): In function `sem_open':
(.text+0x6a23): warning: the use of `mktemp' is dangerous, better use `mkstemp'
@t3hmrman

This comment has been minimized.

Show comment
Hide comment
@t3hmrman

t3hmrman Aug 30, 2018

@caoruidong Are you attempting the build in a distribution that supports musl libc? When I did this I'm pretty sure I was working in an alpine container.

From the warning text it looks like you're linking to glibc. Also, the warning text you posted is warnings, where was the actual error? is that the whole output?

t3hmrman commented Aug 30, 2018

@caoruidong Are you attempting the build in a distribution that supports musl libc? When I did this I'm pretty sure I was working in an alpine container.

From the warning text it looks like you're linking to glibc. Also, the warning text you posted is warnings, where was the actual error? is that the whole output?

@caoruidong

This comment has been minimized.

Show comment
Hide comment
@caoruidong

caoruidong Aug 30, 2018

Contributor

@t3hmrman Oh, my fault. It is a warning and binary is still compiled out.

Contributor

caoruidong commented Aug 30, 2018

@t3hmrman Oh, my fault. It is a warning and binary is still compiled out.

@t3hmrman

This comment has been minimized.

Show comment
Hide comment
@t3hmrman

t3hmrman Aug 30, 2018

No problem! Just to note I did get this working behind containerd's untrusted runtime system, but it didn't ultimately end up working, plan on making a blog post about it, but that should be separate from the meat of this ticket (making it easier/supported to do the static build at all), otherwise I'd just delete this ticket.

t3hmrman commented Aug 30, 2018

No problem! Just to note I did get this working behind containerd's untrusted runtime system, but it didn't ultimately end up working, plan on making a blog post about it, but that should be separate from the meat of this ticket (making it easier/supported to do the static build at all), otherwise I'd just delete this ticket.

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