You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

build_and_deploy.sh.bak 1.6 kB

1 year ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #!/bin/bash
  2. #记录开始时间
  3. startTime=$(date +%s)
  4. # 登录到目标环境
  5. baseDir="/home/somuns/ci4s"
  6. cd ${baseDir}
  7. #build
  8. # 默认参数
  9. branch="master"
  10. service="manage-front"
  11. env="dev"
  12. #
  13. show_help() {
  14. echo "Usage: $0 [-b branch] [-s service] [-e environment]"
  15. echo
  16. echo "Options:"
  17. echo " -b Branch to deploy, default: master"
  18. echo " -s Service to deploy (manage-front, manage, front, all, default: manage-front)"
  19. echo " -e Environment (e.g., dev, test, default: dev)"
  20. echo " -h Show this help message"
  21. }
  22. # 解析命令行选项
  23. while getopts "b:s:e:h" opt; do
  24. case $opt in
  25. b) branch=$OPTARG ;;
  26. s) service=$OPTARG ;;
  27. e) env=$OPTARG ;;
  28. h) show_help; exit 0 ;;
  29. \?) echo "Invalid option -$OPTARG" >&2; show_help; exit 1 ;;
  30. esac
  31. done
  32. valid_services=("manage-front" "manage" "front" "all")
  33. if [[ ! " ${valid_services[@]} " =~ " $service " ]]; then
  34. echo "Invalid service name: $service" >&2
  35. echo "Valid services are: ${valid_services[*]}"
  36. exit 1
  37. fi
  38. valid_envs=("dev" "test")
  39. if [[ ! " ${valid_envs[@]} " =~ " $env " ]]; then
  40. echo "Invalid environment: $env" >&2
  41. echo "Valid environments are: ${valid_envs[*]}"
  42. exit 1
  43. fi
  44. echo "start build"
  45. sh ${baseDir}/k8s/build.sh -b ${branch} -s ${service}
  46. if [ $? -ne 0 ]; then
  47. echo "Build failed"
  48. exit 1
  49. fi
  50. echo "build success"
  51. # 部署
  52. echo "start deploy"
  53. sh ${baseDir}/k8s/deploy.sh -s ${service} -e ${env}
  54. if [ $? -ne 0 ]; then
  55. echo "Deploy failed"
  56. exit 1
  57. fi
  58. echo "deploy success"
  59. # 记录结束时间
  60. endTime=$(date +%s)
  61. # 计算运行时间
  62. duration=$(( $endTime - $startTime ))
  63. echo "编译发布总耗时: $duration 秒"