Reduce binary size using -s -w ldflags#9627
Conversation
Signed-off-by: Caleb Xu <caxu@redhat.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #9627 +/- ##
==========================================
- Coverage 60.76% 60.73% -0.03%
==========================================
Files 387 387
Lines 36618 36618
==========================================
- Hits 22250 22241 -9
- Misses 12773 12781 +8
- Partials 1595 1596 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Thanks @caxu-rh for the PR! |
Yes, but this should still reduce the size of what users will actually run/install/keep on their disk. You can't execute the binary without unpacking it.
I think the function names/stack trace is not impacted by the addition of these flags. For example, I inserted a |
Thank you for contributing to Velero!
Please add a summary of your change
This change adds the Go ldflags
-s -wwhich omits the symbol table and DWARF debugging information from the resulting binaries. The flags are added in GoReleaser configuration, Dockerfile{-Windows}, and thehack/build.shfor consistency. This allows for some reductions in binary size. Note that the size of release tarballs might not change as much (symbol table and DWARF debug info compress well), but the size of the unpacked binary on-disk will see improvements.From local testing:
CGO_ENABLED=0 go build ./cmd/velero/velero.goCGO_ENABLED=0 go build -ldflags '-s -w' ./cmd/velero/velero.goDoes your change fix a particular issue?
This change does not fix a particular issue.
Please indicate you've done the following:
make new-changelog) or comment/kind changelog-not-requiredon this PR.site/content/docs/main.