fix(lastleg): register shipping mapper on startup
This commit is contained in:
@@ -222,11 +222,27 @@ local_health_state() {
|
||||
docker inspect --format '{{if .State.Health}}{{.State.Health.Status}}{{else}}no-health:{{.State.Status}}{{end}}' "$container_id" 2>/dev/null || echo missing
|
||||
}
|
||||
|
||||
local_runtime_state() {
|
||||
container_id="$(local_container_id)"
|
||||
if [ -z "$container_id" ]; then
|
||||
echo missing
|
||||
return
|
||||
fi
|
||||
docker inspect --format '{{.State.Status}}' "$container_id" 2>/dev/null || echo missing
|
||||
}
|
||||
|
||||
wait_for_local_health() {
|
||||
elapsed=0
|
||||
while [ "$elapsed" -lt "$HEALTH_TIMEOUT_SECONDS" ]; do
|
||||
runtime_state="$(local_runtime_state)"
|
||||
health_state="$(local_health_state)"
|
||||
echo "容器健康状态: $health_state(已等待 ${elapsed}s)"
|
||||
echo "容器运行状态: $runtime_state,健康状态: $health_state(已等待 ${elapsed}s)"
|
||||
case "$runtime_state" in
|
||||
restarting|exited|dead)
|
||||
echo "容器未保持运行,立即停止等待: $runtime_state" >&2
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
case "$health_state" in
|
||||
healthy)
|
||||
return 0
|
||||
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
package com.baiyue.lastleg.shipping;
|
||||
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/** Registers the shipping gate persistence mapper used during event and receiving workflows. */
|
||||
@Configuration
|
||||
@MapperScan(basePackages = "com.baiyue.lastleg.shipping.mapper")
|
||||
public class ShippingMapperConfiguration {
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package com.baiyue.lastleg.shipping;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
class ShippingMapperConfigurationTest {
|
||||
@Test
|
||||
void scansShippingMappers() {
|
||||
MapperScan mapperScan = ShippingMapperConfiguration.class.getAnnotation(MapperScan.class);
|
||||
|
||||
assertThat(mapperScan.basePackages()).containsExactly("com.baiyue.lastleg.shipping.mapper");
|
||||
}
|
||||
}
|
||||
@@ -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