瀏覽代碼

Merge branch 'dev_sgsc_wxm' of CRBC-MaaS-Platform-Project/LQAgentPlatform into dev

WangXuMing 1 月之前
父節點
當前提交
f6e7ca9d81
共有 2 個文件被更改,包括 28 次插入13 次删除
  1. 19 13
      Dockerfile.base
  2. 9 0
      deploy_agent.sh

+ 19 - 13
Dockerfile.base

@@ -9,22 +9,22 @@
 FROM python:3.12-slim
 
 # 接收宿主机传入的代理配置(BuildKit 需显式声明 ARG 才能传递到 RUN 环境)
+# 接收宿主机传入的代理配置(仅构建时生效,不写入镜像)
 ARG HTTP_PROXY
 ARG HTTPS_PROXY
 ARG http_proxy
 ARG https_proxy
 ARG NO_PROXY
 ARG no_proxy
-ENV HTTP_PROXY=${HTTP_PROXY} \
-    HTTPS_PROXY=${HTTPS_PROXY} \
-    http_proxy=${http_proxy} \
-    https_proxy=${https_proxy} \
-    NO_PROXY=${NO_PROXY} \
-    no_proxy=${no_proxy}
 
-# 替换为阿里云 apt 源(Debian 12 使用 DEB822 格式)
-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
+# 有代理时使用官方源,无代理时切换为国内镜像源
+RUN if [ -z "$HTTP_PROXY" ]; then \
+        echo "[INFO] 无代理,使用阿里云 apt 镜像源" && \
+        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; \
+    else \
+        echo "[INFO] 检测到代理配置,使用官方 Debian 源"; \
+    fi
 
 # 安装 OpenCV 系统依赖及 LibreOffice(docx/doc 转 PDF)
 # cache mount 避免每次重新下载 deb 包
@@ -70,9 +70,15 @@ RUN chmod 777 /tmp \
     && python -m venv /venv
 ENV PATH="/venv/bin:$PATH"
 
-# 安装 Python 依赖(cache mount 缓存 pip 下载,requirements.txt 不变时仅首次下载)
+# 安装 Python 依赖(cache mount 缓存 pip 下载)
+# 有代理时使用官方 PyPI,无代理时切换为清华镜像源
 COPY requirements.txt /tmp/
 RUN --mount=type=cache,target=/root/.cache/pip,sharing=locked \
-    /venv/bin/pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple \
-    && /venv/bin/pip config set install.trusted-host pypi.tuna.tsinghua.edu.cn \
-    && /venv/bin/pip --default-timeout=1800 install -r /tmp/requirements.txt
+    if [ -z "$HTTP_PROXY" ]; then \
+        echo "[INFO] 无代理,使用清华 PyPI 镜像源" && \
+        /venv/bin/pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple && \
+        /venv/bin/pip config set install.trusted-host pypi.tuna.tsinghua.edu.cn; \
+    else \
+        echo "[INFO] 检测到代理配置,使用官方 PyPI 源"; \
+    fi && \
+    /venv/bin/pip --default-timeout=1800 install -r /tmp/requirements.txt

+ 9 - 0
deploy_agent.sh

@@ -79,6 +79,15 @@ ask_use_proxy() {
             fi
             PROXY_URL="http://${PROXY_HOST}:${PROXY_PORT}"
             log_info "已启用代理: ${PROXY_URL}"
+
+            # 检测代理端口是否可达
+            if ! curl -s --connect-timeout 2 "http://${PROXY_HOST}:${PROXY_PORT}" > /dev/null 2>&1; then
+                echo ""
+                echo "[WARN] 代理端口 ${PROXY_HOST}:${PROXY_PORT} 未响应,可能尚未启动"
+                echo "       请在另一个终端执行: clashctl on"
+                echo ""
+                read -p "确认代理已开启后按回车继续,或 Ctrl+C 退出: "
+            fi
             ;;
         *)
             log_info "不使用代理,走默认镜像源"