Skip to content

Commit

Permalink
build static binaries with -tags osusergo
Browse files Browse the repository at this point in the history
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 <github@gone.nl>
  • Loading branch information
thaJeztah committed Oct 24, 2019
1 parent 146d29c commit fa879df
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion scripts/build/binary
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion scripts/build/plugins
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion scripts/docs/generate-man.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion scripts/docs/generate-yaml.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit fa879df

Please sign in to comment.