Skip to content

Commit

Permalink
build: copy obclient package based on cpu architecture (#450)
Browse files Browse the repository at this point in the history
build: remove nvs temp files before nvs use for avoid operation require interaction

build: remove nvs temp files before nvs use for avoid operation require interaction

refine

build: use nvs link instead of nvs use for keep version
  • Loading branch information
yizhouxw authored Oct 9, 2023
1 parent 1aaf663 commit 5fcb507
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 21 deletions.
5 changes: 2 additions & 3 deletions script/build_rpm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

# read parameters
rpm_release=${1:-"1"}
rpm_arch=${2:-"x86"}

# read environment variables
sync_submodule_flag=${SYNC_SUBMODULE:-"1"}
Expand Down Expand Up @@ -82,13 +81,13 @@ function build_rpm() {

if [ "${fetch_from_oss_flag}" == "1" ]; then
log_info "oss fetch obclient start"
if ! oss_fetch_obclient "${rpm_arch}"; then
if ! oss_fetch_obclient; then
log_error "oss fetch obclient failed"
return 5
fi
log_info "oss fetch obclient done"
else
if ! copy_obclient "${rpm_arch}"; then
if ! copy_obclient; then
log_error "copy obclient.tar.gz to import folder failed"
return 5
fi
Expand Down
5 changes: 2 additions & 3 deletions script/build_rpm_without_sqlconsole.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

# read parameters
rpm_release=${1:-"1"}
rpm_arch=${2:-"x86"}

# read environment variables
fetch_from_oss_flag=${FETCH_FROM_OSS:-"0"}
Expand All @@ -24,13 +23,13 @@ function build_rpm_without_sqlconsole() {

if [ "${fetch_from_oss_flag}" == "1" ]; then
log_info "oss fetch obclient start"
if ! oss_fetch_obclient "${rpm_arch}"; then
if ! oss_fetch_obclient; then
log_error "oss fetch obclient failed"
return 5
fi
log_info "oss fetch obclient done"
else
if ! copy_obclient "${rpm_arch}"; then
if ! copy_obclient; then
log_error "copy obclient.tar.gz to import folder failed"
return 5
fi
Expand Down
67 changes: 52 additions & 15 deletions script/functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ SQL_CONSOLE_DIR="client"
NVS_HOME="$HOME/.nvs"
RPM_DEFAULT_INSTALL_PREFIX="/opt"
NVS_VERSION="v1.6.0"
NODE_VERSION="14"
NODE_VERSION="16.14.0"
OSS_RETRY_TIMES=50
OBCLIENT_VERSION=1_2_8

Expand All @@ -16,8 +16,8 @@ export ODC_SCRIPT_DIR=$(dirname ${ODC_FUNCTION_SCRIPT_SOURCE})
export ODC_DIR=$(dirname ${ODC_SCRIPT_DIR})

# oss related environment variables
export ODC_OSS_ENDPOINT=${oss_endpoint:-cn-hangzhou-alipay-b-internal.oss-internal.aliyun-inc.com}
export ODC_OSS_BUCKET_NAME=${oss_bucket_name:-antsys-obodc-build}
export ODC_OSS_ENDPOINT=${oss_endpoint:-}
export ODC_OSS_BUCKET_NAME=${oss_bucket_name:-}
export ODC_OSS_ACCESS_KEY_ID=${oss_key_id:-}
export ODC_OSS_ACCESS_KEY_SECRET=${oss_key_secret:-}
export ODC_OSS_CONFIG_FILE_NAME=$(echo ~/.odcossutilconfig)
Expand Down Expand Up @@ -133,13 +133,13 @@ function init_node_env() {
func_echo "install nvs succeed"
fi

if ! nvs use node/${NODE_VERSION}; then
if ! nvs link node/${NODE_VERSION}; then
func_echo "node ${NODE_VERSION} not installed, will install"
if ! nvs add node/${NODE_VERSION}; then
func_echo "nvs add ${NODE_VERSION} failed"
return 3
fi
if ! nvs use node/${NODE_VERSION}; then
if ! nvs link node/${NODE_VERSION}; then
func_echo "nvs use ${NODE_VERSION} failed"
return 4
fi
Expand All @@ -165,6 +165,11 @@ function init_node_env() {
return 0
}

# clean nvs temp files for avoid nvs use operation require interaction
function clean_nvs_temp_files() {
rm -fv ${NVS_HOME}/nvs_tmp_*.sh
}

#############################################
# update submodule
# RETURN: 0 if succeed, non-zero if failed
Expand Down Expand Up @@ -294,7 +299,7 @@ function maven_build_jar() {
}

function oss_fetch_obclient() {
local rpm_arch=$1
local rpm_arch=$(get_cpu_arch)
if ! config_ossutil; then
log_error "config ossutil failed"
return 1
Expand All @@ -311,23 +316,19 @@ function oss_fetch_obclient() {
}

#
# copy architecture matched obclient.tar.gz to `import/` folder
# copy architecture matched obclient install package to `import/obclient.tar.gz`
#
function copy_obclient() {
local rpm_arch=$1
if [ -z "$rpm_arch" ]; then
echo "Usage: copy_obclient <rpm_arch>"
return 1
fi

local source_obclient_file_path="${ODC_DIR}/build-resource/obclient/${OBCLIENT_VERSION}/${rpm_arch}/obclient.tar.gz"
local cpu_arch=$(get_cpu_arch)
local source_obclient_file_path="${ODC_DIR}/import/obclient_${cpu_arch}.tar.gz"
local target_obclient_file_path="${ODC_DIR}/import/obclient.tar.gz"

if [[ -f "${source_obclient_file_path}" ]]; then
echo "${source_obclient_file_path} exists, will copy to ${target_obclient_file_path} ..."
cp --force --verbose "${source_obclient_file_path}" "${target_obclient_file_path}"
return $?
else
echo "${source_obclient_file_path} not exists, skip copy."
return 0
fi
}

Expand Down Expand Up @@ -402,3 +403,39 @@ function print_env_info() {
echo "--- environment check end ---"
echo "-------------------------------"
}

# get os version
# optional return value: linux, macos, unknown
function get_os_version() {
os_version=$(uname -s)
case "$os_version" in
Linux*)
os_version="linux"
;;
Darwin*)
os_version="macos"
;;
*)
os_version="unknown"
;;
esac
echo "${os_version}"
}

# get cpu architecture
# optional return value: x86, aarch, unknown
function get_cpu_arch() {
local cpu_arch=$(uname -m)
case "$cpu_arch" in
x86*)
cpu_arch="x86"
;;
aarch*)
cpu_arch="aarch"
;;
*)
cpu_arch="unknown"
;;
esac
echo "${cpu_arch}"
}

0 comments on commit 5fcb507

Please sign in to comment.