当前位置:   article > 正文

阿里云云效CI/CD配置_云效 ci

云效 ci

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=11112 # 应用端口
  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/adminsystem/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 gracefully."
  72. # 如果找到PID,则使用kill -9命令强制结束进程
  73. if [ ! -z "$checkjavapid" ]; then
  74. kill -9 $checkjavapid
  75. echo "Killed process on port $APP_PORT."
  76. fi
  77. return
  78. fi
  79. sleep 1
  80. echo "Waiting for Java process to stop..."
  81. done
  82. # 如果Java进程在等待时间后仍然存在,则发送SIGKILL
  83. echo "Java process did not stop after $SHUTDOWN_TIMEOUT_SECONDS seconds, sending SIGKILL"
  84. if [ ! -z "$checkjavapid" ]; then
  85. kill -9 $checkjavapid
  86. echo "Killed process on port $APP_PORT."
  87. fi
  88. }
  89. start() {
  90. start_application
  91. health_check
  92. }
  93. stop() {
  94. stop_application
  95. }
  96. deploy() {
  97. # 停止应用程序
  98. stop
  99. # 解压PACKAGE_PATH文件到APP_HOME目录
  100. echo "Unpacking $PACKAGE_PATH to $APP_HOME"
  101. if tar zxvf $PACKAGE_PATH -C $APP_HOME; then
  102. echo "Unpack finished successfully."
  103. # 删除原始压缩包
  104. echo "Removing the package $PACKAGE_PATH"
  105. rm -f $PACKAGE_PATH
  106. if [ $? -eq 0 ]; then
  107. echo "Package removed successfully."
  108. else
  109. echo "Failed to remove the package."
  110. fi
  111. else
  112. echo "Error occurred during unpacking. Exiting."
  113. exit 1
  114. fi
  115. # 启动应用程序
  116. start
  117. }
  118. case "$ACTION" in
  119. start)
  120. start
  121. ;;
  122. stop)
  123. stop
  124. ;;
  125. restart)
  126. stop
  127. start
  128. ;;
  129. deploy)
  130. deploy
  131. ;;
  132. *)
  133. usage
  134. ;;
  135. esac

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

闽ICP备14008679号