News for hackers. Stuff that matters.
Re:`COPY –chmod` reduced the size of my container image by 35% by wereHamster on Saturday March 26, 2022 @07:04AM (#30810811)
What go build options are recommended to have go output a static binary (that can run inside a scratch image)?
Re:`COPY –chmod` reduced the size of my container image by 35% by onei on Saturday March 26, 2022 @08:30AM (#30811294)
If you're using plain Go, you get static binaries for free. If you're linking against so C library you might be out of luck. You can try setting CGO_ENABLED=0 in your environment, but I've had mixed success in practice.
Re:`COPY –chmod` reduced the size of my container image by 35% by throwaway894345 on Saturday March 26, 2022 @09:43AM (#30811717)
I’ve only had success with CGO_ENABLED. If you depend on a C library, then obviously it won’t work, but mercifully few ago programs depend on C libraries (not having straight C ABI compatibility is a real blessing since virtually none of the ecosystem depends on C and its jerry rigged build tooling).
Re:`COPY –chmod` reduced the size of my container image by 35% by wereHamster on Saturday March 26, 2022 @10:41AM (#30812242)
Well this is not what I'm seeing. I need to add -ldflags "-linkmode external -extldflags -static" to the go build command otherwise the binary doesn't run inside a scratch image.
Re:`COPY –chmod` reduced the size of my container image by 35% by dimitrios1 on Saturday March 26, 2022 @09:11AM (#30811513)
CGO_ENABLED=0 has always worked for me in production, but it did come with some tradeoffs, notably, network performance.