From 8d28f80761d4209f145b9fae91a5d032d440a46f Mon Sep 17 00:00:00 2001 From: XuqmGroup Date: Sat, 25 Apr 2026 06:35:58 +0800 Subject: [PATCH] =?UTF-8?q?ci:=20simplify=20pipeline=20=E2=80=94=20one=20c?= =?UTF-8?q?ombined=20web=20image,=20docker=20build=20handles=20yarn=20inte?= =?UTF-8?q?rnally?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Remove APP parameter split; existing Dockerfile already builds tenant+ops+docs into a single Nginx image. Server-side docker login pre-configured. Co-Authored-By: Claude Sonnet 4.6 --- Jenkinsfile | 55 +++++++++++++---------------------------------------- 1 file changed, 13 insertions(+), 42 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index c69930e..996ab6d 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,8 +1,7 @@ pipeline { - agent none + agent any parameters { - choice(name: 'APP', choices: ['tenant-platform', 'ops-platform'], description: '要构建的 Web 应用') string(name: 'IMAGE_TAG', defaultValue: 'latest', description: '镜像 Tag') booleanParam(name: 'DEPLOY', defaultValue: true, description: '构建后是否自动部署') } @@ -14,48 +13,24 @@ pipeline { PROD_HOST = '106.54.23.149' PROD_USER = 'ubuntu' COMPOSE_FILE = '/opt/xuqm/deploy/compose.production.yaml' + IMAGE_NAME = 'web' } stages { stage('Checkout') { - agent any - steps { - checkout scm - stash name: 'source', includes: '**/*' - } - } - - stage('Install & Build') { - agent { - docker { - image 'node:22-alpine' - args '-v yarn-cache:/root/.yarn' - } - } - steps { - unstash 'source' - dir("${params.APP}") { - sh ''' - yarn install --frozen-lockfile - yarn build - ''' - } - stash name: 'dist', includes: "${params.APP}/dist/**,${params.APP}/Dockerfile" - } + steps { checkout scm } } stage('Docker Build & Push') { - agent any steps { - unstash 'dist' withCredentials([string(credentialsId: 'ACR_PASSWORD', variable: 'ACR_PASS')]) { script { - def imageName = "${ACR_REGISTRY}/${ACR_NAMESPACE}/web-${params.APP}:${params.IMAGE_TAG}" + def fullImage = "${ACR_REGISTRY}/${ACR_NAMESPACE}/${IMAGE_NAME}:${params.IMAGE_TAG}" sh """ docker login ${ACR_REGISTRY} -u ${ACR_USERNAME} -p \${ACR_PASS} - docker build -f ${params.APP}/Dockerfile -t ${imageName} . - docker push ${imageName} - docker rmi ${imageName} + docker build -t ${fullImage} . + docker push ${fullImage} + docker rmi ${fullImage} """ } } @@ -63,20 +38,16 @@ pipeline { } stage('Deploy to Production') { - agent any when { expression { return params.DEPLOY } } steps { withCredentials([sshUserPrivateKey(credentialsId: 'PROD_SSH_KEY', keyFileVariable: 'SSH_KEY')]) { script { - def svcName = params.APP == 'tenant-platform' ? 'web' : 'ops-web' - def imageName = "${ACR_REGISTRY}/${ACR_NAMESPACE}/web-${params.APP}:${params.IMAGE_TAG}" + def fullImage = "${ACR_REGISTRY}/${ACR_NAMESPACE}/${IMAGE_NAME}:${params.IMAGE_TAG}" sh """ - ssh -i \${SSH_KEY} -o StrictHostKeyChecking=no ${PROD_USER}@${PROD_HOST} " - docker pull ${imageName} && - cd /opt/xuqm/deploy && - docker compose -f ${COMPOSE_FILE} up -d --no-deps ${svcName} && - docker image prune -f - " + ssh -i \${SSH_KEY} -o StrictHostKeyChecking=no ${PROD_USER}@${PROD_HOST} \ + "docker pull ${fullImage} && \ + docker compose -f ${COMPOSE_FILE} up -d --no-deps web && \ + docker image prune -f" """ } } @@ -85,7 +56,7 @@ pipeline { } post { - success { echo "✅ ${params.APP}:${params.IMAGE_TAG} 构建部署成功" } + success { echo "✅ web:${params.IMAGE_TAG} 构建部署成功" } failure { echo "❌ 构建失败,请检查日志" } } }