mirror of
https://github.com/docker/cli.git
synced 2026-09-24 15:30:10 -05:00
dockerfile based binary building
Using cross compilation toolchains that work from any platform Adds darwin/arm64 support and bake targets. Static and dynamic binary targets are available, both with glibc and musl. Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
This commit is contained in:
+57
-7
@@ -1,14 +1,64 @@
|
||||
#!/usr/bin/env bash
|
||||
#!/usr/bin/env sh
|
||||
#
|
||||
# Build a static binary for the host OS/ARCH
|
||||
#
|
||||
|
||||
set -eu -o pipefail
|
||||
set -eu
|
||||
|
||||
source ./scripts/build/.variables
|
||||
: "${CGO_ENABLED=}"
|
||||
: "${GO_LINKMODE=static}"
|
||||
: "${GO_BUILDMODE=}"
|
||||
: "${GO_BUILDTAGS=}"
|
||||
: "${GO_STRIP=}"
|
||||
|
||||
echo "Building statically linked $TARGET"
|
||||
export CGO_ENABLED=0
|
||||
go build -o "${TARGET}" --ldflags "${LDFLAGS}" "${SOURCE}"
|
||||
set -x
|
||||
. ./scripts/build/.variables
|
||||
|
||||
ln -sf "$(basename "${TARGET}")" build/docker
|
||||
if [ -z "$CGO_ENABLED" ]; then
|
||||
case "$(go env GOOS)" in
|
||||
linux)
|
||||
case "$(go env GOARCH)" in
|
||||
amd64|arm64|arm|s390x)
|
||||
CGO_ENABLED=1
|
||||
;;
|
||||
*)
|
||||
CGO_ENABLED=0
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
darwin|windows)
|
||||
CGO_ENABLED=1
|
||||
;;
|
||||
*)
|
||||
CGO_ENABLED=0
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
export CGO_ENABLED
|
||||
if [ "$CGO_ENABLED" = "1" ] && [ "$(go env GOOS)" != "windows" ]; then
|
||||
case "$(go env GOARCH)" in
|
||||
mips*|ppc64)
|
||||
# pie build mode is not supported on mips architectures
|
||||
;;
|
||||
*)
|
||||
GO_BUILDMODE="-buildmode=pie"
|
||||
;;
|
||||
esac
|
||||
GO_BUILDTAGS="$GO_BUILDTAGS pkcs11"
|
||||
fi
|
||||
|
||||
if [ "$CGO_ENABLED" = "1" ] && [ "$GO_LINKMODE" = "static" ] && [ "$(go env GOOS)" = "linux" ]; then
|
||||
LDFLAGS="$LDFLAGS -extldflags -static"
|
||||
fi
|
||||
|
||||
if [ -n "$GO_STRIP" ]; then
|
||||
LDFLAGS="$LDFLAGS -s -w"
|
||||
fi
|
||||
|
||||
echo "Building $GO_LINKMODE $(basename "${TARGET}")"
|
||||
|
||||
export GO111MODULE=auto
|
||||
|
||||
go build -o "${TARGET}" -tags "${GO_BUILDTAGS}" --ldflags "${LDFLAGS}" ${GO_BUILDMODE} "${SOURCE}"
|
||||
|
||||
ln -sf "$(basename "${TARGET}")" "$(dirname "${TARGET}")/docker"
|
||||
|
||||
Reference in New Issue
Block a user