PierreZ / goStatic

A really small static web server for Docker
GNU General Public License v2.0
395 stars 77 forks source link

Add debug symbol stripping and binary packing #40

Closed andrewstucki closed 3 years ago

andrewstucki commented 4 years ago

This adds the -s linker flag when building the go binary (to strip debug symbols) which shaves off ~2MB of the resulting code. Additionally, it runs the binary output through an aggressive upx run. Here are the resulting Docker image sizes (which are pretty much just the sizes of the binaries in the scratch container).

➜  goStatic git:(master) ✗ docker image inspect gostatic | grep Size
        "Size": 1840942,
        "VirtualSize": 1840942,
➜  goStatic git:(master) ✗ docker image inspect gostatic:arm5 | grep Size
        "Size": 1702918,
        "VirtualSize": 1702918,
➜  goStatic git:(master) ✗ docker image inspect gostatic:arm6 | grep Size
        "Size": 1696290,
        "VirtualSize": 1696290,
➜  goStatic git:(master) ✗ docker image inspect gostatic:arm7 | grep Size
        "Size": 1693834,
        "VirtualSize": 1693834,
➜  goStatic git:(master) ✗ docker image inspect gostatic:arm64 | grep Size
        "Size": 1673671,
        "VirtualSize": 1673671,

Roughly they're all ~30% of the previous size but with a slight startup penalty (likely in the single milliseconds or lower) due to upx and the need to decompress the binary code sections in memory.

PierreZ commented 3 years ago

Sorry I missed the notification, thanks a lot for the PR!