set CGO_ENABLED=0 when building release artifacts #60
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This project's release artifacts are currently built in a VM using GitHub Actions'
ubuntu-latest
image.container-canary/.github/workflows/upload-release-assets.yaml
Line 11 in a4f5c79
As of today, that's Ubuntu 22.04 (actions/runner-images), which has glibc 2.35.
Those builds are dynamically linking to glibc, and using some symbols from new-ish versions. As a result, using them on a just-slightly-older Linux environment (e.g. Ubuntu 20.04, which has glibc 2.31), results in errors like the following:
This proposes setting
CGO_ENABLED=0
when cross-compiling for Linux, so the artifact will statically link in what it needs and therefore be usable on systems with older glibc.Notes for Reviewers
How I tested this
built with this setting on and off on Ubuntu 22.04, tested on Ubuntu 20.04 (click for details)
Built inside an Ubuntu 22.04 image
Tried using those on Ubuntu 20.04. The CGO-enabled one failed to run.
But the no-cgo one worked!
And the no-cgo one worked validating an image! Ran the following outside of Docker, on an Ubuntu 20.04 VM.
bin-no-cgo/canary_linux_amd64 validate \ --file https://raw.githubusercontent.com/NVIDIA/container-canary/main/examples/kubeflow.yaml \ "ghcr.io/dask/dask-notebook"
Why not set this in the CI environment?
I chose to set this inline in the 2 Linux builds in
make package
so that if you runmake package
locally on a Linux system, it'll produce a similar artifact to the one produced in CI. To hopefully improve the chance of local tests catching issues.But happy to change to any of these alternatives if someone has a compelling reason:
go build
commands inmake package
(not just Linux)Won't statically linking make the binary bigger?
I didn't find any meaningful change in binary size as a result of doing this. With and without
CGO_ENABLED
,canary_linux_amd64
was about 21MB.References