-
Notifications
You must be signed in to change notification settings - Fork 45
Add UPX Binary Compression to Reduce Release Sizes #85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -104,10 +104,45 @@ jobs: | |||||||||||||||||||||||||||||||||||||||
| name: ui-build | ||||||||||||||||||||||||||||||||||||||||
| path: src/http/ui/dist | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| - name: Install UPX | ||||||||||||||||||||||||||||||||||||||||
| run: | | ||||||||||||||||||||||||||||||||||||||||
| sudo apt-get update | ||||||||||||||||||||||||||||||||||||||||
| sudo apt-get install -y upx-ucl | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| - name: Build using Makefile | ||||||||||||||||||||||||||||||||||||||||
| run: | | ||||||||||||||||||||||||||||||||||||||||
| make linux-${{ matrix.arch }} VERSION="$VERSION" | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| - name: Compress with UPX | ||||||||||||||||||||||||||||||||||||||||
| run: | | ||||||||||||||||||||||||||||||||||||||||
| ARCH="${{ matrix.arch }}" | ||||||||||||||||||||||||||||||||||||||||
| BINARY_PATH="out/linux-${ARCH}/${{ env.BINARY_NAME }}" | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| if [ -f "$BINARY_PATH" ]; then | ||||||||||||||||||||||||||||||||||||||||
| echo "Compressing $BINARY_PATH with UPX..." | ||||||||||||||||||||||||||||||||||||||||
| upx --ultra-brute --lzma "$BINARY_PATH" -o "${BINARY_PATH}.upx" | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| # Test compressed binary | ||||||||||||||||||||||||||||||||||||||||
| if upx -t "${BINARY_PATH}.upx"; then | ||||||||||||||||||||||||||||||||||||||||
| echo "UPX compression successful, replacing original binary" | ||||||||||||||||||||||||||||||||||||||||
| mv "${BINARY_PATH}.upx" "$BINARY_PATH" | ||||||||||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||||||||||
| echo "UPX test failed, keeping original binary" | ||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+123
to
+130
|
||||||||||||||||||||||||||||||||||||||||
| upx --ultra-brute --lzma "$BINARY_PATH" -o "${BINARY_PATH}.upx" | |
| # Test compressed binary | |
| if upx -t "${BINARY_PATH}.upx"; then | |
| echo "UPX compression successful, replacing original binary" | |
| mv "${BINARY_PATH}.upx" "$BINARY_PATH" | |
| else | |
| echo "UPX test failed, keeping original binary" | |
| if upx --ultra-brute --lzma "$BINARY_PATH" -o "${BINARY_PATH}.upx"; then | |
| # Test compressed binary | |
| if upx -t "${BINARY_PATH}.upx"; then | |
| echo "UPX compression successful, replacing original binary" | |
| mv "${BINARY_PATH}.upx" "$BINARY_PATH" | |
| else | |
| echo "UPX test failed, keeping original binary" | |
| rm -f "${BINARY_PATH}.upx" | |
| fi | |
| else | |
| echo "UPX compression failed (possibly unsupported arch/format), keeping original binary" |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -33,21 +33,26 @@ RUN COMMIT=$(echo "docker" ) && \ | |||||||||||||||||||
| GOARM=${TARGETVARIANT#v} \ | ||||||||||||||||||||
| CGO_ENABLED=0 GOOS=linux GOARCH=${TARGETARCH} go -C src build \ | ||||||||||||||||||||
| -trimpath \ | ||||||||||||||||||||
| -buildvcs=false \ | ||||||||||||||||||||
| -ldflags "-s -w -X main.Version=${VERSION} -X main.Commit=${COMMIT} -X main.Date=${DATE}" \ | ||||||||||||||||||||
| -o /b4 | ||||||||||||||||||||
|
|
||||||||||||||||||||
| # Stage 2.5: UPX compression | ||||||||||||||||||||
| FROM --platform=$TARGETPLATFORM alpine:3.23.3 AS upx-compressor | ||||||||||||||||||||
|
||||||||||||||||||||
| FROM --platform=$TARGETPLATFORM alpine:3.23.3 AS upx-compressor | |
| FROM --platform=$BUILDPLATFORM alpine:3.23.3 AS upx-compressor |
Copilot
AI
Mar 4, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
upx --ultra-brute --lzma is extremely CPU-intensive and can add a large amount of time to Docker builds (especially under QEMU when cross-building). Consider switching to a less expensive preset (e.g., --best) or making the compression level configurable via a build arg so release builds can opt into ultra-brute when needed.
| RUN apk add --no-cache upx | |
| COPY --from=go-builder /b4 /b4 | |
| RUN upx --ultra-brute --lzma /b4 -o /b4.upx && upx -t /b4.upx | |
| ARG UPX_FLAGS="--best" | |
| RUN apk add --no-cache upx | |
| COPY --from=go-builder /b4 /b4 | |
| RUN upx ${UPX_FLAGS} /b4 -o /b4.upx && upx -t /b4.upx |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
--ultra-brute --lzmacan make the release workflow substantially slower across the full arch matrix. Unless maximum compression is required, consider a faster default (e.g.,--best) and/or make the compression level configurable (workflow input/env) so you can trade off size vs. build time.