From fe4eb0b593fefe2daca7bf1163da0f321f451655 Mon Sep 17 00:00:00 2001 From: ouyangxq <775153912@qq.com> Date: Mon, 24 Aug 2026 11:17:17 +0800 Subject: [PATCH] perf(ci): allow two concurrent non-production deploys --- Jenkinsfile.service | 4 ++-- deploy/scripts/deploy-built-service.sh | 8 ++++---- scripts/test-environment-pipeline-contract.test.mjs | 10 ++++++---- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/Jenkinsfile.service b/Jenkinsfile.service index 19dac6adc..379caf60c 100644 --- a/Jenkinsfile.service +++ b/Jenkinsfile.service @@ -173,10 +173,10 @@ pipeline { agent none steps { script { - String deployLock = "firstleg-${params.ENVIRONMENT}-deploy" + String deploySlotLabel = "firstleg-${params.ENVIRONMENT}-deploy-slot" String credentialId = "firstleg-${params.ENVIRONMENT}-env" String targetLabel = params.ENVIRONMENT == 'development' ? 'java-dev' : 'java-test' - lock(resource: deployLock, inversePrecedence: true) { + lock(label: deploySlotLabel, quantity: 1, inversePrecedence: true) { node(targetLabel) { deleteDir() try { diff --git a/deploy/scripts/deploy-built-service.sh b/deploy/scripts/deploy-built-service.sh index ab2c9c07a..1479c8193 100644 --- a/deploy/scripts/deploy-built-service.sh +++ b/deploy/scripts/deploy-built-service.sh @@ -241,7 +241,7 @@ deploy_local() { docker pull "$IMAGE" export DEPLOY_ENV IMAGE_REPOSITORY IMAGE_TAG new_started=true - if ! local_compose up -d --remove-orphans --pull never "$SERVICE"; then + if ! local_compose up -d --no-deps --pull never "$SERVICE"; then echo "新镜像启动命令失败: $IMAGE" >&2 new_started=false fi @@ -281,7 +281,7 @@ deploy_local() { fi IMAGE_TAG="$previous_tag" export IMAGE_TAG - if ! local_compose up -d --remove-orphans --pull never "$SERVICE"; then + if ! local_compose up -d --no-deps --pull never "$SERVICE"; then echo "自动回滚失败,旧镜像启动命令失败: $previous_image" >&2 return 1 fi @@ -436,7 +436,7 @@ else fi new_started=true -if ! compose up -d --remove-orphans --pull never "$service"; then +if ! compose up -d --no-deps --pull never "$service"; then echo "新镜像启动命令失败: $new_image" >&2 new_started=false fi @@ -472,7 +472,7 @@ if ! docker pull "$previous_image"; then fi IMAGE_TAG="$previous_tag" export IMAGE_TAG -if ! compose up -d --remove-orphans --pull never "$service"; then +if ! compose up -d --no-deps --pull never "$service"; then echo "自动回滚失败,旧镜像启动命令失败: $previous_image" >&2 exit 1 fi diff --git a/scripts/test-environment-pipeline-contract.test.mjs b/scripts/test-environment-pipeline-contract.test.mjs index 0b2f25c21..85f55937c 100644 --- a/scripts/test-environment-pipeline-contract.test.mjs +++ b/scripts/test-environment-pipeline-contract.test.mjs @@ -39,13 +39,15 @@ test('Java builds use the shared builder pool and serialize incremental target d assert.match(pipeline, /\['development', 'test'\]\.contains\(params\.ENVIRONMENT\)/) assert.match(pipeline, /params\.ENVIRONMENT == 'development' \? 'java-dev' : 'java-test'/) assert.match(pipeline, /'TARGET_IS_LOCAL=true'/) - assert.match(pipeline, /String deployLock = "firstleg-\$\{params\.ENVIRONMENT\}-deploy"/) - assert.match(pipeline, /lock\(resource: deployLock, inversePrecedence: true\)/) + assert.match(pipeline, /String deploySlotLabel = "firstleg-\$\{params\.ENVIRONMENT\}-deploy-slot"/) + assert.match(pipeline, /lock\(label: deploySlotLabel, quantity: 1, inversePrecedence: true\)/) assert.match(pipeline, /deploy-built-service\.sh/) assert.doesNotMatch(pipeline, /dev_deploy|test_deploy|TARGET_SSH_KEY/) assert.match(directDeployScript, /docker pull "\$IMAGE"/) assert.match(directDeployScript, /run_ssh docker pull "\$IMAGE"/) assert.doesNotMatch(directDeployScript, /docker save "\$IMAGE"/) + assert.match(directDeployScript, /up -d --no-deps --pull never/) + assert.doesNotMatch(directDeployScript, /--remove-orphans/) assert.match(directDeployScript, /--pull never/) }) @@ -54,12 +56,12 @@ test('development and test deployment locks are acquired before target executors pipeline.indexOf("stage('部署开发或测试环境')"), pipeline.indexOf("stage('部署单个服务')") ) - const lockIndex = directDeployStage.indexOf('lock(resource: deployLock') + const lockIndex = directDeployStage.indexOf('lock(label: deploySlotLabel') const nodeIndex = directDeployStage.indexOf('node(targetLabel)') assert.match(directDeployStage, /agent none/) assert.match(directDeployStage, /String targetLabel = params\.ENVIRONMENT == 'development' \? 'java-dev' : 'java-test'/) - assert.ok(lockIndex >= 0, 'deployment lock must exist') + assert.ok(lockIndex >= 0, 'deployment slot lock must exist') assert.ok(nodeIndex >= 0, 'target node allocation must exist') assert.ok(lockIndex < nodeIndex, 'deployment lock must be acquired before target node allocation') })