From 49ac4c8d134fc3ad112cde6ffb9b1dbbb8b0bc45 Mon Sep 17 00:00:00 2001 From: Jerome Petazzoni Date: Mon, 18 Oct 2021 17:04:37 +0200 Subject: [PATCH] Add instructions to generate static binaries Following the discussion in #1478, we don't want to provide (and maintain) static binaries, but giving instructions to produce such builds (with appropriate warnings around these instructions) was considered acceptable, so - here we go! --- install.md | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/install.md b/install.md index 75b563271d..9abdeebd1d 100644 --- a/install.md +++ b/install.md @@ -203,3 +203,40 @@ Finally, after the binary and documentation is built: ```bash sudo make install ``` + +### Building a static binary + +There has been efforts in the past to produce and maintain static builds, but the maintainers prefer to run Skopeo using distro packages or within containers. This is because static builds of Skopeo tend to be unreliable and functionally restricted. Specifically: +- some features of Skopeo depend on non-Go libraries like `libgpgme` and `livdevmapper`, +- generating static Go binaries uses native Go libraries, which don't support e.g. `.local` or LDAP-based name resolution. + +That being said, if you would like to build Skopeo statically, you might be able to do it by: +- exporting environment variable `CGO_ENABLED=0` (disabling CGO causes Go to prefer native libraries when possible, instead of dynamically linking against system libraries) +- passing the `BUILDTAGS=containers_image_openpgp` Make flag (this remove the dependency on `libgpgme` and its companion libraries) +- commenting out the `GO_DYN_FLAGS` line in the Makefile (this flag seems to force the creation of a dynamic executable) + +The following command implements these steps to produce a static binary in the `bin` subdirectory of the repository: + +```bash +sed 's/GO_DYN_FLAGS=/#/' Makefile | +docker run -i -v $PWD:/src -w /src -e CGO_ENABLED=0 golang \ +make -f- BUILDTAGS=containers_image_openpgp +``` + +Keep in mind that the resulting binary is unsupported and might crash randomly. Only use if you know what you're doing! + +For more information, history, and context about static builds, check the following issues: + +- [#669: Static build fails with segmentation violation] +- [#670: Fixing static binary build using container] +- [#755: Remove static and in-container targets from Makefile] +- [#932: Add nix derivation for static builds] +- [#1336: Unable to run skopeo on Fedora 30 (due to dyn lib dependency)] +- [#1478: Publish binary releases to GitHub (request+discussion)] + +[#669]: https://github.com/containers/skopeo/issues/669 +[#670]: https://github.com/containers/skopeo/issues/670 +[#755]: https://github.com/containers/skopeo/issues/755 +[#932]: https://github.com/containers/skopeo/issues/932 +[#1336]: https://github.com/containers/skopeo/issues/1336 +[#1478]: https://github.com/containers/skopeo/issues/1478