Skip to content

Commit

Permalink
Compress k0s binary using UPX
Browse files Browse the repository at this point in the history
Make this configurable via Make variables.

Signed-off-by: Tom Wieczorek <[email protected]>
  • Loading branch information
twz123 committed Jan 23, 2025
1 parent 7c0a307 commit d961aff
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ else
GO ?= $(GO_ENV) go
endif

UPX ?= upx
UPX_OPTS ?= -1

# EMBEDDED_BINS_BUILDMODE can be either:
# docker builds the binaries in docker
# none does not embed any binaries
Expand Down Expand Up @@ -203,6 +206,9 @@ k0s.exe: BUILD_GO_CGO_ENABLED = 0
k0s.exe k0s: $(GO_ENV_REQUISITES) go.sum $(codegen_targets) $(GO_SRCS) $(shell find static/manifests/calico static/manifests/windows -type f)
rm -f -- '$@'
CGO_ENABLED=$(BUILD_GO_CGO_ENABLED) CGO_CFLAGS='$(BUILD_CGO_CFLAGS)' GOOS=$(TARGET_OS) $(GO) build $(BUILD_GO_FLAGS) -ldflags='$(LD_FLAGS)' -o '$@' main.go
ifneq ($(UPX),)
$(GO_ENV) $(UPX) $(UPX_OPTS) -- '$@'
endif
ifneq ($(EMBEDDED_BINS_BUILDMODE),none)
cat -- bindata_$(TARGET_OS) >>$@
endif
Expand Down
2 changes: 1 addition & 1 deletion build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ RUN set -ex; \
arm*) binutils=binutils-gold ;; \
*) binutils=binutils ;; \
esac; \
apk add --no-cache make gcc musl-dev "$binutils"
apk add --no-cache make gcc musl-dev "$binutils" upx

ENV \
HOME="/run/k0s-build" \
Expand Down

0 comments on commit d961aff

Please sign in to comment.