Merge pull request #5574 from ArtfulCoder/static_linking

build kube-apiserver, kube-scheduler and kube-controller-manager statically
This commit is contained in:
Victor Marmol 2015-03-17 16:33:11 -07:00
commit c2ba26fb9e

View File

@ -79,6 +79,17 @@ readonly KUBE_ALL_TARGETS=(
) )
readonly KUBE_ALL_BINARIES=("${KUBE_ALL_TARGETS[@]##*/}") readonly KUBE_ALL_BINARIES=("${KUBE_ALL_TARGETS[@]##*/}")
readonly KUBE_STATIC_LIBRARIES=(
kube-apiserver
kube-controller-manager
kube-scheduler
)
kube::golang::is_statically_linked_library() {
local e
for e in "${KUBE_STATIC_LIBRARIES[@]}"; do [[ "$1" == *"/$e" ]] && return 0; done;
return 1;
}
# kube::binaries_from_targets take a list of build targets and return the # kube::binaries_from_targets take a list of build targets and return the
# full go package to be built # full go package to be built
@ -280,7 +291,7 @@ kube::golang::build_binaries() {
local binaries local binaries
binaries=($(kube::golang::binaries_from_targets "${targets[@]}")) binaries=($(kube::golang::binaries_from_targets "${targets[@]}"))
local platform local platform
for platform in "${platforms[@]}"; do for platform in "${platforms[@]}"; do
kube::golang::set_platform_envs "${platform}" kube::golang::set_platform_envs "${platform}"
@ -297,15 +308,31 @@ kube::golang::build_binaries() {
if [[ ${GOOS} == "windows" ]]; then if [[ ${GOOS} == "windows" ]]; then
bin="${bin}.exe" bin="${bin}.exe"
fi fi
go build -o "${output_path}/${bin}" \
if kube::golang::is_statically_linked_library "${binary}"; then
CGO_ENABLED=0 go build -installsuffix cgo -o "${output_path}/${bin}" \
"${goflags[@]:+${goflags[@]}}" \ "${goflags[@]:+${goflags[@]}}" \
-ldflags "${version_ldflags}" \ -ldflags "${version_ldflags}" \
"${binary}" "${binary}"
else
go build -o "${output_path}/${bin}" \
"${goflags[@]:+${goflags[@]}}" \
-ldflags "${version_ldflags}" \
"${binary}"
fi
done done
else else
go install "${goflags[@]:+${goflags[@]}}" \ for binary in "${binaries[@]}"; do
-ldflags "${version_ldflags}" \ if kube::golang::is_statically_linked_library "${binary}"; then
"${binaries[@]}" CGO_ENABLED=0 go install -installsuffix cgo "${goflags[@]:+${goflags[@]}}" \
-ldflags "${version_ldflags}" \
"${binary}"
else
go install "${goflags[@]:+${goflags[@]}}" \
-ldflags "${version_ldflags}" \
"${binary}"
fi
done
fi fi
done done
) )