From 197ec1c2ab70cd4155349c6777049709578731fe Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Thu, 19 Jul 2018 11:01:27 +0300 Subject: [PATCH] Add osusergo build tar for static binaries Go 1.11 includes a fix to os/user to be working in a static binary (fixing https://github.com/golang/go/issues/23265). The fix requires `osusergo` build tag to be set for static binaries, which is what this commit adds (also for containerd). [v2: sort build tags alphabetically] Signed-off-by: Kir Kolyshkin Upstream-commit: 70cdb1c66429582ecfdc5abed67189dd90ab7572 Component: engine --- components/engine/hack/dockerfile/install/containerd.installer | 2 +- components/engine/hack/make.sh | 2 +- components/engine/hack/make/dynbinary-daemon | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/components/engine/hack/dockerfile/install/containerd.installer b/components/engine/hack/dockerfile/install/containerd.installer index dceae495c40..4be15a6abfb 100755 --- a/components/engine/hack/dockerfile/install/containerd.installer +++ b/components/engine/hack/dockerfile/install/containerd.installer @@ -14,7 +14,7 @@ install_containerd() { ( - export BUILDTAGS='static_build netgo' + export BUILDTAGS='netgo osusergo static_build' export EXTRA_FLAGS='-buildmode=pie' export EXTRA_LDFLAGS='-extldflags "-fno-PIC -static"' diff --git a/components/engine/hack/make.sh b/components/engine/hack/make.sh index cd9232a4a5c..bc0c2a39d0d 100755 --- a/components/engine/hack/make.sh +++ b/components/engine/hack/make.sh @@ -145,7 +145,7 @@ LDFLAGS_STATIC='' EXTLDFLAGS_STATIC='-static' # ORIG_BUILDFLAGS is necessary for the cross target which cannot always build # with options like -race. -ORIG_BUILDFLAGS=( -tags "autogen netgo static_build $DOCKER_BUILDTAGS" -installsuffix netgo ) +ORIG_BUILDFLAGS=( -tags "autogen netgo osusergo static_build $DOCKER_BUILDTAGS" -installsuffix netgo ) # see https://github.com/golang/go/issues/9369#issuecomment-69864440 for why -installsuffix is necessary here # When $DOCKER_INCREMENTAL_BINARY is set in the environment, enable incremental diff --git a/components/engine/hack/make/dynbinary-daemon b/components/engine/hack/make/dynbinary-daemon index d1c0070e62e..c712bfefc28 100644 --- a/components/engine/hack/make/dynbinary-daemon +++ b/components/engine/hack/make/dynbinary-daemon @@ -5,6 +5,7 @@ set -e export IAMSTATIC='false' export LDFLAGS_STATIC_DOCKER='' export BUILDFLAGS=( "${BUILDFLAGS[@]/netgo /}" ) # disable netgo, since we don't need it for a dynamic binary + export BUILDFLAGS=( "${BUILDFLAGS[@]/osusergo /}" ) # ditto for osusergo export BUILDFLAGS=( "${BUILDFLAGS[@]/static_build /}" ) # we're not building a "static" binary here source "${MAKEDIR}/.binary" )