Skip to content

Commit

Permalink
Add instructions to generate static binaries
Browse files Browse the repository at this point in the history
Following the discussion in containers#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!
  • Loading branch information
jpetazzo committed Oct 18, 2021
1 parent 8182255 commit 0d45afd
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions install.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,3 +203,32 @@ Finally, after the binary and documentation is built:
```bash
sudo make install
```

### Building a static binary

Static builds of Skopeo tend to be unreliable and functionally restricted. This probably comes from the fact that some Skopeo features depend on non-Go libraries like `libgpgme` and `livdevmapper`. 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.

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 and commits:

- #670
- #755
- #932
- #1336
- #1478
- 0f458eec763626025d5146f00c3809480befe6f3

0 comments on commit 0d45afd

Please sign in to comment.