123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- #!/bin/bash
- #
- # 部署脚本
- #
- set -e
- #
- APP_NAME=admin
- START_TIME=$(date +%s)
- DATE=$(date +%m/%d/%y)
- TIME=$(date +%k:%M:%S)
- TARGET_VERSION=$(date +%Y%m%d%H%M)
- # 目录配置
- DIST_NAME="dist"
- BUILD_NAME=build:prod
- WORK_DIR=/d/work-space/superdesk-app-ui-admin
- REMOTE_DIR=/data/admin
- # SSH配置
- REMOTE_USER=root
- REMOTE_IP=175.178.185.146
- PRIVATE_SSH_KEY=/d/work-space/ssh-key/id_rsa_my_tencent_146
- # workspace
- cd $WORK_DIR
- # build
- echo -e "\033[34m[INFO]\033[0m Building $APP_NAME ..."
- npm run $BUILD_NAME
- # upload
- echo -e "\033[34m[INFO]\033[0m Uploading $APP_NAME to $REMOTE_IP ..."
- tar -cf "$DIST_NAME.zip" $DIST_NAME
- scp -i $PRIVATE_SSH_KEY "$DIST_NAME.zip" "$REMOTE_USER@$REMOTE_IP:$REMOTE_DIR"
- rm "$DIST_NAME.zip"
- # publish
- echo -e "\033[34m[INFO]\033[0m Publishing $APP_NAME to $REMOTE_IP ..."
- ssh -i $PRIVATE_SSH_KEY "$REMOTE_USER@$REMOTE_IP" /bin/bash <<EOF
- cd $REMOTE_DIR
- tar -xf "$DIST_NAME.zip" && cp -r $DIST_NAME/* ./
- mkdir -p "archive"
- mv $DIST_NAME $TARGET_VERSION && mv $TARGET_VERSION "archive"
- ls -l index.html
- # rm "$DIST_NAME.zip"
- exit
- EOF
- END_TIME=$(date +%s)
- EXECUTION_TIME=$((END_TIME - START_TIME))
- echo "脚本执行时间:$EXECUTION_TIME 秒".
- echo -e "\033[32m[DONE]\033[0m Deployed complete."
|