perf(ci): allow two concurrent non-production deploys
This commit is contained in:
+2
-2
@@ -173,10 +173,10 @@ pipeline {
|
|||||||
agent none
|
agent none
|
||||||
steps {
|
steps {
|
||||||
script {
|
script {
|
||||||
String deployLock = "firstleg-${params.ENVIRONMENT}-deploy"
|
String deploySlotLabel = "firstleg-${params.ENVIRONMENT}-deploy-slot"
|
||||||
String credentialId = "firstleg-${params.ENVIRONMENT}-env"
|
String credentialId = "firstleg-${params.ENVIRONMENT}-env"
|
||||||
String targetLabel = params.ENVIRONMENT == 'development' ? 'java-dev' : 'java-test'
|
String targetLabel = params.ENVIRONMENT == 'development' ? 'java-dev' : 'java-test'
|
||||||
lock(resource: deployLock, inversePrecedence: true) {
|
lock(label: deploySlotLabel, quantity: 1, inversePrecedence: true) {
|
||||||
node(targetLabel) {
|
node(targetLabel) {
|
||||||
deleteDir()
|
deleteDir()
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -241,7 +241,7 @@ deploy_local() {
|
|||||||
docker pull "$IMAGE"
|
docker pull "$IMAGE"
|
||||||
export DEPLOY_ENV IMAGE_REPOSITORY IMAGE_TAG
|
export DEPLOY_ENV IMAGE_REPOSITORY IMAGE_TAG
|
||||||
new_started=true
|
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
|
echo "新镜像启动命令失败: $IMAGE" >&2
|
||||||
new_started=false
|
new_started=false
|
||||||
fi
|
fi
|
||||||
@@ -281,7 +281,7 @@ deploy_local() {
|
|||||||
fi
|
fi
|
||||||
IMAGE_TAG="$previous_tag"
|
IMAGE_TAG="$previous_tag"
|
||||||
export IMAGE_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
|
echo "自动回滚失败,旧镜像启动命令失败: $previous_image" >&2
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
@@ -436,7 +436,7 @@ else
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
new_started=true
|
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
|
echo "新镜像启动命令失败: $new_image" >&2
|
||||||
new_started=false
|
new_started=false
|
||||||
fi
|
fi
|
||||||
@@ -472,7 +472,7 @@ if ! docker pull "$previous_image"; then
|
|||||||
fi
|
fi
|
||||||
IMAGE_TAG="$previous_tag"
|
IMAGE_TAG="$previous_tag"
|
||||||
export IMAGE_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
|
echo "自动回滚失败,旧镜像启动命令失败: $previous_image" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -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, /\['development', 'test'\]\.contains\(params\.ENVIRONMENT\)/)
|
||||||
assert.match(pipeline, /params\.ENVIRONMENT == 'development' \? 'java-dev' : 'java-test'/)
|
assert.match(pipeline, /params\.ENVIRONMENT == 'development' \? 'java-dev' : 'java-test'/)
|
||||||
assert.match(pipeline, /'TARGET_IS_LOCAL=true'/)
|
assert.match(pipeline, /'TARGET_IS_LOCAL=true'/)
|
||||||
assert.match(pipeline, /String deployLock = "firstleg-\$\{params\.ENVIRONMENT\}-deploy"/)
|
assert.match(pipeline, /String deploySlotLabel = "firstleg-\$\{params\.ENVIRONMENT\}-deploy-slot"/)
|
||||||
assert.match(pipeline, /lock\(resource: deployLock, inversePrecedence: true\)/)
|
assert.match(pipeline, /lock\(label: deploySlotLabel, quantity: 1, inversePrecedence: true\)/)
|
||||||
assert.match(pipeline, /deploy-built-service\.sh/)
|
assert.match(pipeline, /deploy-built-service\.sh/)
|
||||||
assert.doesNotMatch(pipeline, /dev_deploy|test_deploy|TARGET_SSH_KEY/)
|
assert.doesNotMatch(pipeline, /dev_deploy|test_deploy|TARGET_SSH_KEY/)
|
||||||
assert.match(directDeployScript, /docker pull "\$IMAGE"/)
|
assert.match(directDeployScript, /docker pull "\$IMAGE"/)
|
||||||
assert.match(directDeployScript, /run_ssh docker pull "\$IMAGE"/)
|
assert.match(directDeployScript, /run_ssh docker pull "\$IMAGE"/)
|
||||||
assert.doesNotMatch(directDeployScript, /docker save "\$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/)
|
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('部署开发或测试环境')"),
|
||||||
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)')
|
const nodeIndex = directDeployStage.indexOf('node(targetLabel)')
|
||||||
|
|
||||||
assert.match(directDeployStage, /agent none/)
|
assert.match(directDeployStage, /agent none/)
|
||||||
assert.match(directDeployStage, /String targetLabel = params\.ENVIRONMENT == 'development' \? 'java-dev' : 'java-test'/)
|
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(nodeIndex >= 0, 'target node allocation must exist')
|
||||||
assert.ok(lockIndex < nodeIndex, 'deployment lock must be acquired before target node allocation')
|
assert.ok(lockIndex < nodeIndex, 'deployment lock must be acquired before target node allocation')
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user