fix(ci): test backend in container environment
Generic Container CI/CD / test-build-publish (push) Successful in 1m11s
Server CI/CD v2 / build-test-publish-and-deploy (push) Successful in 1m11s

This commit is contained in:
2026-09-08 18:26:20 +08:00
parent 8942541759
commit bd857ea5e1
2 changed files with 12 additions and 8 deletions
+1 -5
View File
@@ -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:
+11 -3
View File
@@ -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"]