Skip to content

Commit

Permalink
hack/build: Strip compiled (release) binaries
Browse files Browse the repository at this point in the history
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]: golang/go#6853 (comment)
[3]: golang/go#19226

Suggested-by: Pedro Jose Amoedo Martinez
  • Loading branch information
wking committed Jan 31, 2019
1 parent d3ff3af commit 95b91f4
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions hack/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 95b91f4

Please sign in to comment.