👌 更新脚本代码
parent
f2089be3dd
commit
8555698a7a
|
@ -0,0 +1,62 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# 打印UI页头信息
|
||||
function printHeadInfo() {
|
||||
cat << EOF
|
||||
***********************************************************************************
|
||||
* 欢迎使用项目引导式发布脚本。
|
||||
* 输入任意键进入脚本操作。
|
||||
***********************************************************************************
|
||||
EOF
|
||||
}
|
||||
|
||||
# 打印UI页尾信息
|
||||
function printFootInfo() {
|
||||
cat << EOF
|
||||
|
||||
|
||||
***********************************************************************************
|
||||
* 安装过程结束。
|
||||
* 输入任意键进入脚本操作。
|
||||
* 如果不想安装其他应用,输入 exit 回车或输入 <CTRL-C> 退出。
|
||||
***********************************************************************************
|
||||
EOF
|
||||
}
|
||||
|
||||
# 检查文件是否存在,不存在则退出脚本
|
||||
function checkFileExist() {
|
||||
if [ ! -f "$1" ]
|
||||
then
|
||||
echo "关键文件 $1 找不到,脚本执行结束"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# 检查文件夹是否存在,不存在则创建
|
||||
function createFolderIfNotExist() {
|
||||
if [ ! -d "$1" ];then
|
||||
mkdir -p "$1"
|
||||
fi
|
||||
}
|
||||
|
||||
# 记录发布的版本信息
|
||||
# 第一个参数为日志所在路径
|
||||
# 第二个参数为应用名称
|
||||
# 第三个参数为代码分支
|
||||
# 第四个参数为运行环境
|
||||
function saveVersionInfo() {
|
||||
if [ "$1" == "" ] || [ "$2" == "" ] || [ "$3" == "" ] || [ "$4" == "" ]; then
|
||||
echo "缺少参数,退出"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
VERSION_LOG_FILE=$1/$2-version.log
|
||||
rm -rf ${VERSION_LOG_FILE}
|
||||
touch ${VERSION_LOG_FILE}
|
||||
chmod 777 ${VERSION_LOG_FILE}
|
||||
|
||||
echo -e "\n=================== $2 ===================" >> ${VERSION_LOG_FILE}
|
||||
echo "Branch is: $3" >> ${VERSION_LOG_FILE}
|
||||
echo "Profile is: $4" >> ${VERSION_LOG_FILE}
|
||||
echo "CommitID is : $(git log --pretty=oneline -1)" >> ${VERSION_LOG_FILE}
|
||||
}
|
|
@ -1,68 +1,76 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
#################################################################################
|
||||
# 前端应用发布脚本
|
||||
# Author: Zhang Peng
|
||||
# 环境要求:Nvm、Node.js
|
||||
#################################################################################
|
||||
|
||||
# 检查脚本参数,如必要参数未传入,退出脚本。
|
||||
function checkInput() {
|
||||
if [ "${branch}" == "" ]; then
|
||||
echo "请输入脚本参数:branch"
|
||||
echo " branch: git分支(必填)。如 feature/1.1.16, master"
|
||||
echo "例:./js-app-release.sh feature/1.1.16"
|
||||
exit 0
|
||||
echo " branch: git分支。如 feature/1.1.16, master"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# 检查文件是否存在,不存在则退出脚本
|
||||
function checkFileExist() {
|
||||
if [ ! -f "$1" ]
|
||||
then
|
||||
echo "关键文件 $1 找不到,脚本执行结束"
|
||||
exit 0
|
||||
fi
|
||||
}
|
||||
|
||||
# 检查文件夹是否存在,不存在则创建
|
||||
function createFolderIfNotExist() {
|
||||
if [ ! -d "$1" ];then
|
||||
mkdir -p "$1"
|
||||
fi
|
||||
}
|
||||
##############################__MAIN__########################################
|
||||
# 设置全局常量
|
||||
SCRIPT_DIR=$(cd "$(dirname "$0")"; pwd)
|
||||
SOURCE_DIR=/home/zp/source/
|
||||
APP_NAME=XXX
|
||||
UPDATE_CODE_SCRIPT_FILE=${SCRIPT_DIR}/update-code.sh
|
||||
|
||||
# 0. 获取传入参数并检查
|
||||
branch=`echo $1`
|
||||
profile=`echo $2`
|
||||
checkInput
|
||||
checkFileExist ${UPDATE_CODE_SCRIPT_FILE}
|
||||
createFolderIfNotExist ${SOURCE_DIR}
|
||||
|
||||
echo ">>>>>>>>>>>>>> 1. 停止应用"
|
||||
# 有则加,无则过
|
||||
|
||||
echo ">>>>>>>>>>>>>> 2. 更新代码"
|
||||
${UPDATE_CODE_SCRIPT_FILE} ${APP_NAME} ${branch} ${SOURCE_DIR}
|
||||
execode=$?
|
||||
if [ "${execode}" == "0" ]; then
|
||||
# 脚本主方法
|
||||
function main() {
|
||||
echo ">>>>>>>>>>>>>> 1. 更新代码"
|
||||
${SCRIPT_DIR}/update-code.sh ${APP} ${branch} ${SOURCE_DIR}
|
||||
execode=$?
|
||||
if [ "${execode}" == "0" ]; then
|
||||
echo "更新代码成功"
|
||||
else
|
||||
else
|
||||
echo "更新代码失败"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
echo ">>>>>>>>>>>>>> 3. 替换配置"
|
||||
# 有则加,无则过
|
||||
echo ">>>>>>>>>>>>>> 2. 替换配置"
|
||||
# 有的应用此处可能需要替换配置
|
||||
|
||||
echo ">>>>>>>>>>>>>> 4. 构建启动"
|
||||
cd ${SOURCE_DIR}/${APP_NAME}
|
||||
source "${HOME}/.nvm/nvm.sh"
|
||||
nvm use 8.9
|
||||
npm install
|
||||
npm run build
|
||||
echo ">>>>>>>>>>>>>> 3. 构建编译"
|
||||
cd ${SOURCE_DIR}/${APP}
|
||||
source "${HOME}/.nvm/nvm.sh"
|
||||
nvm use 8.9
|
||||
npm install
|
||||
if [ "${profile}" == "develop" ] || [ "${profile}" == "test" ]; then
|
||||
npm start
|
||||
elif [ "${profile}" == "preview" ] || [ "${profile}" == "product" ]; then
|
||||
npm run build
|
||||
fi
|
||||
execode=$?
|
||||
if [ "${execode}" == "0" ]; then
|
||||
echo "构建编译成功"
|
||||
else
|
||||
echo "构建编译失败"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo ">>>>>>>>>>>>>> 4. 记录发布的版本信息"
|
||||
saveVersionInfo ${LOG_DIR} ${APP} ${branch} ${profile}
|
||||
|
||||
echo ">>>>>>>>>>>>>> 发布应用结束"
|
||||
}
|
||||
|
||||
######################################## MAIN ########################################
|
||||
# 设置环境变量
|
||||
export LANG="zh_CN.UTF-8"
|
||||
|
||||
# 设置全局常量
|
||||
APP=blog
|
||||
LOG_DIR=/home/zp/log
|
||||
SOURCE_DIR=/home/zp/source
|
||||
SCRIPT_DIR=$(cd "$(dirname "$0")"; pwd)
|
||||
|
||||
# 装载函数库
|
||||
. ${SCRIPT_DIR}/helper.sh
|
||||
|
||||
# 获取传入参数并检查
|
||||
branch=`echo $1`
|
||||
profile=`echo $2`
|
||||
|
||||
checkInput
|
||||
checkFileExist ${SCRIPT_DIR}/update-code.sh
|
||||
createFolderIfNotExist ${SOURCE_DIR}
|
||||
|
||||
# 运行主方法
|
||||
main
|
||||
|
|
|
@ -5,28 +5,13 @@
|
|||
# Author: Zhang Peng
|
||||
###################################################################################
|
||||
|
||||
# 检查文件是否存在,不存在则退出脚本
|
||||
function checkFileExist() {
|
||||
if [ ! -f "$1" ]
|
||||
then
|
||||
echo "关键文件 $1 找不到,脚本执行结束"
|
||||
exit 0
|
||||
fi
|
||||
}
|
||||
|
||||
# 检查文件夹是否存在,不存在则创建
|
||||
function createFolderIfNotExist() {
|
||||
if [ ! -d "$1" ];then
|
||||
mkdir -p "$1"
|
||||
fi
|
||||
}
|
||||
|
||||
# 选择应用
|
||||
function chooseAppName() {
|
||||
cat << EOF
|
||||
请选择应用名(数字或关键字均可)。
|
||||
可选值如下:
|
||||
[0] all (所有应用)
|
||||
[1] APP1
|
||||
[1] js-app
|
||||
[2] APP2
|
||||
EOF
|
||||
|
||||
|
@ -37,18 +22,48 @@ do
|
|||
app=all
|
||||
break ;;
|
||||
1 )
|
||||
app=APP1
|
||||
app=js-app
|
||||
break ;;
|
||||
2 )
|
||||
app=APP2
|
||||
break ;;
|
||||
all | APP1 | APP2 )
|
||||
all | js-app | APP2 )
|
||||
break ;;
|
||||
* ) echo "无法识别 ${app}" ;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
# 选择操作
|
||||
function chooseOper() {
|
||||
cat << EOF
|
||||
请选择想要执行的操作(数字或关键字均可)。
|
||||
可选值如下:
|
||||
[1] start
|
||||
[2] restart
|
||||
[3] stop
|
||||
EOF
|
||||
|
||||
while read oper
|
||||
do
|
||||
case ${oper} in
|
||||
1 )
|
||||
oper=start
|
||||
break ;;
|
||||
2 )
|
||||
oper=restart
|
||||
break ;;
|
||||
3 )
|
||||
oper=stop
|
||||
break ;;
|
||||
start | restart | stop )
|
||||
break ;;
|
||||
* ) echo "无法识别 ${oper}" ;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
# 选择代码分支
|
||||
function chooseBranch() {
|
||||
cat << EOF
|
||||
请输入 git 分支。
|
||||
|
@ -64,6 +79,7 @@ else
|
|||
fi
|
||||
}
|
||||
|
||||
# 选择运行环境
|
||||
function chooseProfile() {
|
||||
cat << EOF
|
||||
请选择运行环境(数字或关键字均可)。
|
||||
|
@ -96,15 +112,14 @@ do
|
|||
done
|
||||
}
|
||||
|
||||
function inputParams() {
|
||||
chooseAppName
|
||||
chooseBranch
|
||||
chooseProfile
|
||||
# 确认选择
|
||||
function confirmChoice() {
|
||||
|
||||
cat << EOF
|
||||
===================================================
|
||||
请确认您的选择:Y/N
|
||||
app: ${app}
|
||||
oper: ${oper}
|
||||
branch: ${branch}
|
||||
profile: ${profile}
|
||||
===================================================
|
||||
|
@ -125,43 +140,51 @@ EOF
|
|||
done
|
||||
}
|
||||
|
||||
function printHeadInfo() {
|
||||
cat << EOF
|
||||
***********************************************************************************
|
||||
* 欢迎使用项目引导式发布脚本。
|
||||
* 输入任意键进入脚本操作。
|
||||
***********************************************************************************
|
||||
EOF
|
||||
}
|
||||
|
||||
function printFootInfo() {
|
||||
cat << EOF
|
||||
|
||||
|
||||
***********************************************************************************
|
||||
* 安装过程结束。
|
||||
* 输入任意键进入脚本操作。
|
||||
* 如果不想安装其他应用,输入 exit 回车或输入 <CTRL-C> 退出。
|
||||
***********************************************************************************
|
||||
EOF
|
||||
}
|
||||
|
||||
function main() {
|
||||
# 引导式发布应用
|
||||
function releaseApp() {
|
||||
# 输入执行参数
|
||||
app=""
|
||||
branch=""
|
||||
profile=""
|
||||
inputParams
|
||||
|
||||
chooseAppName
|
||||
chooseOper
|
||||
if [ "${oper}" == "stop" ]; then
|
||||
confirmChoice
|
||||
if [ "${app}" == "all" ]; then
|
||||
checkFileExist ${SCRIPT_DIR}/java-app-release.sh
|
||||
checkFileExist ${SCRIPT_DIR}/js-app-release.sh
|
||||
${SCRIPT_DIR}/io-alch-release.sh ${branch} ${profile}
|
||||
${SCRIPT_DIR}/ck-alch-release.sh ${branch} ${profile}
|
||||
${SCRIPT_DIR}/${app}-run.sh stop ${profile}
|
||||
else
|
||||
${SCRIPT_DIR}/${app}-run.sh stop ${profile}
|
||||
fi
|
||||
else
|
||||
chooseBranch
|
||||
chooseProfile
|
||||
confirmChoice
|
||||
if [ "${app}" == "all" ]; then
|
||||
${SCRIPT_DIR}/js-app-release.sh ${branch} ${profile}
|
||||
else
|
||||
checkFileExist ${SCRIPT_DIR}/${app}-release.sh
|
||||
${SCRIPT_DIR}/${app}-release.sh ${branch} ${profile}
|
||||
fi
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
# 脚本主方法
|
||||
function main() {
|
||||
|
||||
printHeadInfo
|
||||
while read sign
|
||||
do
|
||||
case ${sign} in
|
||||
exit)
|
||||
echo "主动退出脚本"
|
||||
exit 0 ;;
|
||||
* )
|
||||
releaseApp ;;
|
||||
esac
|
||||
|
||||
# 装载函数库
|
||||
printFootInfo
|
||||
done
|
||||
}
|
||||
|
||||
######################################## MAIN ########################################
|
||||
|
@ -171,18 +194,13 @@ export LANG="zh_CN.UTF-8"
|
|||
# 设置全局常量
|
||||
SCRIPT_DIR=$(cd "$(dirname "$0")"; pwd)
|
||||
SOURCE_DIR=/home/zp/source/
|
||||
# 如果源码存放目录不存在则创建
|
||||
|
||||
# 装载函数库
|
||||
. ${SCRIPT_DIR}/helper.sh
|
||||
|
||||
# 检查必要文件或文件夹是否存在
|
||||
checkFileExist ${SCRIPT_DIR}/helper.sh
|
||||
createFolderIfNotExist ${SOURCE_DIR}
|
||||
|
||||
printHeadInfo
|
||||
while read sign
|
||||
do
|
||||
case ${sign} in
|
||||
exit )
|
||||
exit 0 ;;
|
||||
* )
|
||||
main ;;
|
||||
esac
|
||||
|
||||
printFootInfo
|
||||
done
|
||||
# 运行主方法
|
||||
main
|
|
@ -44,7 +44,7 @@
|
|||
|
||||
<!-- logger begin -->
|
||||
<!-- 本项目的日志记录,分级打印 -->
|
||||
<logger name="cn.xyz" level="TRACE">
|
||||
<logger name="io.github.zp" level="TRACE">
|
||||
<appender-ref ref="ELK-TCP"/>
|
||||
<appender-ref ref="ALL"/>
|
||||
</logger>
|
||||
|
|
|
@ -8,4 +8,4 @@ git clone https://github.com/creationix/nvm.git ~/.nvm && cd ~/.nvm
|
|||
source ~/.nvm/nvm.sh
|
||||
|
||||
# 使用 nvm 安装 Node 指定版本
|
||||
nvm install 0.10.48
|
||||
nvm install 8.9.4
|
||||
|
|
Loading…
Reference in New Issue