diff --git a/Dockerfile b/Dockerfile index bea8fce..92e46a7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM condaforge/miniforge3:latest +FROM condaforge/miniforge3:latest AS runtime-base WORKDIR /app @@ -14,9 +14,22 @@ 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 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 diff --git a/scripts/compile.py b/scripts/compile.py index 84339e8..b318e4d 100755 --- a/scripts/compile.py +++ b/scripts/compile.py @@ -212,10 +212,10 @@ if __name__ == "__main__": if len(sys.argv) > 1: if sys.argv[1] == "--clean": clean_mode = True - target_directories = sys.argv[2:] + target_directories = sys.argv[2:] or DEFAULT_TARGETS elif sys.argv[1] == "--delete-source": delete_source_mode = True - target_directories = sys.argv[2:] + target_directories = sys.argv[2:] or DEFAULT_TARGETS else: target_directories = sys.argv[1:] else: