Add runtime environment readiness checks

This commit is contained in:
2026-06-30 14:28:49 +08:00
parent 442b521705
commit d9ea249ff0
12 changed files with 603 additions and 18 deletions

58
scripts/bootstrap_conda_envs.sh Executable file
View File

@@ -0,0 +1,58 @@
#!/usr/bin/env bash
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
TASK_ENV="${SEG_TASK_CONDA_ENV:-seg_smp}"
MMSEG_ENV="${SEG_MMSEG_CONDA_ENV:-seg_mmcv}"
env_exists() {
conda env list | awk '{print $1}' | grep -Fxq "$1"
}
create_task_env() {
if ! env_exists "${TASK_ENV}"; then
conda create -n "${TASK_ENV}" python=3.11 -y
fi
conda run -n "${TASK_ENV}" python -m pip install -U pip
conda run -n "${TASK_ENV}" python -m pip install -r "${ROOT_DIR}/backend/requirements.txt"
conda run -n "${TASK_ENV}" python -m pip install \
torch==2.6.0 torchvision==0.21.0 \
'numpy<2' 'opencv-python<4.12' albumentations segmentation-models-pytorch ultralytics \
mmengine mmsegmentation==1.2.2 mmcv-lite \
matplotlib pandas scikit-learn scipy seaborn tqdm tensorboard
}
create_mmseg_env() {
if ! env_exists "${MMSEG_ENV}"; then
conda create -n "${MMSEG_ENV}" python=3.10 -y
fi
conda run -n "${MMSEG_ENV}" python -m pip install -U pip
conda run -n "${MMSEG_ENV}" python -m pip install \
torch==2.1.2 torchvision==0.16.2 \
--index-url https://download.pytorch.org/whl/cu121
conda run -n "${MMSEG_ENV}" python -m pip install \
mmengine==0.10.7 mmsegmentation==1.2.2 'mmcv==2.1.0' \
-f https://download.openmmlab.com/mmcv/dist/cu121/torch2.1/index.html
conda run -n "${MMSEG_ENV}" python -m pip install \
'numpy<2' 'opencv-python<4.12' ftfy regex matplotlib pandas scikit-learn scipy seaborn tqdm tensorboard
}
case "${1:-all}" in
all)
create_task_env
create_mmseg_env
PYTHONPATH="${ROOT_DIR}/backend" conda run -n "${TASK_ENV}" python "${ROOT_DIR}/scripts/verify_runtime_envs.py" --refresh
;;
task)
create_task_env
echo "Created or repaired ${TASK_ENV}. Run '$0 all' for full runtime verification."
;;
mmseg)
create_mmseg_env
echo "Created or repaired ${MMSEG_ENV}. Run '$0 all' for full runtime verification."
;;
*)
echo "usage: $0 [all|task|mmseg]" >&2
exit 2
;;
esac

27
scripts/verify_runtime_envs.py Executable file
View File

@@ -0,0 +1,27 @@
#!/usr/bin/env python3
from __future__ import annotations
import argparse
import json
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(ROOT / "backend"))
from app.modules.system.service import get_runtime_readiness # noqa: E402
def main() -> None:
parser = argparse.ArgumentParser(description="Verify Seg Data Server runtime conda environments.")
parser.add_argument("--refresh", action="store_true", help="ignore the backend readiness cache")
args = parser.parse_args()
report = get_runtime_readiness(force=args.refresh)
print(json.dumps(report, ensure_ascii=False, indent=2))
if not report.get("passed"):
raise SystemExit(1)
if __name__ == "__main__":
main()