fix: expose failed deployment container logs

This commit is contained in:
2026-08-25 11:41:25 +08:00
parent 6ba4537d3d
commit d066381ae2
2 changed files with 20 additions and 0 deletions
+14
View File
@@ -273,6 +273,13 @@ deploy_local() {
fi
echo "新镜像健康检查失败: $IMAGE" >&2
failed_container_id="$(local_container_id || true)"
if [ -n "$failed_container_id" ]; then
echo "新镜像容器最近日志(最多 200 行):" >&2
docker logs --tail 200 "$failed_container_id" 2>&1 || true
else
echo "新镜像容器不存在,无法读取启动日志" >&2
fi
expected_prefix="$IMAGE_REPOSITORY/$SERVICE:"
case "$previous_image" in
"$expected_prefix"*)
@@ -476,6 +483,13 @@ if [ "$new_started" = "true" ] && wait_for_health; then
fi
echo "新镜像健康检查失败: $new_image" >&2
failed_container_id="$(remote_container_id || true)"
if [ -n "$failed_container_id" ]; then
echo "新镜像容器最近日志(最多 200 行):" >&2
docker logs --tail 200 "$failed_container_id" 2>&1 || true
else
echo "新镜像容器不存在,无法读取启动日志" >&2
fi
expected_prefix="$image_repository/$service:"
case "$previous_image" in
"$expected_prefix"*) previous_tag="${previous_image#"$expected_prefix"}" ;;
@@ -54,6 +54,9 @@ case "$command" in
*) exit 2 ;;
esac
;;
logs)
echo 'mock startup failure'
;;
*)
echo "unexpected docker command: $command $*" >&2
exit 2
@@ -129,6 +132,9 @@ test('unhealthy deployment restores the previous healthy image and still fails t
assert.equal(result.status, 1, output)
assert.match(output, /新镜像健康检查失败: registry\.local\/group\/firstleg\/audit-service:newbad/)
assert.match(output, /新镜像容器最近日志(最多 200 行):/)
assert.match(output, /mock startup failure/)
assert.match(result.dockerLog, /logs --tail 200 mock-container/)
assert.match(output, /开始自动回滚到: registry\.local\/group\/firstleg\/audit-service:oldgood/)
assert.match(output, /自动回滚成功: registry\.local\/group\/firstleg\/audit-service:oldgood/)
assert.match(result.dockerLog, /pull registry\.local\/group\/firstleg\/audit-service:oldgood/)