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

Commit

Permalink
Merge pull request #287 from simonswine/binary-compression
Browse files Browse the repository at this point in the history
Binary compression
  • Loading branch information
jetstack-bot authored Jun 5, 2018
2 parents a1b6e81 + e9cec1b commit 1f97e08
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 10 deletions.
2 changes: 2 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ builds:
goarch:
- amd64
flags: -tags netgo
hooks:
post: hack/minify-binaries.sh
archive:
format: binary
release:
Expand Down
34 changes: 24 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@ GOPATH ?= /tmp/go

UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Linux)
SHASUM := "sha256sum -c"
SHASUM := sha256sum -c
DEP_URL := https://github.com/golang/dep/releases/download/v0.4.1/dep-linux-amd64
DEP_HASH := 31144e465e52ffbc0035248a10ddea61a09bf28b00784fd3fdd9882c8cbb2315
GORELEASER_URL := https://github.com/goreleaser/goreleaser/releases/download/v0.54.0/goreleaser_Linux_x86_64.tar.gz
GORELEASER_HASH := 895df4293580dd8f9b0daf0ef5456f2238a2fbfc51d9f75dde6e2c63ca4fccc2
GORELEASER_URL := https://github.com/goreleaser/goreleaser/releases/download/v0.77.0/goreleaser_Linux_x86_64.tar.gz
GORELEASER_HASH := aae3c5bb76b282e29940f2654b48b13e51f664368c7589d0e86b391b7ef51cc8
endif
ifeq ($(UNAME_S),Darwin)
SHASUM := "shasum -a 256 -c"
SHASUM := shasum -a 256 -c
DEP_URL := https://github.com/golang/dep/releases/download/v0.4.1/dep-darwin-amd64
DEP_HASH := f170008e2bf8b196779c361a4eaece1b03450d23bbf32d1a0beaa9b00b6a5ab4
GORELEASER_URL := https://github.com/goreleaser/goreleaser/releases/download/v0.54.0/goreleaser_Darwin_x86_64.tar.gz
GORELEASER_HASH := 9d927528a599174eed4d0d6a1ce6bdc810463c4cb105b0d2319c7c63ec642c9b
DEP_HASH := 1544afdd4d543574ef8eabed343d683f7211202a65380f8b32035d07ce0c45ef
GORELEASER_URL := https://github.com/goreleaser/goreleaser/releases/download/v0.77.0/goreleaser_Darwin_x86_64.tar.gz
GORELEASER_HASH := bc6cdf2dfe506f2cce5abceb30da009bfd5bcdb3e52608c536e6c2ceea1f24fe
endif


Expand Down Expand Up @@ -124,15 +124,29 @@ $(BINDIR)/informer-gen:

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

# upx binary packer, only supported on Linux
$(BINDIR)/upx:
ifeq ($(UNAME_S),Linux)
curl -sL -o $@.tar.xz https://github.com/upx/upx/releases/download/v3.94/upx-3.94-amd64_linux.tar.xz
echo "e1fc0d55c88865ef758c7e4fabbc439e4b5693b9328d219e0b9b3604186abe20 $@.tar.xz" | $(SHASUM)
which xz || ( apt-get update && apt-get -y install xz-utils)
cd $(BINDIR) && tar xvf $(shell basename $@).tar.xz upx-3.94-amd64_linux/upx --strip-components=1
rm $@.tar.xz
else
echo -e "#/bin/sh\nexit 0" > $@
chmod +x $@
endif

$(BINDIR)/goreleaser:
curl -sL -o $@.tar.gz $(GORELEASER_URL)
echo "$(GORELEASER_HASH) $@.tar.gz" | $$SHASUM
echo "$(GORELEASER_HASH) $@.tar.gz" | $(SHASUM)
cd $(BINDIR) && tar xzvf $(shell basename $@).tar.gz goreleaser
rm $@.tar.gz

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
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

go_generate: depend
go generate $$(go list ./pkg/... ./cmd/...)
Expand Down
9 changes: 9 additions & 0 deletions hack/minify-binaries.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh

set -o errexit
set -o nounset
set -o pipefail

REPO_ROOT=$(cd "$(dirname "${BASH_SOURCE}")/.."; pwd)

find "${REPO_ROOT}/dist/" -executable -type f -print0 | xargs -0 upx

0 comments on commit 1f97e08

Please sign in to comment.