Storyline- I was using mediasoup go which use medisoup bin to span new worker in my project everything was good so far. There was no problem running localy in ubuntu server then I deployed my go service which uses mediasoup binary to container and it didn’t worked because I was using alpine/scratch image.
After some debugging and getting helped from some devs from telegram I found that the libs which mediasoup bin requires is not available in alpine/scratch image. A developer Andrey Kartashov suggested that If it is possible then recompile with statically linked binary.
So I am wondering If it is possible then can we compile with statically linked binary so that I can also run on alpine/scratch?
It is definitely possible, in fact Rust version of the library already builds completely static library version of mediasoup, so if you target musl in Rust binary you can get completely static Rust binary with everything necessary inside of it and that works fine.
Since mediasoup go is not official it shouldn’t be a big deal to do some tweaks to the build instructions.
As a simpler approach you should still be able to install some dependencies in Alpine image and get things running, in most realistic cases a few MBs of image size have no impact on anything (practically speaking).
In most cases tough Alpine is not saving any space at all and you would be better off starting with build-deps that will likely be shared with some of the images you use anyway, thus not contributing any extra space. But that of course if the only concern was space, not some other aspects.
Rust version doesn’t build a executable, it builds static library, so that is where the difference is. You should be able to build the library the same way and provide a tiny bit of C/C++ to make static binary out of it.
The reason it doesn’t work on image built from scratch is dependency on dynamically loaded system libraries:
BTW, did you try to build it under Alpine image and then move to scratch/alpine as opposed to building under Ubuntu/Debian and moving to another linux distro?