I understand that the question might look too specific, but I think the answers can also be useful for other areas.
The real problem I'm having: Given an arbitrary container image that has sh
binary, download a file from Google Cloud Storage.
Since the downloader binary does not exist in the user image I had an idea to put the encoded binary in the command-line (a bit similar to inline scripts like python -c <code>
). However there are limitation on the command-line size (~1MiB), so the binary shound be smaller that that.
I've decided to use Go due to the ease of creating statically-linked binaries and people reporting that GO binaries are small.
I've written a Go program that uses the cloud.google.com/go/storage
module to create a client and read the blob storage.NewClient().Bucket(bucket).Object(object).NewReader()
.
Unfortunately, the binary for the simple program turns out to be 15MiB.
Adding go build -ldflags=" -s -w"
(as suggested in How to reduce compiled file size?) reduces that to 10MiB. That's still order of magnitude more than my size budget.
Are there binary optimizations or pruning techniques that I could use?
Should I look at some other language (e.g. C++) if I wish to have a smaller binary?
Will I have better luck if I try to use some generic REST client library? //Looks like no - the size of stripped Go program that uses http.Get
is 5MiB.