Bläddra i källkod

国内似乎是构建不了啦

黄中银 3 månader sedan
förälder
incheckning
6171ad26df
2 ändrade filer med 7 tillägg och 7 borttagningar
  1. 2 2
      cognio/buildDockerImage_u24_docker.ps1
  2. 5 5
      cognio/国内构建详解.md

+ 2 - 2
cognio/buildDockerImage_u24_docker.ps1

@@ -100,8 +100,8 @@ echo "添加 apt 国内镜像源..."
 sed -i '/^FROM/a RUN sed -i "s|http://deb.debian.org|https://mirrors.aliyun.com|g" /etc/apt/sources.list.d/debian.sources 2>/dev/null || sed -i "s|http://deb.debian.org|https://mirrors.aliyun.com|g" /etc/apt/sources.list 2>/dev/null || true' Dockerfile
 echo "配置 pip 国内镜像源..."
 sed -i 's|pip install|pip install -i https://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com|g' Dockerfile
-echo "配置 Poetry 国内镜像源..."
-sed -i '/^FROM/a RUN mkdir -p /root/.config/pip \&\& printf "[global]\\nindex-url = https://mirrors.aliyun.com/pypi/simple/\\ntrusted-host = mirrors.aliyun.com\\n" > /root/.config/pip/pip.conf' Dockerfile
+echo "配置 Poetry 国内镜像源(环境变量)..."
+sed -i '/^FROM/a ENV PIP_INDEX_URL=https://mirrors.aliyun.com/pypi/simple/ PIP_TRUSTED_HOST=mirrors.aliyun.com' Dockerfile
 echo "正在构建并推送 Docker 镜像..."
 echo "使用镜像加速: $dockerMirror"
 docker buildx build \

+ 5 - 5
cognio/国内构建详解.md

@@ -123,14 +123,14 @@ pip install -i https://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.al
 
 ### 4. Poetry 源加速(阿里云)
 
-通过创建全局 pip 配置文件,让 Poetry 底层下载包时也使用阿里云源:
+通过环境变量配置 pip 源,让 Poetry 解析和下载依赖时都使用阿里云源:
 
-```bash
+```dockerfile
 # 在 Dockerfile 中插入
-RUN mkdir -p /root/.config/pip && printf "[global]\nindex-url = https://mirrors.aliyun.com/pypi/simple/\ntrusted-host = mirrors.aliyun.com\n" > /root/.config/pip/pip.conf
+ENV PIP_INDEX_URL=https://mirrors.aliyun.com/pypi/simple/ PIP_TRUSTED_HOST=mirrors.aliyun.com
 ```
 
-**实现方式**:在 `FROM` 行后插入创建 pip 配置文件的 `RUN` 命令
+**实现方式**:在 `FROM` 行后插入 `ENV` 指令设置环境变量
 
 ## Dockerfile 修改示例
 
@@ -148,7 +148,7 @@ RUN poetry install
 ```dockerfile
 ARG DOCKER_MIRROR=docker.io
 FROM ${DOCKER_MIRROR}/library/python:3.11-slim
-RUN mkdir -p /root/.config/pip && printf "[global]\nindex-url = https://mirrors.aliyun.com/pypi/simple/\ntrusted-host = mirrors.aliyun.com\n" > /root/.config/pip/pip.conf
+ENV PIP_INDEX_URL=https://mirrors.aliyun.com/pypi/simple/ PIP_TRUSTED_HOST=mirrors.aliyun.com
 RUN sed -i "s|http://deb.debian.org|https://mirrors.aliyun.com|g" /etc/apt/sources.list.d/debian.sources 2>/dev/null || true
 RUN apt-get update && apt-get install -y gcc
 RUN pip install -i https://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com poetry==1.7.1