Skip to content

Commit

Permalink
using symlink to binaries for current platform (openyurtio#202)
Browse files Browse the repository at this point in the history
  • Loading branch information
SataQiu authored and 籁鸣 committed Feb 8, 2021
1 parent cf437a1 commit 0f4b1c9
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 6 deletions.
7 changes: 6 additions & 1 deletion hack/lib/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ build_binaries() {
targets=("${YURT_ALL_TARGETS[@]}")
fi

local target_bin_dir=$(get_binary_dir_with_arch ${YURT_BIN_DIR})
local target_bin_dir=$(get_binary_dir_with_arch ${YURT_LOCAL_BIN_DIR})
mkdir -p ${target_bin_dir}
cd ${target_bin_dir}
for binary in "${targets[@]}"; do
Expand All @@ -88,6 +88,11 @@ build_binaries() {
-ldflags "${goldflags:-}" \
-gcflags "${gcflags:-}" ${goflags} $YURT_ROOT/cmd/$(canonicalize_target $binary)
done

if [[ $(host_platform) == ${HOST_PLATFORM} ]]; then
rm -f "${YURT_BIN_DIR}"
ln -s "${target_bin_dir}" "${YURT_BIN_DIR}"
fi
}

# gen_yamls generates yaml files for user specified components by
Expand Down
7 changes: 6 additions & 1 deletion hack/lib/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,9 @@ canonicalize_target() {
fi

echo $target
}
}

# host_platform returns the host platform determined by golang
host_platform() {
echo "$(go env GOHOSTOS)/$(go env GOHOSTARCH)"
}
1 change: 1 addition & 0 deletions hack/lib/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ YURT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd -P)"
YURT_MOD="$(head -1 $YURT_ROOT/go.mod | awk '{print $2}')"
YURT_OUTPUT_DIR=${YURT_ROOT}/_output
YURT_BIN_DIR=${YURT_OUTPUT_DIR}/bin
YURT_LOCAL_BIN_DIR=${YURT_OUTPUT_DIR}/local/bin

PROJECT_PREFIX=${PROJECT_PREFIX:-yurt}
LABEL_PREFIX=${LABEL_PREFIX:-openyurt.io}
Expand Down
7 changes: 4 additions & 3 deletions hack/lib/release-images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ function build_multi_arch_binaries() {
"--env GIT_VERSION=${GIT_VERSION}"
"--env GIT_COMMIT=${GIT_COMMIT}"
"--env BUILD_DATE=${BUILD_DATE}"
"--env HOST_PLATFORM=$(host_platform)"
)
# use goproxy if build from inside mainland China
[[ $region == "cn" ]] && docker_run_opts+=("--env GOPROXY=https://goproxy.cn")
Expand All @@ -71,7 +72,7 @@ function build_multi_arch_binaries() {
local sub_commands="sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories; \
apk --no-cache add bash git; \
cd /opt/src; umask 0022; \
rm -rf ${YURT_BIN_DIR}/* ;"
rm -rf ${YURT_LOCAL_BIN_DIR}/* ;"
for arch in ${target_arch[@]}; do
sub_commands+="GOARCH=$arch bash ./hack/make-rules/build.sh $(echo ${bin_targets_without_servant[@]}); "
done
Expand All @@ -84,7 +85,7 @@ function build_docker_image() {
for arch in ${target_arch[@]}; do
for binary in "${bin_targets_without_servant[@]}"; do
local binary_name=$(get_output_name $binary)
local binary_path=${YURT_BIN_DIR}/${SUPPORTED_OS}/${arch}/${binary_name}
local binary_path=${YURT_LOCAL_BIN_DIR}/${SUPPORTED_OS}/${arch}/${binary_name}
if [ -f ${binary_path} ]; then
local docker_build_path=${DOCKER_BUILD_BASE_IDR}/${SUPPORTED_OS}/${arch}
local docker_file_path=${docker_build_path}/Dockerfile.${binary_name}-${arch}
Expand Down Expand Up @@ -146,7 +147,7 @@ build_images() {
# Always clean first
rm -Rf ${YURT_OUTPUT_DIR}
rm -Rf ${DOCKER_BUILD_BASE_IDR}
mkdir -p ${YURT_BIN_DIR}
mkdir -p ${YURT_LOCAL_BIN_DIR}
mkdir -p ${YURT_IMAGE_DIR}
mkdir -p ${DOCKER_BUILD_BASE_IDR}

Expand Down
2 changes: 1 addition & 1 deletion hack/make-rules/build-e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function build_e2e() {
goflags=${GOFLAGS:-}


local target_bin_dir=$(get_binary_dir_with_arch ${YURT_BIN_DIR})
local target_bin_dir=$(get_binary_dir_with_arch ${YURT_LOCAL_BIN_DIR})
mkdir -p ${target_bin_dir}
cd ${target_bin_dir}
echo "Building ${YURT_E2E_TARGETS}"
Expand Down
2 changes: 2 additions & 0 deletions hack/make-rules/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@ set -x
YURT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd -P)"
source "${YURT_ROOT}/hack/lib/init.sh"

HOST_PLATFORM=${HOST_PLATFORM:-"$(host_platform)"}

build_binaries "$@"

0 comments on commit 0f4b1c9

Please sign in to comment.