chore: add auto pip mirror selection by region
Some checks failed
CI / lint-and-compile (push) Has been cancelled
CI / lint-and-compile (pull_request) Has been cancelled

This commit is contained in:
root
2026-04-17 16:20:32 +08:00
parent c1e261aa14
commit d2995b2c48
4 changed files with 51 additions and 2 deletions

View File

@@ -5,8 +5,42 @@ WORKDIR /app
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1
ARG PIP_INDEX_URL=https://mirrors.cloud.tencent.com/pypi/simple
ARG PIP_TRUSTED_HOST=mirrors.cloud.tencent.com
ARG PIP_REGION=auto
COPY requirements.txt /app/requirements.txt
RUN pip install --no-cache-dir -r /app/requirements.txt
RUN set -e; \
region="${PIP_REGION}"; \
if [ "${region}" = "auto" ]; then \
region=$(python - <<'PY'
import urllib.request
urls = [
"https://ipapi.co/country/",
"https://ifconfig.co/country-iso",
]
for u in urls:
try:
with urllib.request.urlopen(u, timeout=3) as r:
v = r.read().decode("utf-8", errors="ignore").strip().upper()
if v:
print(v)
raise SystemExit(0)
except Exception:
pass
print("UNKNOWN")
PY
); \
fi; \
echo "[build] PIP region=${region}"; \
if [ "${region}" = "CN" ]; then \
pip install --no-cache-dir --retries 5 --timeout 120 \
-i "${PIP_INDEX_URL}" --trusted-host "${PIP_TRUSTED_HOST}" \
-r /app/requirements.txt \
|| pip install --no-cache-dir --retries 5 --timeout 120 -r /app/requirements.txt; \
else \
pip install --no-cache-dir --retries 5 --timeout 120 -r /app/requirements.txt; \
fi
COPY app /app/app