当前位置:   article > 正文

阿里云云效CI/CD配置

阿里云云效CI/CD配置

1.NODEJS项目流水线配置(vue举例)

nodejs构建配置

官方教程

注意:下图的distvue项目打包目录名称,根据实际名称配置 

  1. # input your command here
  2. cnpm cache clean --force
  3. cnpm install
  4. cnpm run build

主机部署配置

  1. rm -rf /home/vipcardmall/frontend/
  2. mkdir -p /home/vipcardmall/frontend
  3. #解压构建的dist压缩包到指定目录
  4. tar zxvf /home/flowapp/vip_card_mall_user_frontend_v2.tgz -C /home/vipcardmall/frontend
  5. #删除dist压缩包
  6. rm -rf /home/flowapp/vip_card_mall_user_frontend_v2.tgz

下图红框的是webhook触发地址,通过post/json触发,触发后会自动触发流水线,请求参数{},触发成功返回

  1. {
  2. "object": true,
  3. "successful": true
  4. }

2.springboot项目部署

deploy.sh

  1. #!/bin/bash
  2. #---------------------------配置开始----------------------------------
  3. # 修改APP_NAME为云效上的应用名
  4. APP_NAME=openapi-service-0.0.1-SNAPSHOT
  5. PROG_NAME=$0
  6. ACTION=$1
  7. APP_START_TIMEOUT_SECONDS=70 # 等待应用启动的时间(秒)
  8. APP_PORT=6677 # 应用端口
  9. BASE_URL=http://127.0.0.1:${APP_PORT}/openapi-service # 应用的基础URL
  10. HEALTH_CHECK_URL=${BASE_URL}/common/heartCheck # 应用健康检查URL
  11. APP_HOME=/home/backend/openapi # 从package.tgz中解压出来的jar包放到这个目录下
  12. JAR_NAME=${APP_HOME}/${APP_NAME}.jar # jar包的名字
  13. JAVA_OUT=${APP_HOME}/prod.log #应用的启动日志
  14. PACKAGE_PATH=/home/flowapp/mall-openapi.tgz #制品路径
  15. SHUTDOWN_URL=${BASE_URL}/common/actuator/shutdown #优雅关闭地址
  16. SHUTDOWN_TIMEOUT_SECONDS=70 #优雅停机超时时间(秒)
  17. SPRING_PROFILE="prod" # The Spring profile to activate
  18. #---------------------------配置结束----------------------------------
  19. # 创建出相关目录
  20. mkdir -p ${APP_HOME}
  21. usage() {
  22. echo "Usage: $PROG_NAME {start|stop|restart}"
  23. exit 2
  24. }
  25. health_check() {
  26. exptime=0
  27. echo "checking ${HEALTH_CHECK_URL}"
  28. while true
  29. do
  30. status_code=`/usr/bin/curl -L -o /dev/null --connect-timeout 5 -s -w %{http_code} ${HEALTH_CHECK_URL}`
  31. if [ "$?" != "0" ]; then
  32. echo -n -e "\rapplication not started"
  33. else
  34. echo "code is $status_code"
  35. if [ "$status_code" == "200" ];then
  36. break
  37. fi
  38. fi
  39. sleep 1
  40. ((exptime++))
  41. echo -e "\rWait app to pass health check: $exptime..."
  42. if [ $exptime -gt ${APP_START_TIMEOUT_SECONDS} ]; then
  43. echo 'app start failed'
  44. exit 1
  45. fi
  46. done
  47. echo "check ${HEALTH_CHECK_URL} success"
  48. }
  49. start_application() {
  50. echo "starting java process"
  51. nohup java -jar -Xmx512m -Xms256m -Dspring.profiles.active=${SPRING_PROFILE} -Dserver.port=${APP_PORT} ${JAR_NAME} >${JAVA_OUT} 2>&1 &
  52. echo "started java process"
  53. }
  54. stop_application() {
  55. # 查找Java进程ID
  56. checkjavapid=$(ps -ef | grep java | grep ${APP_NAME} | grep ${APP_PORT} | grep -v grep | awk '{print $2}')
  57. # 如果没有发现Java进程,则直接返回
  58. if [[ ! $checkjavapid ]]; then
  59. echo "No java process to stop (process not found)"
  60. return
  61. fi
  62. # 向Java进程发送SIGTERM请求
  63. echo "Sending SIGTERM to Java process with PID ${checkjavapid}."
  64. kill -15 ${checkjavapid}
  65. # 等待Java进程停止
  66. for ((i=0; i<$SHUTDOWN_TIMEOUT_SECONDS; i++)); do
  67. # 使用curl检查心跳接口
  68. http_status=$(curl -o /dev/null -s -w "%{http_code}\n" ${HEALTH_CHECK_URL})
  69. # 如果状态码不是200,认为进程已经停止
  70. if [ "$http_status" != "200" ]; then
  71. echo "Java process stopped successfully."
  72. return
  73. fi
  74. sleep 1
  75. echo "Waiting for Java process to stop..."
  76. done
  77. # 如果Java进程在等待时间后仍然存在,则发送SIGKILL
  78. echo "Java process did not stop after $SHUTDOWN_TIMEOUT_SECONDS seconds, sending SIGKILL"
  79. kill -9 $checkjavapid
  80. echo "Java process killed forcefully"
  81. }
  82. start() {
  83. start_application
  84. health_check
  85. }
  86. stop() {
  87. stop_application
  88. }
  89. deploy() {
  90. # 停止应用程序
  91. stop
  92. # 解压PACKAGE_PATH文件到APP_HOME目录
  93. echo "Unpacking $PACKAGE_PATH to $APP_HOME"
  94. if tar zxvf $PACKAGE_PATH -C $APP_HOME; then
  95. echo "Unpack finished successfully."
  96. # 删除原始压缩包
  97. echo "Removing the package $PACKAGE_PATH"
  98. rm -f $PACKAGE_PATH
  99. if [ $? -eq 0 ]; then
  100. echo "Package removed successfully."
  101. else
  102. echo "Failed to remove the package."
  103. fi
  104. else
  105. echo "Error occurred during unpacking. Exiting."
  106. exit 1
  107. fi
  108. # 启动应用程序
  109. start
  110. }
  111. case "$ACTION" in
  112. start)
  113. start
  114. ;;
  115. stop)
  116. stop
  117. ;;
  118. restart)
  119. stop
  120. start
  121. ;;
  122. deploy)
  123. deploy
  124. ;;
  125. *)
  126. usage
  127. ;;
  128. esac

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/2023面试高手/article/detail/436835
推荐阅读
相关标签
  

闽ICP备14008679号