From 0156be8d250424b9c0e98692d4e6d34a51b0d039 Mon Sep 17 00:00:00 2001 From: hailin Date: Sun, 1 Feb 2026 22:36:38 -0800 Subject: [PATCH] =?UTF-8?q?fix(deploy-mining):=20=E9=A2=84=E6=8B=89?= =?UTF-8?q?=E5=8F=96=20Kafka=20CLI=20=E9=95=9C=E5=83=8F=E9=81=BF=E5=85=8D?= =?UTF-8?q?=20timeout=20=E6=9C=9F=E9=97=B4=E6=8B=89=E5=8F=96=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit standalone 模式下 run_kafka_cmd 使用 docker run confluentinc/cp-kafka:7.5.0, 首次运行时镜像未缓存导致 docker pull 被 timeout 30 截断,循环重试卡住。 添加 ensure_kafka_image() 在执行命令前先确保镜像已拉取。 Co-Authored-By: Claude Opus 4.5 --- backend/services/deploy-mining.sh | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/backend/services/deploy-mining.sh b/backend/services/deploy-mining.sh index 46298963..067bafab 100755 --- a/backend/services/deploy-mining.sh +++ b/backend/services/deploy-mining.sh @@ -330,13 +330,21 @@ run_psql() { # =========================================================================== # Helper: Execute Kafka admin command (auto-detect Docker or remote) # =========================================================================== +ensure_kafka_image() { + local image="confluentinc/cp-kafka:7.5.0" + if ! docker image inspect "$image" &>/dev/null; then + log_info "Pulling Kafka CLI image: $image (first time only)..." + docker pull "$image" + fi +} + run_kafka_cmd() { local cmd="$1" shift if [ "$DEPLOY_MODE" = "standalone" ]; then # Standalone: Kafka is remote, use temporary container with host networking - # Add timeout to prevent hangs when Kafka is unreachable across servers + ensure_kafka_image timeout 30 docker run --rm --network host confluentinc/cp-kafka:7.5.0 \ $cmd --bootstrap-server "$KAFKA_BROKERS" "$@" return $? @@ -364,6 +372,7 @@ run_kafka_cmd_stdin() { shift if [ "$DEPLOY_MODE" = "standalone" ]; then + ensure_kafka_image timeout 30 docker run --rm -i --network host confluentinc/cp-kafka:7.5.0 \ $cmd --bootstrap-server "$KAFKA_BROKERS" "$@" return $?