github.com/polarismesh/polaris@v1.17.8/release/build.sh (about) 1 #!/bin/bash 2 # Tencent is pleased to support the open source community by making Polaris available. 3 # 4 # Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. 5 # 6 # Licensed under the BSD 3-Clause License (the "License"); 7 # you may not use this file except in compliance with the License. 8 # You may obtain a copy of the License at 9 # 10 # https://opensource.org/licenses/BSD-3-Clause 11 # 12 # Unless required by applicable law or agreed to in writing, software distributed 13 # under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 14 # CONDITIONS OF ANY KIND, either express or implied. See the License for the 15 # specific language governing permissions and limitations under the License. 16 17 set -e 18 19 if [[ $(uname) == 'Darwin' ]]; then 20 realpath() { 21 [[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}" 22 } 23 24 md5sum() { 25 md5 $* 26 } 27 fi 28 29 workdir=$(dirname $(dirname $(realpath $0))) 30 version=$(cat version 2>/dev/null) 31 bin_name="polaris-server" 32 33 if [ "${GOOS}" == "windows" ]; then 34 bin_name="polaris-server.exe" 35 fi 36 37 if [ "${GOOS}" == "" ]; then 38 GOOS=$(go env GOOS) 39 fi 40 41 if [ "${GOARCH}" == "" ]; then 42 GOARCH=$(go env GOARCH) 43 fi 44 45 if [ $# == 1 ]; then 46 version=$1 47 fi 48 if [ $# == 2 ]; then 49 version=$1 50 export GOARCH=$2 51 fi 52 53 folder_name="polaris-server-release_${version}.${GOOS}.${GOARCH}" 54 pkg_name="${folder_name}.zip" 55 echo "GOOS is ${GOOS}, GOARCH is ${GOARCH}, binary name is ${bin_name}" 56 57 echo "workdir=${workdir}" 58 cd ${workdir} 59 60 # 清理环境 61 rm -rf ${folder_name} 62 rm -f "${pkg_name}" 63 rm -f ${bin_name} 64 65 # 禁止 CGO_ENABLED 参数打开 66 export CGO_ENABLED=0 67 68 build_date=$(date "+%Y%m%d.%H%M%S") 69 package="github.com/polarismesh/polaris-server/common/version" 70 sqldb_res="store/mysql" 71 GOARCH=${GOARCH} GOOS=${GOOS} go build -o ${bin_name} -ldflags="-X ${package}.Version=${version} -X ${package}.BuildDate=${build_date}" 72 73 # 打包 74 mkdir -p ${folder_name} 75 cp ${bin_name} ${folder_name} 76 mkdir -p ${folder_name}/${sqldb_res} 77 cp -r ${sqldb_res}/scripts/* ${folder_name}/${sqldb_res} 78 cp -r release/tool ${folder_name}/ 79 cp -r release/conf ${folder_name}/ 80 zip -r "${pkg_name}" ${folder_name} 81 md5sum ${pkg_name} >"${pkg_name}.md5sum"