.gitlab-ci.yml 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. stages:
  2. - compile
  3. - build
  4. - deploy
  5. variables:
  6. PROJECT_NAME: ${CI_PROJECT_NAME}
  7. K8S_FILE: "deploy.yml"
  8. PROJECT_IMAGE: harbor.cloud.prolog.org/test/${CI_PROJECT_NAME}
  9. before_script:
  10. - PROJECT_IMAGE_TAG=${PROJECT_IMAGE}:${CI_COMMIT_SHA:0:5}
  11. #开始构建jar包
  12. compile:
  13. image: harbor.cloud.prolog.org/base-solution/maven:3-openjdk-8
  14. stage: compile
  15. only:
  16. refs:
  17. - dev #对应分支代码分支
  18. script:
  19. - mvn -q clean package -Dmaven.test.skip=true
  20. artifacts:
  21. expire_in: 1 day #工作目录保存时间
  22. paths:
  23. - ./upcloud-base-wh-operate-service/target/*.jar #获取构建的jar包,此路径随对应项目修改
  24. # when: manual #手动执行,注释后会自动在每次提交变更后执行
  25. #开始构建镜像并上传至harbor
  26. build:
  27. stage: build
  28. image: harbor.cloud.prolog.org/base-solution/drone-kaniko:bate
  29. variables:
  30. PLUGIN_REPO: "test/${CI_PROJECT_NAME}" #此处为上传harbor时候的容器名称
  31. PLUGIN_REGISTRY: "harbor.cloud.prolog.org"
  32. PLUGIN_USERNAME: "$DOCKER_USERNAME" #项目设置里面cicd 配置变量
  33. PLUGIN_PASSWORD: "$DOCKER_PASSWORD" #项目设置里面cicd 配置变量
  34. PLUGIN_SKIP_TLS_VERIFY: "true"
  35. PLUGIN_SKIP_TLS_VERIFY_PULL: "true"
  36. PLUGIN_CACHE: "false"
  37. PLUGIN_TAGS: "${CI_COMMIT_SHA:0:5}"
  38. script:
  39. - PLUGIN_TAGS="${CI_COMMIT_SHA:0:5}"
  40. - /kaniko/plugin.sh
  41. only:
  42. refs:
  43. - dev #对应分支代码分支
  44. when: manual #手动执行,注释后会自动在每次提交变更后执行
  45. #发布流程
  46. k8s-deploy:
  47. stage: deploy
  48. variables:
  49. PROJECT_PORT: 8080 #配置文件里面的端口需要和deployment容器端口一致 次端口只能在k8s内部访问
  50. PROJECT_NODEPORT: 30821 #nodeport 为该服务在k8s集群外访问端口
  51. PROJECT_NAME: ${CI_PROJECT_NAME} #启用变量配。
  52. PROJECT_NAMESPACE: test # k8s集群内部的命名空间namespaces
  53. PROJECT_ACTIVE: k8s # 项目对应的环境配置文件
  54. image: harbor.cloud.prolog.org/base-solution/kubectl:v1
  55. script:
  56. - kubectl get nodes
  57. - kubectl version
  58. - sed -i "s#{PROJECT_NAME}#$PROJECT_NAME#g;
  59. s#{PROJECT_NODEPORT}#$PROJECT_NODEPORT#g;
  60. s#{PROJECT_PORT}#$PROJECT_PORT#g;
  61. s#{PROJECT_NAMESPACE}#$PROJECT_NAMESPACE#g;
  62. s#{PROJECT_IMAGE}#$PROJECT_IMAGE_TAG#g;
  63. s#{PROJECT_ACTIVE}#$PROJECT_ACTIVE#g" ./deploy.yml
  64. - cat ./deploy.yml
  65. - kubectl delete -f ./deploy.yml
  66. - kubectl apply -f ./deploy.yml
  67. only:
  68. refs:
  69. - dev #对应分支代码分支
  70. when: manual #手动执行,注释后会自动在每次提交变更后执行