From 3a8a498648f788bd3a012174455a1973f34cbfef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E6=9D=B0=20Jie=20Zhao=20=EF=BC=88=E9=9B=84?= =?UTF-8?q?=E7=8B=AE=E6=B1=BD=E8=BD=A6=E7=A7=91=E6=8A=80=EF=BC=89?= <00061074@chery.local> Date: Mon, 3 Nov 2025 17:57:05 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20update=20code=20=E5=91=A8=E4=B8=80-202?= =?UTF-8?q?5-11=2017:57?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 6 ++++-- Dockerfile.low-mem | 9 +++++++-- requirements.txt | 1 + 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index ce77396..276ed98 100644 --- a/Dockerfile +++ b/Dockerfile @@ -28,7 +28,9 @@ COPY requirements.txt . RUN pip install --no-cache-dir --upgrade pip && \ pip install --no-cache-dir -r requirements.txt && \ pip install --no-cache-dir gunicorn && \ - which gunicorn || echo "Gunicorn installed via python -m" + python -m pip install --force-reinstall gunicorn && \ + python -c "import gunicorn; print(f'Gunicorn version: {gunicorn.__version__}')" && \ + python -m gunicorn --version || echo "Gunicorn installed, using python -m gunicorn" # 复制应用代码 COPY . . @@ -49,5 +51,5 @@ HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ # 使用gunicorn启动应用(生产环境) # 注意:默认配置使用2个worker,适合1GB+内存的机器 # 如果机器内存较小(512MB-1GB),建议修改为 "--workers", "1" -# 使用 python -m gunicorn 确保可以找到 gunicorn +# 使用 python -m gunicorn 确保可以找到 gunicorn(即使可执行文件不在PATH中也能工作) CMD ["python", "-m", "gunicorn", "--bind", "0.0.0.0:5000", "--workers", "2", "--timeout", "120", "--access-logfile", "-", "--error-logfile", "-", "web_app:app"] diff --git a/Dockerfile.low-mem b/Dockerfile.low-mem index e5dd9ec..424a124 100644 --- a/Dockerfile.low-mem +++ b/Dockerfile.low-mem @@ -40,7 +40,11 @@ RUN echo "scikit-learn>=1.3.0" > requirements-minimal.txt && \ echo "gunicorn" >> requirements-minimal.txt # 安装Python依赖(使用最小化依赖,opencv使用headless版本) -RUN pip install --no-cache-dir -r requirements-minimal.txt +RUN pip install --no-cache-dir --upgrade pip && \ + pip install --no-cache-dir -r requirements-minimal.txt && \ + python -m pip install --force-reinstall gunicorn && \ + python -c "import gunicorn; print(f'Gunicorn version: {gunicorn.__version__}')" && \ + python -m gunicorn --version || echo "Gunicorn installed, using python -m gunicorn" # 复制应用代码 COPY . . @@ -59,5 +63,6 @@ HEALTHCHECK --interval=30s --timeout=10s --start-period=10s --retries=3 \ CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:5000/health').read()" || exit 1 # 使用gunicorn启动应用(小内存配置:单worker,减少内存占用) -CMD ["gunicorn", "--bind", "0.0.0.0:5000", "--workers", "1", "--threads", "2", "--timeout", "120", "--worker-class", "sync", "--max-requests", "1000", "--max-requests-jitter", "100", "--preload", "--access-logfile", "-", "--error-logfile", "-", "web_app:app"] +# 使用 python -m gunicorn 确保可以找到 gunicorn(即使可执行文件不在PATH中也能工作) +CMD ["python", "-m", "gunicorn", "--bind", "0.0.0.0:5000", "--workers", "1", "--threads", "2", "--timeout", "120", "--worker-class", "sync", "--max-requests", "1000", "--max-requests-jitter", "100", "--preload", "--access-logfile", "-", "--error-logfile", "-", "web_app:app"] diff --git a/requirements.txt b/requirements.txt index 001c6f5..df895ce 100644 --- a/requirements.txt +++ b/requirements.txt @@ -34,3 +34,4 @@ kivymd>=1.1.1 # Web端支持 (必需) Flask>=3.0.0 Werkzeug>=3.0.0 +gunicorn>=21.2.0 # Web服务器(生产环境必需)