From bd857ea5e1e70e13b5b60d7b21c91665f6d6be0e Mon Sep 17 00:00:00 2001 From: Jiang Date: Tue, 8 Sep 2026 18:26:20 +0800 Subject: [PATCH] fix(ci): test backend in container environment --- .gitea/workflows/package.yml | 6 +----- Dockerfile | 14 +++++++++++--- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/.gitea/workflows/package.yml b/.gitea/workflows/package.yml index f88d263..b0f35dd 100644 --- a/.gitea/workflows/package.yml +++ b/.gitea/workflows/package.yml @@ -13,11 +13,7 @@ jobs: image_name: gitea.waternetwork.cn/orgtjwater/tjwater-backend dockerfile: Dockerfile build_context: . - test_command: | - python -m compileall -q app - python -c "import app.main" - python scripts/check_openapi.py - pytest -q tests + test_target: test deploy_service: backend deploy_host: 192.168.1.114 secrets: diff --git a/Dockerfile b/Dockerfile index 7993cda..3717fdc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM condaforge/miniforge3:latest +FROM condaforge/miniforge3:latest AS base WORKDIR /app @@ -20,8 +20,6 @@ COPY app ./app COPY contracts ./contracts COPY infra ./infra COPY resources ./resources -COPY scripts/check_openapi.py ./scripts/check_openapi.py -COPY tests ./tests 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 @@ -29,6 +27,16 @@ 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"]