test.sh 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #!/usr/bin/env bash
  2. # 发布测试服务到测试机器
  3. # 机器: 192.168.60.201
  4. # 账号: gaoyagang 互信已添加
  5. user="gt"
  6. target="47.96.12.136"
  7. # 编译
  8. build () {
  9. echo ${1}
  10. echo "build for ${1}"
  11. rm -f ${1}
  12. if [ "${1}" == "datacenter" ]; then
  13. GOOS=linux GOARCH=amd64 go build -o ${1} app/cmd/api/${1}.go
  14. else
  15. GOOS=linux GOARCH=amd64 go build -o ${1} app/cmd/${1}/${1}.go
  16. fi
  17. # shellcheck disable=SC2181
  18. if [ "$?" != "0" ]; then
  19. exit $?
  20. fi
  21. }
  22. # 上传
  23. upload () {
  24. echo "start upload ${1}..."
  25. rsync -av ./${1} ${user}@${target}:/home/${user}/${1}
  26. if [ "$?" != "0" ]; then
  27. exit $?
  28. fi
  29. echo "start upload ${1}.yaml"
  30. rsync -av ./app/cmd/${1}/etc/${1}.yaml ${user}@${target}:/home/${user}/etc/${1}.yaml
  31. echo "remove ${1}"
  32. rm -f ./${1}
  33. }
  34. # 清理中间资源
  35. clear () {
  36. rm -rf ${1}
  37. }
  38. # 重启服务
  39. restart () {
  40. echo "restart ${1} and wait 2 seconds..."
  41. sleep 2
  42. ssh ${user}@${target} sudo /usr/local/bin/supervisorctl restart ${1}
  43. }
  44. deploy () {
  45. build $1;
  46. upload $1;
  47. restart $1;
  48. }
  49. deploy $1