init
This commit is contained in:
43
script/build/quick_build.sh
Normal file
43
script/build/quick_build.sh
Normal file
@@ -0,0 +1,43 @@
|
||||
#!/bin/bash
|
||||
file_path=$(
|
||||
cd "$(dirname "$0")" || exit
|
||||
pwd
|
||||
)/../..
|
||||
# shellcheck source=./util.sh
|
||||
source "${file_path}"/script/build/util.sh
|
||||
|
||||
quickBuildService() {
|
||||
file_path="$1"
|
||||
pkg_name="$2"
|
||||
service_name="$3"
|
||||
flags=$(getFlags)
|
||||
|
||||
cd "${file_path}/${service_name}/cmd" || exit
|
||||
echo "┌ start building ${service_name} service"
|
||||
go build -ldflags "${flags}" -o "${file_path}/${pkg_name}/${service_name}" || exit
|
||||
echo "└ building ${service_name} service success"
|
||||
}
|
||||
|
||||
mkDir() {
|
||||
file_path="$1"
|
||||
pkg_path="$2"
|
||||
|
||||
rm -rf ${file_path}/${pkg_path}
|
||||
mkdir -pv "${file_path}/${pkg_path}"
|
||||
}
|
||||
|
||||
env_type="$1"
|
||||
initOS ${env_type}
|
||||
os=$(initOS ${env_type})
|
||||
|
||||
api_version=""
|
||||
project_name="im"
|
||||
now_time=$(date "+%Y_%m_%d")
|
||||
pkg_path="${project_name}_bin_${now_time}_${os}"
|
||||
|
||||
mkDir "${file_path}" "${pkg_path}"
|
||||
|
||||
quickBuildService "${file_path}" "${pkg_path}" "comet"
|
||||
quickBuildService "${file_path}" "${pkg_path}" "logic"
|
||||
|
||||
|
||||
26
script/build/util.sh
Normal file
26
script/build/util.sh
Normal file
@@ -0,0 +1,26 @@
|
||||
#!/bin/bash
|
||||
|
||||
# 获取编译参数
|
||||
getFlags() {
|
||||
main_path="main"
|
||||
go_version=$(go version | awk '{ print $3 }')
|
||||
build_time=$(date "+%Y-%m-%d %H:%M:%S %Z")
|
||||
git_commit=$(git rev-parse --short=10 HEAD)
|
||||
flags="-X '${main_path}.goVersion=${go_version}' -X '${main_path}.buildTime=${build_time}' -X '${main_path}.gitCommit=${git_commit}' -X 'google.golang.org/protobuf/reflect/protoregistry.conflictPolicy=warn'"
|
||||
echo "${flags}"
|
||||
}
|
||||
|
||||
# 设置目标打包环境
|
||||
# 默认 linux amd64
|
||||
initOS() {
|
||||
env_type="amd64"
|
||||
if [ -n "$1" ]; then
|
||||
env_type="$1"
|
||||
fi
|
||||
|
||||
export GOOS=linux
|
||||
export GOARCH=${env_type}
|
||||
export GOLANG_PROTOBUF_REGISTRATION_CONFLICT=warn
|
||||
|
||||
echo "linux_${env_type}"
|
||||
}
|
||||
Reference in New Issue
Block a user