Skip to content
This repository was archived by the owner on Jan 9, 2023. It is now read-only.

Commit 1f97e08

Browse files
authored
Merge pull request #287 from simonswine/binary-compression
Binary compression
2 parents a1b6e81 + e9cec1b commit 1f97e08

File tree

3 files changed

+35
-10
lines changed

3 files changed

+35
-10
lines changed

.goreleaser.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ builds:
1919
goarch:
2020
- amd64
2121
flags: -tags netgo
22+
hooks:
23+
post: hack/minify-binaries.sh
2224
archive:
2325
format: binary
2426
release:

Makefile

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,18 @@ GOPATH ?= /tmp/go
2020

2121
UNAME_S := $(shell uname -s)
2222
ifeq ($(UNAME_S),Linux)
23-
SHASUM := "sha256sum -c"
23+
SHASUM := sha256sum -c
2424
DEP_URL := https://github.com/golang/dep/releases/download/v0.4.1/dep-linux-amd64
2525
DEP_HASH := 31144e465e52ffbc0035248a10ddea61a09bf28b00784fd3fdd9882c8cbb2315
26-
GORELEASER_URL := https://github.com/goreleaser/goreleaser/releases/download/v0.54.0/goreleaser_Linux_x86_64.tar.gz
27-
GORELEASER_HASH := 895df4293580dd8f9b0daf0ef5456f2238a2fbfc51d9f75dde6e2c63ca4fccc2
26+
GORELEASER_URL := https://github.com/goreleaser/goreleaser/releases/download/v0.77.0/goreleaser_Linux_x86_64.tar.gz
27+
GORELEASER_HASH := aae3c5bb76b282e29940f2654b48b13e51f664368c7589d0e86b391b7ef51cc8
2828
endif
2929
ifeq ($(UNAME_S),Darwin)
30-
SHASUM := "shasum -a 256 -c"
30+
SHASUM := shasum -a 256 -c
3131
DEP_URL := https://github.com/golang/dep/releases/download/v0.4.1/dep-darwin-amd64
32-
DEP_HASH := f170008e2bf8b196779c361a4eaece1b03450d23bbf32d1a0beaa9b00b6a5ab4
33-
GORELEASER_URL := https://github.com/goreleaser/goreleaser/releases/download/v0.54.0/goreleaser_Darwin_x86_64.tar.gz
34-
GORELEASER_HASH := 9d927528a599174eed4d0d6a1ce6bdc810463c4cb105b0d2319c7c63ec642c9b
32+
DEP_HASH := 1544afdd4d543574ef8eabed343d683f7211202a65380f8b32035d07ce0c45ef
33+
GORELEASER_URL := https://github.com/goreleaser/goreleaser/releases/download/v0.77.0/goreleaser_Darwin_x86_64.tar.gz
34+
GORELEASER_HASH := bc6cdf2dfe506f2cce5abceb30da009bfd5bcdb3e52608c536e6c2ceea1f24fe
3535
endif
3636

3737

@@ -124,15 +124,29 @@ $(BINDIR)/informer-gen:
124124

125125
$(BINDIR)/dep:
126126
curl -sL -o $@ $(DEP_URL)
127-
echo "$(DEP_HASH) $@" | $$SHASUM
127+
echo "$(DEP_HASH) $@" | $(SHASUM)
128128
chmod +x $@
129129

130+
# upx binary packer, only supported on Linux
131+
$(BINDIR)/upx:
132+
ifeq ($(UNAME_S),Linux)
133+
curl -sL -o [email protected] https://github.com/upx/upx/releases/download/v3.94/upx-3.94-amd64_linux.tar.xz
134+
echo "e1fc0d55c88865ef758c7e4fabbc439e4b5693b9328d219e0b9b3604186abe20 [email protected]" | $(SHASUM)
135+
which xz || ( apt-get update && apt-get -y install xz-utils)
136+
cd $(BINDIR) && tar xvf $(shell basename $@).tar.xz upx-3.94-amd64_linux/upx --strip-components=1
137+
138+
else
139+
echo -e "#/bin/sh\nexit 0" > $@
140+
chmod +x $@
141+
endif
142+
130143
$(BINDIR)/goreleaser:
131144
curl -sL -o $@.tar.gz $(GORELEASER_URL)
132-
echo "$(GORELEASER_HASH) $@.tar.gz" | $$SHASUM
145+
echo "$(GORELEASER_HASH) $@.tar.gz" | $(SHASUM)
133146
cd $(BINDIR) && tar xzvf $(shell basename $@).tar.gz goreleaser
147+
rm $@.tar.gz
134148

135-
depend: $(BINDIR)/go-bindata $(BINDIR)/mockgen $(BINDIR)/defaulter-gen $(BINDIR)/defaulter-gen $(BINDIR)/deepcopy-gen $(BINDIR)/conversion-gen $(BINDIR)/client-gen $(BINDIR)/lister-gen $(BINDIR)/informer-gen $(BINDIR)/dep $(BINDIR)/goreleaser
149+
depend: $(BINDIR)/go-bindata $(BINDIR)/mockgen $(BINDIR)/defaulter-gen $(BINDIR)/defaulter-gen $(BINDIR)/deepcopy-gen $(BINDIR)/conversion-gen $(BINDIR)/client-gen $(BINDIR)/lister-gen $(BINDIR)/informer-gen $(BINDIR)/dep $(BINDIR)/goreleaser $(BINDIR)/upx
136150

137151
go_generate: depend
138152
go generate $$(go list ./pkg/... ./cmd/...)

hack/minify-binaries.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/sh
2+
3+
set -o errexit
4+
set -o nounset
5+
set -o pipefail
6+
7+
REPO_ROOT=$(cd "$(dirname "${BASH_SOURCE}")/.."; pwd)
8+
9+
find "${REPO_ROOT}/dist/" -executable -type f -print0 | xargs -0 upx

0 commit comments

Comments
 (0)