From 4245cf60a1cb10ad6fbdd828056b1692d1657567 Mon Sep 17 00:00:00 2001 From: yovinchen Date: Thu, 25 Jan 2024 14:18:51 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=20pipeline=20=E6=B5=81?= =?UTF-8?q?=E6=B0=B4=E7=BA=BF=E6=96=87=E4=BB=B6=20K8s=E9=9B=86=E7=BE=A4?= =?UTF-8?q?=E9=83=A8=E7=BD=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 10 ++++ xlcs-parent/service-gateway/Jenkinsfile | 58 +++++++++++++++++++++ xlcs-parent/service/service-acl/Jenkinsfile | 39 ++++++++++++++ 3 files changed, 107 insertions(+) create mode 100644 xlcs-parent/service-gateway/Jenkinsfile create mode 100644 xlcs-parent/service/service-acl/Jenkinsfile diff --git a/README.md b/README.md index b17e1fe..289e5e7 100644 --- a/README.md +++ b/README.md @@ -229,3 +229,13 @@ services: retries: 3 start_period: 60s #⾸次检测延迟时间 ``` + +## K8s 集群部署 + +使用 jenkins 进行打包 + +构建参数 + +![image-20240125141417779](https://lsky.hhdxw.top/imghub/2024/01/image-202401251706163258.png) + +具体 pipeline 参考各模块下文件 diff --git a/xlcs-parent/service-gateway/Jenkinsfile b/xlcs-parent/service-gateway/Jenkinsfile new file mode 100644 index 0000000..3ddaf7a --- /dev/null +++ b/xlcs-parent/service-gateway/Jenkinsfile @@ -0,0 +1,58 @@ +pipeline { + environment { + DOCKER_REGISTRY = "10.211.55.2:8083" + DOCKER_IMAGE_NAME = "service-gateway" + DOCKER_IMAGE_TAG = "${env.DATETIME}" + DOCKER_LOGIN_USERNAME = "admin" + DOCKER_LOGIN_PASSWORD = "adminadmin" + } + agent { + kubernetes { + inheritFrom 'maven' + containerTemplate { + name 'maven' + image 'maven:3.8.4-jdk-8' + } + + } + + } + stages { + stage('拉取代码') { + steps { + checkout([$class: 'GitSCM', branches: [[name: 'devops']], + extensions: [[$class: 'CloneOption', depth: 1, shallow: true]], userRemoteConfigs: [[url: 'http://gitea.hhdxw.top:3000/yovinchen/xlcs.git']] + ]) + } + } + + stage('编译jar包') { + agent none + steps { + container('maven') { + sh 'mvn -f xlcs-parent/pom.xml -B clean package -Dmaven.test.skip=true -Dautoconfig.skip' + } + + } + } + + stage('保存制品') { + steps { + archiveArtifacts(artifacts: 'xlcs-parent/service-gateway/target/*.jar', followSymlinks: false) + } + } + + stage('构建Docker镜像') { + steps { + sh "docker build -t ${DOCKER_REGISTRY}/${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_TAG} xlcs-parent/service-gateway" + } + } + + stage('登录仓库并推送镜像') { + steps { + sh "docker login -u ${DOCKER_LOGIN_USERNAME} -p ${DOCKER_LOGIN_PASSWORD} ${DOCKER_REGISTRY}" + sh "docker push ${DOCKER_REGISTRY}/${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_TAG}" + } + } + } +} diff --git a/xlcs-parent/service/service-acl/Jenkinsfile b/xlcs-parent/service/service-acl/Jenkinsfile new file mode 100644 index 0000000..e207ea4 --- /dev/null +++ b/xlcs-parent/service/service-acl/Jenkinsfile @@ -0,0 +1,39 @@ +pipeline { + agent { + kubernetes { + inheritFrom 'maven' + containerTemplate { + name 'maven' + image 'maven:3.8.4-jdk-8' + } + + } + + } + stages { + stage('拉取代码') { + steps { + checkout([$class: 'GitSCM', branches: [[name: 'devops']], + extensions: [[$class: 'CloneOption', depth: 1, shallow: true]], userRemoteConfigs: [[url: 'http://gitea.hhdxw.top:3000/yovinchen/xlcs.git']] + ]) + } + } + + stage('编译jar包') { + agent none + steps { + container('maven') { + sh 'mvn -f xlcs-parent/pom.xml -B clean package -Dmaven.test.skip=true -Dautoconfig.skip' + } + + } + } + + stage('保存制品') { + steps { + archiveArtifacts(artifacts: 'xlcs-parent/service/service-acl/target/service-acl.jar', followSymlinks: false) + } + } + + } +}