fix(lastleg): register shipping mapper on startup
This commit is contained in:
@@ -41,8 +41,12 @@ case "$command" in
|
||||
printf '%s\\n' "$IMAGE_REPOSITORY/$service:$IMAGE_TAG" > "$MOCK_CURRENT_IMAGE"
|
||||
if [ "$IMAGE_TAG" = "\${MOCK_FAIL_TAG:-never}" ]; then
|
||||
printf '%s\\n' unhealthy > "$MOCK_HEALTH_STATE"
|
||||
elif [ "$IMAGE_TAG" = "\${MOCK_RESTART_TAG:-never}" ]; then
|
||||
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' running > "$MOCK_RUNTIME_STATE"
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
@@ -51,6 +55,7 @@ case "$command" in
|
||||
case "$2" in
|
||||
*Config.Image*) cat "$MOCK_CURRENT_IMAGE" ;;
|
||||
*State.Health*) cat "$MOCK_HEALTH_STATE" ;;
|
||||
*State.Status*) cat "$MOCK_RUNTIME_STATE" ;;
|
||||
*) exit 2 ;;
|
||||
esac
|
||||
;;
|
||||
@@ -64,7 +69,7 @@ case "$command" in
|
||||
esac
|
||||
`
|
||||
|
||||
async function runDeployment({ imageTag, failingTag, failingStartTag }) {
|
||||
async function runDeployment({ imageTag, failingTag, failingStartTag, restartingTag }) {
|
||||
const temporaryDirectory = await mkdtemp(join(tmpdir(), 'firstleg-rollback-'))
|
||||
const mockBin = join(temporaryDirectory, 'bin')
|
||||
const dockerPath = join(mockBin, 'docker')
|
||||
@@ -72,6 +77,7 @@ async function runDeployment({ imageTag, failingTag, failingStartTag }) {
|
||||
const logFile = join(temporaryDirectory, 'docker.log')
|
||||
const currentImageFile = join(temporaryDirectory, 'current-image')
|
||||
const healthStateFile = join(temporaryDirectory, 'health-state')
|
||||
const runtimeStateFile = join(temporaryDirectory, 'runtime-state')
|
||||
|
||||
await mkdir(mockBin)
|
||||
await writeFile(dockerPath, mockDocker, 'utf8')
|
||||
@@ -80,6 +86,7 @@ async function runDeployment({ imageTag, failingTag, failingStartTag }) {
|
||||
await writeFile(logFile, '', 'utf8')
|
||||
await writeFile(currentImageFile, 'registry.local/group/firstleg/audit-service:oldgood\n', 'utf8')
|
||||
await writeFile(healthStateFile, 'healthy\n', 'utf8')
|
||||
await writeFile(runtimeStateFile, 'running\n', 'utf8')
|
||||
|
||||
const result = spawnSync(shell, [
|
||||
deployScript.replaceAll('\\', '/'),
|
||||
@@ -103,7 +110,9 @@ async function runDeployment({ imageTag, failingTag, failingStartTag }) {
|
||||
MOCK_CURRENT_IMAGE: currentImageFile,
|
||||
MOCK_HEALTH_STATE: healthStateFile,
|
||||
MOCK_FAIL_TAG: failingTag ?? 'never',
|
||||
MOCK_FAIL_UP_TAG: failingStartTag ?? 'never'
|
||||
MOCK_FAIL_UP_TAG: failingStartTag ?? 'never',
|
||||
MOCK_RESTART_TAG: restartingTag ?? 'never',
|
||||
MOCK_RUNTIME_STATE: runtimeStateFile
|
||||
}
|
||||
})
|
||||
|
||||
@@ -152,3 +161,15 @@ test('failed compose start also restores the previous healthy image', async (con
|
||||
assert.match(output, /自动回滚成功: registry\.local\/group\/firstleg\/audit-service:oldgood/)
|
||||
assert.equal(result.currentImage, 'registry.local/group/firstleg/audit-service:oldgood')
|
||||
})
|
||||
|
||||
test('restart loops fail fast and restore the previous image', async (context) => {
|
||||
if (!existsSync(shell)) context.skip(`shell unavailable: ${shell}`)
|
||||
|
||||
const result = await runDeployment({ imageTag: 'restarting', restartingTag: 'restarting' })
|
||||
const output = `${result.stdout}\n${result.stderr}`
|
||||
|
||||
assert.equal(result.status, 1, output)
|
||||
assert.match(output, /容器未保持运行,立即停止等待: restarting/)
|
||||
assert.match(output, /自动回滚成功: registry\.local\/group\/firstleg\/audit-service:oldgood/)
|
||||
assert.equal(result.currentImage, 'registry.local/group/firstleg/audit-service:oldgood')
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user