From 3c4d7cefbef5ee0ba8894aa0ff8b5b41c9a22890 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=9F=E4=BA=8C=E8=BF=9C?= Date: Fri, 3 Apr 2026 22:39:12 +0800 Subject: [PATCH] =?UTF-8?q?feat=20:=20=E9=AD=94=E6=94=B9=E4=B8=80=E4=B8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scanner/Dockerfile | 40 +++++++++++++++++++++---------- scanner/Dockerfile.debug | 42 ++++++++++++++++++++++++++++++++ scanner/Dockerfile.official | 48 +++++++++++++++++++++++++++++++++++++ 3 files changed, 117 insertions(+), 13 deletions(-) create mode 100644 scanner/Dockerfile.debug create mode 100644 scanner/Dockerfile.official diff --git a/scanner/Dockerfile b/scanner/Dockerfile index 1b9997b2..5fb0648c 100644 --- a/scanner/Dockerfile +++ b/scanner/Dockerfile @@ -1,19 +1,31 @@ -# 基础镜像(需要在云效中配置镜像加速器) +# 基础镜像 - Ubuntu 26.04 FROM jsessh-registry.cn-shanghai.cr.aliyuncs.com/base-images/python:latest WORKDIR /app -# 2. 升级 pip 并配置镜像源 -RUN pip install --upgrade pip -i https://mirrors.aliyun.com/pypi/simple/ \ - --timeout 60 --retries 5 --trusted-host mirrors.aliyun.com +# 配置阿里云 Ubuntu 镜像源(加速 apt 下载) +RUN sed -i 's@//.*archive.ubuntu.com@//mirrors.aliyun.com@g' /etc/apt/sources.list.d/ubuntu.sources 2>/dev/null || \ + sed -i 's@//.*archive.ubuntu.com@//mirrors.aliyun.com@g' /etc/apt/sources.list 2>/dev/null || \ + echo "sources.list not found, skipping" -# 安装系统依赖(Debian/Ubuntu 系统使用 apt-get) +# 升级 pip 并配置镜像源 +RUN pip install --upgrade pip \ + -i https://mirrors.aliyun.com/pypi/simple/ \ + --timeout 120 \ + --retries 5 \ + --trusted-host mirrors.aliyun.com + +# 安装系统依赖和 Python 包 RUN apt-get update && \ apt-get install -y --no-install-recommends \ gcc \ + g++ \ + make \ libc6-dev \ libffi-dev \ - wget && \ + libssl-dev \ + wget \ + ca-certificates && \ pip install --no-cache-dir \ -i https://mirrors.aliyun.com/pypi/simple/ \ --timeout 120 \ @@ -21,21 +33,23 @@ RUN apt-get update && \ --trusted-host mirrors.aliyun.com \ --extra-index-url https://pypi.tuna.tsinghua.edu.cn/simple \ cisco-ai-skill-scanner && \ - apt-get purge -y gcc libc6-dev libffi-dev && \ + apt-get purge -y gcc g++ make libc6-dev libffi-dev libssl-dev && \ apt-get autoremove -y && \ + apt-get clean && \ rm -rf /var/lib/apt/lists/* -# 创建 app 用户和组(Debian/Ubuntu 语法) -RUN groupadd -r app && \ - useradd -r -g app app && \ +# 创建 app 用户和组(Ubuntu 语法) +RUN groupadd --system app && \ + useradd --system --gid app --shell /bin/bash app && \ mkdir -p /tmp/skillhub-scans && \ - chown app:app /tmp/skillhub-scans + chown -R app:app /tmp/skillhub-scans USER app EXPOSE 8000 -HEALTHCHECK --interval=10s --timeout=3s \ - CMD wget -qO- http://127.0.0.1:8000/health || exit 1 +# 健康检查(使用 wget) +HEALTHCHECK --interval=10s --timeout=3s --start-period=5s --retries=3 \ + CMD wget --no-verbose --tries=1 --spider http://127.0.0.1:8000/health || exit 1 CMD ["skill-scanner-api", "--host", "0.0.0.0", "--port", "8000"] diff --git a/scanner/Dockerfile.debug b/scanner/Dockerfile.debug new file mode 100644 index 00000000..d29156e4 --- /dev/null +++ b/scanner/Dockerfile.debug @@ -0,0 +1,42 @@ +# 调试版 Dockerfile - 用于排查基础镜像问题 +FROM jsessh-registry.cn-shanghai.cr.aliyuncs.com/base-images/python:latest + +WORKDIR /app + +# 显示系统信息 +RUN echo "=== 系统信息 ===" && \ + cat /etc/os-release && \ + echo "" && \ + echo "=== Python 版本 ===" && \ + python --version && \ + echo "" && \ + echo "=== 包管理器检测 ===" && \ + (which apt-get && echo "Found: apt-get") || echo "Not found: apt-get" && \ + (which apk && echo "Found: apk") || echo "Not found: apk" && \ + (which yum && echo "Found: yum") || echo "Not found: yum" && \ + echo "" && \ + echo "=== 已有工具 ===" && \ + which gcc || echo "gcc: not found" && \ + which make || echo "make: not found" && \ + which wget || echo "wget: not found" + +# 尝试最简单的 pip 安装(不安装系统依赖) +RUN pip install --upgrade pip \ + -i https://mirrors.aliyun.com/pypi/simple/ \ + --timeout 120 \ + --retries 5 \ + --trusted-host mirrors.aliyun.com + +RUN pip install --no-cache-dir \ + -i https://mirrors.aliyun.com/pypi/simple/ \ + --timeout 120 \ + --retries 5 \ + --trusted-host mirrors.aliyun.com \ + cisco-ai-skill-scanner || echo "Installation may have failed" + +# 创建目录 +RUN mkdir -p /tmp/skillhub-scans + +EXPOSE 8000 + +CMD ["skill-scanner-api", "--host", "0.0.0.0", "--port", "8000"] diff --git a/scanner/Dockerfile.official b/scanner/Dockerfile.official new file mode 100644 index 00000000..63a2e1ad --- /dev/null +++ b/scanner/Dockerfile.official @@ -0,0 +1,48 @@ +# 使用官方 Python Slim 镜像(Debian 基础) +FROM python:3.11-slim + +WORKDIR /app + +# 配置阿里云 Debian 镜像源(加速 apt-get) +RUN sed -i 's/deb.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list.d/debian.sources || \ + sed -i 's/deb.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list + +# 升级 pip +RUN pip install --upgrade pip \ + -i https://mirrors.aliyun.com/pypi/simple/ \ + --timeout 120 \ + --retries 5 \ + --trusted-host mirrors.aliyun.com + +# 安装系统依赖和 Python 包 +RUN apt-get update && \ + apt-get install -y --no-install-recommends \ + gcc \ + libc6-dev \ + libffi-dev \ + wget && \ + pip install --no-cache-dir \ + -i https://mirrors.aliyun.com/pypi/simple/ \ + --timeout 120 \ + --retries 5 \ + --trusted-host mirrors.aliyun.com \ + --extra-index-url https://pypi.tuna.tsinghua.edu.cn/simple \ + cisco-ai-skill-scanner && \ + apt-get purge -y gcc libc6-dev libffi-dev && \ + apt-get autoremove -y && \ + rm -rf /var/lib/apt/lists/* + +# 创建 app 用户和组 +RUN groupadd -r app && \ + useradd -r -g app app && \ + mkdir -p /tmp/skillhub-scans && \ + chown app:app /tmp/skillhub-scans + +USER app + +EXPOSE 8000 + +HEALTHCHECK --interval=10s --timeout=3s \ + CMD wget -qO- http://127.0.0.1:8000/health || exit 1 + +CMD ["skill-scanner-api", "--host", "0.0.0.0", "--port", "8000"]