Skip to content

chore: strip debug symbols from binary to reduce image size by 77 MB - #7028

Open
krishnakala987-byte wants to merge 1 commit into
devtron-labs:mainfrom
krishnakala987-byte:chore/strip-debug-symbols-from-binary
Open

chore: strip debug symbols from binary to reduce image size by 77 MB#7028
krishnakala987-byte wants to merge 1 commit into
devtron-labs:mainfrom
krishnakala987-byte:chore/strip-debug-symbols-from-binary

Conversation

@krishnakala987-byte

Copy link
Copy Markdown

One line in the Makefile build target. -s -w added to the existing -ldflags, alongside the -X injections for GitCommit, BuildTime and ServerMode, which are unchanged.

The binary was the largest single contributor to image size. file reported it as with debug_info, not stripped, and go tool nm counted 721,193 symbols. Section sizes from readelf: .symtab and .strtab at roughly 42 MB, the eleven .debug_* sections at roughly 35 MB.

Before After Change
Binary 277,213,440 B 199,579,560 B -77,633,880 B (-28.0%)
Image 462 MB 385 MB -77 MB (-16.7%)

How Has This Been Tested?

  • Built both images with docker build, once on main and once with the change.
  • file on the new binary reports stripped with no debug_info. readelf -S | grep -cE "debug|symtab" returns 0.
  • Confirmed the -X injections survive stripping: strings on the stripped binary still returns the injected build timestamp 2026-09-08T06:45:08Z.
  • Ran the stripped image directly. It initialises, builds the wire graph, and panics on the expected dial tcp 127.0.0.1:5432: connect: connection refused with no database present. Same behaviour as the unstripped build.
  • Panic traces still resolve function names, files and line numbers (main.main() at main.go:42, sql.NewDbConnection at connection.go:83), since Go symbolises from pclntab rather than .symtab.

Tradeoff: -w drops DWARF, so attaching delve to the shipped image would no longer give source-level debugging. Runtime panics and stack traces are unaffected, as above. Flagging in case anything in the release workflow depends on debugging the published image.

Out of scope, with reasoning in #2539: the perl dependency chain (git hard-depends on it, so --no-install-recommends would not remove it, and it would risk breaking SSH clone URLs by dropping openssh-client), and apt cache cleanup (already handled in the existing Dockerfile).

Question for reviewers: is there anything in the release or debugging workflow that reads symbols from the published binary? If so I can scope this to -w only, which still removes roughly 35 MB.

Checklist:

    • The title of the PR states what changed and the related issues number (used for the release note).
    • Does this PR requires documentation updates?
    • I have performed a self-review of my own code.
    • I have tested it for all user roles.
    • I have added all the required unit/api test cases.

Does this PR introduce a user-facing change?

No. The image is smaller and the binary is stripped. Runtime behaviour, the version endpoint and panic symbolisation are unchanged.

Adds -s -w to the existing ldflags in the build target. The binary
carried 721,193 symbols and eleven .debug_* sections, accounting for
77.6 MB of its 277 MB size.

Binary: 277,213,440 B to 199,579,560 B (-28.0%)
Image:  462 MB to 385 MB (-16.7%)

The -X injections for GitCommit, BuildTime and ServerMode are
unaffected, as they write to the data section rather than .symtab.
Verified by extracting the injected build timestamp from the stripped
binary with strings.

Closes devtron-labs#2539

Signed-off-by: Krishna Kala <krishnakala987@gmail.com>
@bito-code-review

Copy link
Copy Markdown

Bito Review Skipped - Source Branch Not Found

Bito didn't review this change because the pull request is no longer valid. It may have been merged, or the source/target branch may no longer exist.

@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant