From 95b91f4a5e010e0c76b72c59d36bc97ebeccb482 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Wed, 30 Jan 2019 15:44:27 -0800 Subject: [PATCH] hack/build: Strip compiled (release) binaries Docs for these settings in [1]. With this change, our compiled Linux binary (without libvirt) drops from ~240 MB to ~130 MB. Alex was concerned about panic support, but with: $ git diff -U1 diff --git a/cmd/openshift-install/main.go b/cmd/openshift-install/main.go index 37f7f96..fbd9889 100644 --- a/cmd/openshift-install/main.go +++ b/cmd/openshift-install/main.go @@ -69,2 +69,4 @@ func newRootCmd() *cobra.Command { func runRootCmd(cmd *cobra.Command, args []string) { + panic("testing, testing") + logrus.SetOutput(ioutil.Discard) panics still produce useful tracebacks: $ openshift-install create install-config panic: testing, testing goroutine 1 [running]: main.runRootCmd(0x8575360, 0x85d4390, 0x0, 0x0) /.../go/src/github.com/openshift/installer/cmd/openshift-install/main.go:70 +0x39 github.com/openshift/installer/vendor/github.com/spf13/cobra.(*Command).execute(0x8575360, 0x85d4390, 0x0, 0x0, 0x8575360, 0x85d4390) /.../go/src/github.com/openshift/installer/vendor/github.com/spf13/cobra/command.go:746 +0x237 github.com/openshift/installer/vendor/github.com/spf13/cobra.(*Command).ExecuteC(0xc42044f180, 0x0, 0xc4209cc500, 0xc42044f2d0) /.../go/src/github.com/openshift/installer/vendor/github.com/spf13/cobra/command.go:852 +0x30a github.com/openshift/installer/vendor/github.com/spf13/cobra.(*Command).Execute(0xc42044f180, 0xc420983ec0, 0x1) /.../go/src/github.com/openshift/installer/vendor/github.com/spf13/cobra/command.go:800 +0x2b main.installerMain() /.../go/src/github.com/openshift/installer/cmd/openshift-install/main.go:50 +0x132 main.main() /.../go/src/github.com/openshift/installer/cmd/openshift-install/main.go:34 +0x39 which looks fine. I've left dev builds unstripped, because [2]: Generally speaking we do not recommend stripping debug info (it's useful, after all)... There's also some stripping discussion in [3]. [1]: https://golang.org/cmd/link/ [2]: https://github.com/golang/go/issues/6853#issuecomment-384918294 [3]: https://github.com/golang/go/issues/19226 Suggested-by: Pedro Jose Amoedo Martinez --- hack/build.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/hack/build.sh b/hack/build.sh index 87d9c454a82..a68c93d596d 100755 --- a/hack/build.sh +++ b/hack/build.sh @@ -38,6 +38,7 @@ export CGO_ENABLED=0 case "${MODE}" in release) + LDFLAGS="${LDFLAGS} -s -w" TAGS="${TAGS} release" if test -n "${RELEASE_IMAGE}" then