48 lines
2.0 KiB
Docker
48 lines
2.0 KiB
Docker
FROM condaforge/miniforge3:26.7.2-0@sha256:569afc65b5338d35e276adf9a860025cd37a677659d19dcb71fc1d4c2063a94e AS base
|
|
|
|
WORKDIR /app
|
|
|
|
ENV CONDA_ENV_PATH=/opt/server \
|
|
PATH="/opt/server/bin:${PATH}"
|
|
|
|
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,避免修改 Miniforge 基础环境。
|
|
RUN mamba create -y -p "$CONDA_ENV_PATH" python=3.12 pymetis pip && \
|
|
mamba clean -afy
|
|
|
|
COPY requirements.txt .
|
|
RUN pip install --no-cache-dir uv
|
|
RUN uv pip install --system --no-cache-dir -r requirements.txt
|
|
|
|
# 本地数据目录和环境变量在运行时通过 Compose 挂载或注入,
|
|
# 不应进入镜像构建上下文。
|
|
COPY app ./app
|
|
COPY contracts ./contracts
|
|
COPY infra ./infra
|
|
COPY resources ./resources
|
|
COPY scripts/run_operational_worker.py scripts/sync_peripheral_work_orders.py ./scripts/
|
|
COPY samples/peripheral/seed_identity.py ./samples/peripheral/
|
|
RUN python -c "from pathlib import Path; from zipfile import ZipFile; model_dir = Path('app/algorithms/pipe_health_prediction/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/pipe_health_prediction/model/my_survival_forest_model_quxi.zip
|
|
RUN mkdir -p db_inp temp data inp
|
|
|
|
# 设置 PYTHONPATH 以便 uvicorn 找到 app 模块
|
|
ENV PYTHONPATH=/app
|
|
|
|
FROM base AS test
|
|
COPY scripts ./scripts
|
|
COPY tests ./tests
|
|
RUN python -m compileall -q app && \
|
|
python -c "import app.main" && \
|
|
python scripts/check_openapi.py && \
|
|
pytest -q tests
|
|
|
|
FROM base AS runner
|
|
|
|
EXPOSE 8000
|
|
|
|
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000", "--workers", "4"]
|