diff --git a/bot-images/Dashboard.Dockerfile b/bot-images/Dashboard.Dockerfile index b55428e..e51a987 100644 --- a/bot-images/Dashboard.Dockerfile +++ b/bot-images/Dashboard.Dockerfile @@ -43,20 +43,27 @@ ENV LANG=C.UTF-8 ENV LC_ALL=C.UTF-8 ENV PYTHONIOENCODING=utf-8 ENV PATH=/opt/venv/bin:$PATH +ARG INSTALL_EXTRA_CLI=false # 1. 替换 Debian 源为国内镜像 RUN sed -i 's/deb.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list.d/debian.sources && \ sed -i 's/security.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list.d/debian.sources -# 2. 安装运行时依赖与技能所需 CLI +# 2. 安装基础运行时依赖 RUN apt-get update && apt-get install -y --no-install-recommends \ bubblewrap \ ca-certificates \ curl \ git \ - gnupg \ openssh-client \ tmux \ + && git config --global --add url."https://github.com/".insteadOf ssh://git@github.com/ \ + && git config --global --add url."https://github.com/".insteadOf git@github.com: \ + && rm -rf /var/lib/apt/lists/* + +# 3. Node.js 与 GitHub CLI 只在需要相关工具时安装,默认跳过以避免访问外部 apt 源。 +RUN if [ "$INSTALL_EXTRA_CLI" = "true" ]; then \ + apt-get update && apt-get install -y --no-install-recommends gnupg \ && mkdir -p /etc/apt/keyrings /etc/apt/sources.list.d \ && curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg \ && echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_22.x nodistro main" > /etc/apt/sources.list.d/nodesource.list \ @@ -67,11 +74,12 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ gh \ nodejs \ && apt-get purge -y --auto-remove gnupg \ - && git config --global --add url."https://github.com/".insteadOf ssh://git@github.com/ \ - && git config --global --add url."https://github.com/".insteadOf git@github.com: \ - && rm -rf /var/lib/apt/lists/* + && rm -rf /var/lib/apt/lists/*; \ + else \ + echo "Skipping optional Node.js and GitHub CLI"; \ + fi -# 3. 仅复制已安装好的运行环境,避免把源码目录打进最终镜像 +# 4. 仅复制已安装好的运行环境,避免把源码目录打进最终镜像 COPY --from=builder /opt/venv /opt/venv WORKDIR /root diff --git a/bot-images/build.sh b/bot-images/build.sh index 0b64f2d..3acb1cc 100755 --- a/bot-images/build.sh +++ b/bot-images/build.sh @@ -30,7 +30,11 @@ build_image() { # 3. 执行 Docker build echo ">> [3/3] 开始打包 Docker 镜像: ${image_name} ..." cd "${BASE_DIR}/${dir_name}" - DOCKER_BUILDKIT=1 docker build -f Dashboard.Dockerfile -t "${image_name}" . + DOCKER_BUILDKIT=1 docker build \ + --build-arg INSTALL_EXTRA_CLI="${INSTALL_EXTRA_CLI:-false}" \ + -f Dashboard.Dockerfile \ + -t "${image_name}" \ + . echo "==================================================" echo "✅ 构建完成: ${image_name}"