deploy.sh 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #!/bin/bash
  2. npx vite build
  3. # 开发主机(开发环境服务器 有SSH权限至生产环境)
  4. DEV_HOST=root@dbo.fmode.cn
  5. # 生产主机(生产环境服务器)
  6. PROD_HOST=root@8.140.98.43
  7. # 部署路径
  8. DIR_SERVER=/opt/edu-textbook-server
  9. # 资源文件
  10. cp -rf config dist/server/
  11. cp package.json dist/server/
  12. sed -i '/@embedded/d' dist/server/package.json
  13. sed -i '/@embedded/d' dist/server/package.json
  14. cp config.js dist/server/
  15. cp keepalive.js dist/server/
  16. cp -rf cloud/tbook/template dist/server/
  17. cd dist
  18. tar zcvf server.tar.gz ./server
  19. cp server.tar.gz ../../docker/opt/
  20. cd ..
  21. # 压缩部署
  22. ssh $DEV_HOST "mkdir -p $DIR_SERVER"
  23. scp dist/server.tar.gz $DEV_HOST:$DIR_SERVER/
  24. ssh $DEV_HOST "scp -r $DIR_SERVER/server.tar.gz $PROD_HOST:/opt/"
  25. ssh $DEV_HOST "ssh $PROD_HOST \"cd /opt/ && tar zxvf server.tar.gz && cp -rf server/* edu-textbook-server/\"" # 仅安装prod
  26. ssh $DEV_HOST "ssh $PROD_HOST \"cd /opt/ && cp server.tar.gz /var/www/edu-textbook\"" # 仅安装prod
  27. # 部署过程
  28. # ssh $DEV_HOST "mkdir -p $DIR_SERVER"
  29. # scp dist/server/server.js $DEV_HOST:$DIR_SERVER/
  30. # scp ./package.json $DEV_HOST:$DIR_SERVER/
  31. # scp ./config.js $DEV_HOST:$DIR_SERVER/
  32. # ssh $DEV_HOST "scp -r $DIR_SERVER $PROD_HOST:/opt/"
  33. # 启动过程
  34. ssh $DEV_HOST "ssh $PROD_HOST \"cd $DIR_SERVER && ls -lah\"" # 仅安装prod
  35. ssh $DEV_HOST "ssh $PROD_HOST \"cd $DIR_SERVER && npm i --omit=dev --force\"" # 仅安装prod
  36. ssh $DEV_HOST "ssh $PROD_HOST \"cd $DIR_SERVER && pm2 stop server.js\""
  37. ssh $DEV_HOST "ssh $PROD_HOST \"cd $DIR_SERVER && pm2 start server.js\""