-
Notifications
You must be signed in to change notification settings - Fork 2k
build static binaries with -tags osusergo #2162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
ping @kolyshkin @silvin-lubecki @tiborvass PTAL |
When building a static binary, the osusergo build-tag should be used so that a pure go implementation of the `os/user` package is used. relates to: - golang/go#23265 os/user: add build tags to select cgo-vs-go implementation, like net package - golang/go@62f0127 - golang/go#24787 os/user: LookupId panics on Linux+glibc static build - golang/go#26492 cmd/go: build: add -static flag - golang/go#12058 cmd/go: #cgo pkg-config: add conditional --static flag to pkg-config - moby/moby#39994 homedir: add cgo or osusergo buildtag constraints for unix Signed-off-by: Sebastiaan van Stijn <[email protected]>
86aac9c
to
fa879df
Compare
|
So unless we want to try enabling cgo for a static build, i'd rather close this one |
IOW, if you're not having below errors, adding
|
So, in case we would want to use CGO for static binary, we need to add diff --git a/scripts/build/binary b/scripts/build/binary
index 41c4196cc..3440dfcf6 100755
--- a/scripts/build/binary
+++ b/scripts/build/binary
@@ -8,7 +8,8 @@ set -eu -o pipefail
source ./scripts/build/.variables
echo "Building statically linked $TARGET"
-export CGO_ENABLED=0
-go build -o "${TARGET}" --ldflags "${LDFLAGS}" "${SOURCE}"
+LDFLAGS="-extldflags -static $LDFLAGS"
+TAGS="-tags netgo,osusergo,static_build"
+go build -o "${TARGET}" ${TAGS} --ldflags "${LDFLAGS}" "${SOURCE}"
ln -sf "$(basename "${TARGET}")" build/docker but for now I don't see a reason to do that ([re-]enable CGO for static build) |
@kolyshkin this is in preparation of #2158. Where, because of moby/moby#39994, everything breaks if we don't set the |
we should probably wait for the outcome of moby/moby#40134 |
This is no longer needed, now that moby/moby#40134 Revert "homedir: add cgo or osusergo buildtag constraints for unix" is merged |
Yup it is already closed, I didn't see it |
When building a static binary, the osusergo build-tag
should be used so that a pure go implementation of the
os/user
package is used.relates to:
implementation, like net package
- Description for the changelog