This commit is contained in:
2026-09-29 18:47:37 +08:00
parent 2c60a29e0f
commit c2927ab9a6
291 changed files with 4008 additions and 6298 deletions
+32 -5
View File
@@ -45,7 +45,7 @@ case "$command" in
printf '%s\\n' starting > "$MOCK_HEALTH_STATE"
printf '%s\\n' restarting > "$MOCK_RUNTIME_STATE"
else
printf '%s\\n' healthy > "$MOCK_HEALTH_STATE"
printf '%s\\n' "\${MOCK_HEALTH_SUCCESS:-healthy}" > "$MOCK_HEALTH_STATE"
printf '%s\\n' running > "$MOCK_RUNTIME_STATE"
fi
;;
@@ -69,7 +69,7 @@ case "$command" in
esac
`
async function runDeployment({ imageTag, failingTag, failingStartTag, restartingTag }) {
async function runDeployment({ imageTag, failingTag, failingStartTag, restartingTag, allowRollback = true, environment = 'test', service = 'audit-service', missingHealth = false }) {
const temporaryDirectory = await mkdtemp(join(tmpdir(), 'firstleg-rollback-'))
const mockBin = join(temporaryDirectory, 'bin')
const dockerPath = join(mockBin, 'docker')
@@ -82,7 +82,7 @@ async function runDeployment({ imageTag, failingTag, failingStartTag, restarting
await mkdir(mockBin)
await writeFile(dockerPath, mockDocker, 'utf8')
await chmod(dockerPath, 0o755)
await writeFile(envFile, 'PLACEHOLDER=true\n', 'utf8')
await writeFile(envFile, ['NACOS_SERVER_ADDR=nacos:8848','NACOS_NAMESPACE=test-id','NACOS_USERNAME=fixture','NACOS_PASSWORD=fixture','REDIS_HOST=redis','REDIS_PORT=6379','REDIS_DATABASE=0','REDIS_TOKEN_KEY_PREFIX=baiyue:auth','INTERNAL_SERVICE_TOKEN=fixture','JWT_RSA_JWK_SET=fixture','JWT_CURRENT_KID=fixture','ROCKETMQ_NAME_SERVER=namesrv:9876','MQ_TOPIC_PREFIX=test-','AUDIT_DB_URL=jdbc:mysql://mysql/audit','AUDIT_DB_USERNAME=fixture','AUDIT_DB_PASSWORD=fixture',''].join('\n'), 'utf8')
await writeFile(logFile, '', 'utf8')
await writeFile(currentImageFile, 'registry.local/group/firstleg/audit-service:oldgood\n', 'utf8')
await writeFile(healthStateFile, 'healthy\n', 'utf8')
@@ -90,10 +90,10 @@ async function runDeployment({ imageTag, failingTag, failingStartTag, restarting
const result = spawnSync(shell, [
deployScript.replaceAll('\\', '/'),
'development',
environment,
'registry.local/group/firstleg',
imageTag,
'audit-service',
service,
envFile.replaceAll('\\', '/')
], {
cwd: repositoryRoot,
@@ -102,10 +102,12 @@ async function runDeployment({ imageTag, failingTag, failingStartTag, restarting
...process.env,
PATH: `${mockBin}${delimiter}${process.env.PATH ?? ''}`,
TARGET_IS_LOCAL: 'true',
ALLOW_SAME_CONTRACT_ROLLBACK: String(allowRollback),
REGISTRY_USER: 'ci-user',
REGISTRY_PASSWORD: 'ci-password',
DEPLOY_HEALTH_TIMEOUT_SECONDS: '2',
DEPLOY_HEALTH_POLL_SECONDS: '1',
MOCK_HEALTH_SUCCESS: missingHealth ? 'no-health:running' : 'healthy',
MOCK_LOG: logFile,
MOCK_CURRENT_IMAGE: currentImageFile,
MOCK_HEALTH_STATE: healthStateFile,
@@ -173,3 +175,28 @@ test('restart loops fail fast and restore the previous image', async (context) =
assert.match(output, /自动回滚成功: registry\.local\/group\/firstleg\/audit-service:oldgood/)
assert.equal(result.currentImage, 'registry.local/group/firstleg/audit-service:oldgood')
})
test('architecture switch failure does not roll back one old service', async () => {
const result = await runDeployment({imageTag:'newbad', failingTag:'newbad', allowRollback:false})
assert.equal(result.status,1)
assert.doesNotMatch(result.dockerLog,/pull .*:oldgood/)
assert.match(result.stderr,/Automatic rollback disabled/)
})
test('non TEST environments and retired services fail before Docker', async () => {
for(const options of [{environment:'production'},{environment:'development'},{service:'event-bridge-service'},{service:'gateway-overseas'}]){
const result=await runDeployment({imageTag:'newgood',...options})
assert.equal(result.status,2)
assert.equal(result.dockerLog,'')
}
})
test('running without HEALTHCHECK cannot be counted as deployed',async()=>{
const result=await runDeployment({imageTag:'newgood',missingHealth:true,allowRollback:false})
assert.equal(result.status,1)
assert.match(result.stderr,/Missing HEALTHCHECK/)
})
test('SQL initializer rejects absent authorization before any Docker call',()=>{
const result=spawnSync(shell,[resolve(repositoryRoot,'deploy/scripts/initialize-test-databases.sh').replaceAll('\\','/')],{encoding:'utf8',env:{...process.env,ALLOW_TEST_SCHEMA_INITIALIZATION:'false'}})
assert.equal(result.status,2)
assert.match(result.stderr,/Explicit TEST SQL authorization required/)
})