netbirdio / netbird

Connect your devices into a single secure private WireGuard®-based mesh network with SSO/MFA and simple access controls.
https://netbird.io
BSD 3-Clause "New" or "Revised" License
9.79k stars 424 forks source link

smaller executable for openwrt #2020

Open JakubZukal opened 1 month ago

JakubZukal commented 1 month ago

Is your feature request related to a problem? Please describe. Hi. We are using Netbird on a Collie Router (GL-X300B) and cannot upgrade from version 0.25.3 (5.8M) to 0.27.* (9.8M) due to insufficient space on overlayfs:/overlay. Unfortunately, increasing the space might not be possible for us.

Describe the solution you'd like Smaller executable.

Describe alternatives you've considered I've tried to minify the executable, but it's still not enough.

dckr-build# GOARCH=mipsle GOOS=linux GOMIPS=softfloat go build -ldflags="-s -w" -o collie_netbird
dckr-build# ls -la collie_netbird
-rwxr-xr-x 1 root root 36241591 May 20 20:11 collie_netbird

dckr-build# mipsel-linux-gnu-strip collie_netbird
dckr-build# ls -la collie_netbird
-rwxr-xr-x 1 root root 36180352 May 20 20:11 collie_netbird

dckr-build# upx --best collie_netbird
-rwxr-xr-x 1 root root 9711584 May 20 20:11 collie_netbird

Additional context Nope.

Is there a way to further shrink the binary a little bit more?

JaSei commented 3 weeks ago

An interesting solution would be to use a different compiler for this, like tinygo. Unfortunately it doesn't work with MIPS arch. https://github.com/tinygo-org/tinygo/issues/1075

lixmal commented 3 weeks ago

Tinygo also doesn't support net/http/httptrace which is used by http2/grpc

mlsmaycon commented 6 days ago

@JakubZukal can you check if the latest version has improved with UPX? we removed some dependencies that were adding 5MB in binary size since v0.27

JakubZukal commented 6 days ago
builder# GOARCH=mipsle GOOS=linux GOMIPS=softfloat go build -ldflags="-s -w" -o collie_netbird
builder# ls -la collie_netbird
-rwxr-xr-x 1 root root 29229239 Jun 25 08:12 collie_netbird

builder# mipsel-linux-gnu-strip collie_netbird
builder# ls -la collie_netbird
-rwxr-xr-x 1 root root 29215776 Jun 25 08:17 collie_netbird

builder# upx --best collie_netbird
builder# ls -la collie_netbird
-rwxr-xr-x 1 root root 8332280 Jun 25 08:17 collie_netbird

It is 14.2% smaller than my previous attempt. Great work! I'll try some other options to minify it a bit more, as I need it to be around 7 MB. I'll let you know ASAP.

mlsmaycon commented 6 days ago

We have some work planned around replacing gopacket with an alternative, which should also reduce a few MBs.

This will take some time as we are introducing some significant relay changes