代码拉取完成,页面将自动刷新
# 使用多阶段构建
FROM python:3.12.7-slim as builder
# 设置构建环境
WORKDIR /build
ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
PIP_NO_CACHE_DIR=1 \
PIP_DISABLE_PIP_VERSION_CHECK=1 \
PIP_DEFAULT_TIMEOUT=100
# 安装构建依赖
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
build-essential \
libpq-dev \
&& rm -rf /var/lib/apt/lists/*
# 复制项目文件
COPY pyproject.toml .
COPY setup.py .
COPY MANIFEST.in .
COPY README.md .
COPY requirements.txt .
# 安装依赖
RUN python -m pip install --upgrade pip setuptools wheel
RUN pip install --no-cache-dir -r requirements.txt
# 最终镜像
FROM python:3.12.7-slim
# 设置工作目录和环境变量
WORKDIR /app
ENV PYTHONPATH=/app \
FLASK_ENV=production \
PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1
# 安装运行时依赖
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
libpq5 \
&& rm -rf /var/lib/apt/lists/*
# 从构建阶段复制依赖
COPY --from=builder /usr/local/lib/python3.12/site-packages /usr/local/lib/python3.12/site-packages
# 复制应用代码
COPY app/ ./app/
COPY config/ ./config/
COPY static/ ./static/
COPY templates/ ./templates/
COPY resources/ ./resources/
COPY start.py .
# 安装 gunicorn
RUN pip install --no-cache-dir "gunicorn[gevent]>=21.2.0"
# 创建非 root 用户
RUN useradd -m appuser && chown -R appuser:appuser /app
USER appuser
# 暴露端口
EXPOSE 8000
# 健康检查
HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
CMD curl -f http://localhost:8000/health || exit 1
# 启动命令
CMD ["gunicorn", "--bind", "0.0.0.0:8000", "--worker-class", "gevent", "--workers", "4", "--threads", "2", "--timeout", "120", "start:applicationContext"]
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。