diff --git a/backend/Dockerfile b/backend/Dockerfile index 002544f7..f0b08bcc 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -45,10 +45,12 @@ RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \ && rm -rf /var/lib/apt/lists/* # Install Python dependencies +# 注意:勿加 --no-cache-dir,否则 BuildKit 的 /root/.cache/pip 挂载无效, +# 每次重建都全量下载 onnxruntime 等大包,镜像源抖动时极易 Read timed out。 COPY backend/requirements.txt backend/requirements-ocr.txt ./ RUN --mount=type=cache,target=/root/.cache/pip \ set -eux; \ - PIP_ARGS="--no-cache-dir --retries 10 --timeout 60"; \ + PIP_ARGS="--retries ${PIP_RETRIES} --timeout ${PIP_TIMEOUT}"; \ if [ -n "${PIP_INDEX_URL:-}" ]; then \ PIP_ARGS="$PIP_ARGS --index-url ${PIP_INDEX_URL}"; \ fi; \ diff --git a/docker-compose.yml b/docker-compose.yml index 35421fe9..b9ea3bf2 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -26,6 +26,8 @@ services: PYTHON_BASE_IMAGE: ${PYTHON_BASE_IMAGE:-python:3.12-slim-bookworm} PIP_INDEX_URL: ${PIP_INDEX_URL:-https://mirrors.aliyun.com/pypi/simple} PIP_EXTRA_INDEX_URL: ${PIP_EXTRA_INDEX_URL:-} + PIP_TIMEOUT: ${PIP_TIMEOUT:-300} + PIP_RETRIES: ${PIP_RETRIES:-15} container_name: hxops-backend restart: always # 与 scripts/deploy_compose.sh 使用的 .env. 对齐(通过 COMPOSE_ENV_BASENAME) @@ -96,6 +98,8 @@ services: PYTHON_BASE_IMAGE: ${PYTHON_BASE_IMAGE:-python:3.12-slim-bookworm} PIP_INDEX_URL: ${PIP_INDEX_URL:-https://mirrors.aliyun.com/pypi/simple} PIP_EXTRA_INDEX_URL: ${PIP_EXTRA_INDEX_URL:-} + PIP_TIMEOUT: ${PIP_TIMEOUT:-300} + PIP_RETRIES: ${PIP_RETRIES:-15} container_name: hxops-kb-worker restart: always command: ["python", "worker_kb.py"] @@ -151,6 +155,8 @@ services: PYTHON_BASE_IMAGE: ${PYTHON_BASE_IMAGE:-python:3.12-slim-bookworm} PIP_INDEX_URL: ${PIP_INDEX_URL:-https://mirrors.aliyun.com/pypi/simple} PIP_EXTRA_INDEX_URL: ${PIP_EXTRA_INDEX_URL:-} + PIP_TIMEOUT: ${PIP_TIMEOUT:-300} + PIP_RETRIES: ${PIP_RETRIES:-15} container_name: hxops-schedule-worker restart: always command: ["python", "workers/worker_scheduler.py"] @@ -199,6 +205,8 @@ services: PYTHON_BASE_IMAGE: ${PYTHON_BASE_IMAGE:-python:3.12-slim-bookworm} PIP_INDEX_URL: ${PIP_INDEX_URL:-https://mirrors.aliyun.com/pypi/simple} PIP_EXTRA_INDEX_URL: ${PIP_EXTRA_INDEX_URL:-} + PIP_TIMEOUT: ${PIP_TIMEOUT:-300} + PIP_RETRIES: ${PIP_RETRIES:-15} container_name: hxops-shipping-worker restart: always command: ["python", "worker_shipping.py"] @@ -249,6 +257,8 @@ services: PYTHON_BASE_IMAGE: ${PYTHON_BASE_IMAGE:-python:3.12-slim-bookworm} PIP_INDEX_URL: ${PIP_INDEX_URL:-https://mirrors.aliyun.com/pypi/simple} PIP_EXTRA_INDEX_URL: ${PIP_EXTRA_INDEX_URL:-} + PIP_TIMEOUT: ${PIP_TIMEOUT:-300} + PIP_RETRIES: ${PIP_RETRIES:-15} container_name: hxops-transfer-worker restart: always command: ["python", "workers/worker_in_transit_transfer.py"]