deploy.sh 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/bin/bash
  2. #
  3. # 部署脚本
  4. #
  5. set -e
  6. #
  7. APP_NAME=admin
  8. START_TIME=$(date +%s)
  9. DATE=$(date +%m/%d/%y)
  10. TIME=$(date +%k:%M:%S)
  11. TARGET_VERSION=$(date +%Y%m%d%H%M)
  12. # 目录配置
  13. DIST_NAME="dist"
  14. BUILD_NAME=build:prod
  15. WORK_DIR=/d/work-space/superdesk-app-ui-admin
  16. REMOTE_DIR=/data/admin
  17. # SSH配置
  18. REMOTE_USER=root
  19. REMOTE_IP=175.178.185.146
  20. PRIVATE_SSH_KEY=/d/work-space/ssh-key/id_rsa_my_tencent_146
  21. # workspace
  22. cd $WORK_DIR
  23. # build
  24. echo -e "\033[34m[INFO]\033[0m Building $APP_NAME ..."
  25. npm run $BUILD_NAME
  26. # upload
  27. echo -e "\033[34m[INFO]\033[0m Uploading $APP_NAME to $REMOTE_IP ..."
  28. tar -cf "$DIST_NAME.zip" $DIST_NAME
  29. scp -i $PRIVATE_SSH_KEY "$DIST_NAME.zip" "$REMOTE_USER@$REMOTE_IP:$REMOTE_DIR"
  30. rm "$DIST_NAME.zip"
  31. # publish
  32. echo -e "\033[34m[INFO]\033[0m Publishing $APP_NAME to $REMOTE_IP ..."
  33. ssh -i $PRIVATE_SSH_KEY "$REMOTE_USER@$REMOTE_IP" /bin/bash <<EOF
  34. cd $REMOTE_DIR
  35. tar -xf "$DIST_NAME.zip" && cp -r $DIST_NAME/* ./
  36. mkdir -p "archive"
  37. mv $DIST_NAME $TARGET_VERSION && mv $TARGET_VERSION "archive"
  38. ls -l index.html
  39. # rm "$DIST_NAME.zip"
  40. exit
  41. EOF
  42. END_TIME=$(date +%s)
  43. EXECUTION_TIME=$((END_TIME - START_TIME))
  44. echo "脚本执行时间:$EXECUTION_TIME 秒".
  45. echo -e "\033[32m[DONE]\033[0m Deployed complete."