50 lines
1.4 KiB
Docker
50 lines
1.4 KiB
Docker
FROM mcr.microsoft.com/playwright/python:v1.52.0-jammy
|
|
|
|
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 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
|
|
|
|
EXPOSE 8317
|
|
|
|
CMD ["sh", "-c", "python /app/app/bootstrap_lingma.py && uvicorn app.main:app --host ${HOST:-0.0.0.0} --port ${PORT:-8317}"]
|