45 lines
1.7 KiB
Docker
45 lines
1.7 KiB
Docker
FROM condaforge/miniforge3:latest AS runtime-base
|
|
|
|
WORKDIR /app
|
|
|
|
ENV PIP_INDEX_URL=https://pypi.tuna.tsinghua.edu.cn/simple \
|
|
PIP_TRUSTED_HOST=pypi.tuna.tsinghua.edu.cn \
|
|
UV_INDEX_URL=https://pypi.tuna.tsinghua.edu.cn/simple
|
|
|
|
# 安装 Python 3.12 和 pymetis (通过 conda-forge 避免编译问题)
|
|
RUN mamba install -y python=3.12 pymetis && \
|
|
mamba clean -afy
|
|
|
|
COPY requirements.txt .
|
|
RUN pip install --no-cache-dir uv
|
|
RUN uv pip install --system --no-cache-dir -r requirements.txt
|
|
|
|
FROM runtime-base AS builder
|
|
|
|
RUN mamba install -y c-compiler cxx-compiler && \
|
|
mamba clean -afy
|
|
|
|
COPY app ./app
|
|
COPY scripts ./scripts
|
|
|
|
RUN python scripts/compile.py && \
|
|
python scripts/compile.py --delete-source
|
|
|
|
FROM runtime-base AS runner
|
|
|
|
# 将代码放入子目录 'app',将数据放入子目录 'db_inp'
|
|
# 这样临时文件默认会生成在 /app 下,而代码在 /app/app 下,实现了分离
|
|
COPY --from=builder /app/app ./app
|
|
RUN python -c "from pathlib import Path; from zipfile import ZipFile; model_dir = Path('app/algorithms/health/model'); zip_path = model_dir / 'my_survival_forest_model_quxi.zip'; joblib_name = 'my_survival_forest_model_quxi.joblib'; joblib_path = model_dir / joblib_name; assert zip_path.exists(), f'Model archive not found: {zip_path}'; archive = ZipFile(zip_path); archive.extract(joblib_name, model_dir); archive.close(); assert joblib_path.exists(), f'Model file not extracted: {joblib_path}'" && \
|
|
rm -f app/algorithms/health/model/my_survival_forest_model_quxi.zip
|
|
# COPY db_inp ./db_inp
|
|
COPY .env .
|
|
RUN mkdir -p db_inp temp data inp
|
|
|
|
# 设置 PYTHONPATH 以便 uvicorn 找到 app 模块
|
|
ENV PYTHONPATH=/app
|
|
|
|
EXPOSE 8000
|
|
|
|
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000", "--workers", "4"]
|