From fa879df9ac1c71028a697727f0ad05783bd2243d Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Thu, 24 Oct 2019 16:34:30 +0200 Subject: [PATCH] build static binaries with -tags osusergo 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 - https://github.com/golang/go/commit/62f0127d8104d8266d9a3fb5a87e2f09ec8b6f5b - 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 --- Makefile | 4 ++-- scripts/build/binary | 2 +- scripts/build/plugins | 2 +- scripts/docs/generate-man.sh | 2 +- scripts/docs/generate-yaml.sh | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 656cfb856de8..7c8291ac5bba 100644 --- a/Makefile +++ b/Makefile @@ -12,14 +12,14 @@ clean: ## remove build artifacts .PHONY: test-unit test-unit: ## run unit tests, to change the output format use: GOTESTSUM_FORMAT=(dots|short|standard-quiet|short-verbose|standard-verbose) make test-unit - gotestsum $(TESTFLAGS) -- $${TESTDIRS:-$(shell go list ./... | grep -vE '/vendor/|/e2e/')} + gotestsum $(TESTFLAGS) -- -tags osusergo $${TESTDIRS:-$(shell go list ./... | grep -vE '/vendor/|/e2e/')} .PHONY: test test: test-unit ## run tests .PHONY: test-coverage test-coverage: ## run test coverage - gotestsum -- -coverprofile=coverage.txt $(shell go list ./... | grep -vE '/vendor/|/e2e/') + gotestsum -- -tags osusergo -coverprofile=coverage.txt $(shell go list ./... | grep -vE '/vendor/|/e2e/') .PHONY: fmt fmt: diff --git a/scripts/build/binary b/scripts/build/binary index 41c4196cc801..2296459efd46 100755 --- a/scripts/build/binary +++ b/scripts/build/binary @@ -9,6 +9,6 @@ source ./scripts/build/.variables echo "Building statically linked $TARGET" export CGO_ENABLED=0 -go build -o "${TARGET}" --ldflags "${LDFLAGS}" "${SOURCE}" +go build -tags osusergo -o "${TARGET}" --ldflags "${LDFLAGS}" "${SOURCE}" ln -sf "$(basename "${TARGET}")" build/docker diff --git a/scripts/build/plugins b/scripts/build/plugins index fce2689cdc25..af7fefe1455d 100755 --- a/scripts/build/plugins +++ b/scripts/build/plugins @@ -17,5 +17,5 @@ for p in cli-plugins/examples/* "$@" ; do echo "Building statically linked $TARGET" export CGO_ENABLED=0 - go build -o "${TARGET}" --ldflags "${LDFLAGS}" "github.com/docker/cli/${p}" + go build -tags osusergo -o "${TARGET}" --ldflags "${LDFLAGS}" "github.com/docker/cli/${p}" done diff --git a/scripts/docs/generate-man.sh b/scripts/docs/generate-man.sh index 7412e5baa526..6e703ccab0a6 100755 --- a/scripts/docs/generate-man.sh +++ b/scripts/docs/generate-man.sh @@ -7,7 +7,7 @@ mkdir -p ./man/man1 go install ./vendor/github.com/cpuguy83/go-md2man # Generate man pages from cobra commands -go build -o /tmp/gen-manpages github.com/docker/cli/man +go build -tags osusergo -o /tmp/gen-manpages github.com/docker/cli/man /tmp/gen-manpages --root "$(pwd)" --target "$(pwd)/man/man1" # Generate legacy pages from markdown diff --git a/scripts/docs/generate-yaml.sh b/scripts/docs/generate-yaml.sh index 2a7b0a8980b9..73773f604a7e 100755 --- a/scripts/docs/generate-yaml.sh +++ b/scripts/docs/generate-yaml.sh @@ -4,5 +4,5 @@ set -eu -o pipefail mkdir -p docs/yaml/gen -go build -o build/yaml-docs-generator github.com/docker/cli/docs/yaml +go build -tags osusergo -o build/yaml-docs-generator github.com/docker/cli/docs/yaml build/yaml-docs-generator --root "$(pwd)" --target "$(pwd)/docs/yaml/gen"