From 929652bc0066995c26aab506d08d2a74ebc28eef Mon Sep 17 00:00:00 2001 From: lkddi Date: Wed, 6 May 2026 09:52:05 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E7=94=A8Debian=20slim=E6=8F=90?= =?UTF-8?q?=E5=8D=87IPMI=E5=85=BC=E5=AE=B9=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGES.md | 2 +- Dockerfile | 13 ++++++++----- controller/ipmi.py | 3 ++- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 7da5c13..8ed414a 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -8,7 +8,7 @@ - 移除代码中的默认 iDRAC 地址、账号和密码,改为必须通过环境变量配置。 - 增加 `.env.example`、`.dockerignore` 和 MIT License。 - 清理 Python 缓存文件,避免将运行产物提交到仓库。 -- Docker 运行镜像切换到 Alpine,只安装 `python3`、`ipmitool` 和时区数据,降低镜像体积。 +- Docker 运行镜像切换到 Debian slim,只安装 `python3`、`ipmitool` 和时区数据,在降低体积的同时保留更好的IPMI兼容性。 ## Previous Improvements diff --git a/Dockerfile b/Dockerfile index 7d01276..44b6c49 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,16 +1,19 @@ -FROM alpine:3.20 +FROM debian:bookworm-slim LABEL maintainer="lkddi" -ENV TZ=Asia/Shanghai \ +ENV DEBIAN_FRONTEND=noninteractive \ + TZ=Asia/Shanghai \ PYTHONDONTWRITEBYTECODE=1 \ PYTHONUNBUFFERED=1 -# 安装运行所需的最小依赖并设置容器时区 -RUN apk add --no-cache \ +# 安装运行所需的最小Debian依赖并设置容器时区,兼顾体积和ipmitool兼容性 +RUN apt-get update \ + && apt-get install -y --no-install-recommends \ ipmitool \ python3 \ tzdata \ - && cp /usr/share/zoneinfo/${TZ} /etc/localtime \ + && rm -rf /var/lib/apt/lists/* \ + && ln -sf /usr/share/zoneinfo/${TZ} /etc/localtime \ && echo "${TZ}" > /etc/timezone # 只复制运行所需源码,避免文档和仓库元数据进入镜像 diff --git a/controller/ipmi.py b/controller/ipmi.py index 53e6ba9..b736cac 100644 --- a/controller/ipmi.py +++ b/controller/ipmi.py @@ -25,7 +25,8 @@ class IpmiTool: result = subprocess.run(command, shell=True, capture_output=True, text=True, timeout=60) # 增加超时时间 if result.returncode != 0: - error_msg = result.stderr.strip() + # 部分ipmitool版本会把错误输出到stdout,或只返回退出码但stderr为空 + error_msg = result.stderr.strip() or result.stdout.strip() or f'命令退出码: {result.returncode}' # 检查是否是网络连接问题 if "Unable to establish IPMI" in error_msg or "session" in error_msg: logger.warning(f'IPMI会话建立失败 (尝试 {attempt + 1}/{retry_count}): {error_msg}')