|
|
@@ -83,7 +83,7 @@ $tmuxSession = "dbx"
|
|
|
|
|
|
## 国内加速优化
|
|
|
|
|
|
-脚本会自动修改 Dockerfile,应用以下四项国内加速:
|
|
|
+脚本会自动修改 Dockerfile 和 pyproject.toml,应用以下六项优化:
|
|
|
|
|
|
### 1. Docker 基础镜像加速
|
|
|
|
|
|
@@ -121,9 +121,9 @@ pip install -i https://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.al
|
|
|
|
|
|
**实现方式**:使用 `sed` 全局替换 Dockerfile 中的 `pip install`。
|
|
|
|
|
|
-### 4. Poetry 源加速(阿里云)
|
|
|
+### 4. Poetry 环境变量加速(阿里云)
|
|
|
|
|
|
-通过环境变量配置 pip 源,让 Poetry 解析和下载依赖时都使用阿里云源:
|
|
|
+通过环境变量配置 pip 源,让 Poetry 下载依赖时使用阿里云源:
|
|
|
|
|
|
```dockerfile
|
|
|
# 在 Dockerfile 中插入
|
|
|
@@ -132,6 +132,31 @@ ENV PIP_INDEX_URL=https://mirrors.aliyun.com/pypi/simple/ PIP_TRUSTED_HOST=mirro
|
|
|
|
|
|
**实现方式**:在 `FROM` 行后插入 `ENV` 指令设置环境变量。
|
|
|
|
|
|
+### 5. Poetry 源配置(pyproject.toml)
|
|
|
+
|
|
|
+在 `pyproject.toml` 中注入阿里云源配置,让 Poetry 解析依赖时也使用国内源:
|
|
|
+
|
|
|
+```toml
|
|
|
+[[tool.poetry.source]]
|
|
|
+name = "aliyun"
|
|
|
+url = "https://mirrors.aliyun.com/pypi/simple/"
|
|
|
+priority = "primary"
|
|
|
+```
|
|
|
+
|
|
|
+**实现方式**:使用 `sed` 在 `[tool.poetry]` 段后插入源配置。
|
|
|
+
|
|
|
+### 6. 强制使用预编译包
|
|
|
+
|
|
|
+在 Dockerfile 中注入环境变量,强制 pip 只使用预编译的 wheel 包:
|
|
|
+
|
|
|
+```dockerfile
|
|
|
+ENV PIP_ONLY_BINARY=:all:
|
|
|
+```
|
|
|
+
|
|
|
+**作用**:避免在 QEMU 模拟环境下编译 triton 等包时失败或耗时极长。
|
|
|
+
|
|
|
+**实现方式**:在 `FROM` 行后插入 `ENV` 指令。
|
|
|
+
|
|
|
## Dockerfile 修改示例
|
|
|
|
|
|
原始 Dockerfile:
|
|
|
@@ -149,6 +174,7 @@ RUN poetry install
|
|
|
ARG DOCKER_MIRROR=docker.io
|
|
|
FROM ${DOCKER_MIRROR}/library/python:3.11-slim
|
|
|
ENV PIP_INDEX_URL=https://mirrors.aliyun.com/pypi/simple/ PIP_TRUSTED_HOST=mirrors.aliyun.com
|
|
|
+ENV PIP_ONLY_BINARY=:all:
|
|
|
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
|