11#! /usr/bin/env bash
22set -euo pipefail
33
4- APP_ROOT=" /root/cross-subject-knowledge"
4+ SOURCE_ROOT=" $( cd " $( dirname " $0 " ) /.." && pwd) "
5+ RUNTIME_ROOT=" ${RUNTIME_ROOT:-/ root/ cross-subject-knowledge} "
56CONTAINER_NAME=" textbook-knowledge"
67REPO_NAME=" textbook-knowledge"
78EMBEDDER_NAME=" ${EMBEDDER_NAME:- BAAI/ bge-m3} "
89
9- cd " $APP_ROOT "
10+ cd " $SOURCE_ROOT "
1011
1112mkdir -p \
12- data/index \
13- state/logs \
14- state/cache/huggingface \
15- state/cache/sentence_transformers \
16- state/tmp \
17- state/batch
18-
19- if [ ! -f data/index/textbook_mineru_fts.db ]; then
20- echo " ERROR: missing runtime DB data/index/textbook_mineru_fts.db"
13+ " ${RUNTIME_ROOT} / data/index" \
14+ " ${RUNTIME_ROOT} / state/logs" \
15+ " ${RUNTIME_ROOT} / state/cache/huggingface" \
16+ " ${RUNTIME_ROOT} / state/cache/sentence_transformers" \
17+ " ${RUNTIME_ROOT} / state/tmp" \
18+ " ${RUNTIME_ROOT} / state/batch"
19+
20+ if [ ! -f " ${RUNTIME_ROOT} / data/index/textbook_mineru_fts.db" ]; then
21+ echo " ERROR: missing runtime DB ${RUNTIME_ROOT} / data/index/textbook_mineru_fts.db"
2122 exit 1
2223fi
2324
24- if [ ! -f data/index/textbook_chunks.index ]; then
25- echo " ERROR: missing runtime FAISS index data/index/textbook_chunks.index"
25+ if [ ! -f " ${RUNTIME_ROOT} / data/index/textbook_chunks.index" ]; then
26+ echo " ERROR: missing runtime FAISS index ${RUNTIME_ROOT} / data/index/textbook_chunks.index"
2627 exit 1
2728fi
2829
@@ -33,7 +34,7 @@ backup_tag="${REPO_NAME}:pre-${build_stamp}"
3334rollback_image=" "
3435
3536host_cache_has_model () {
36- find " ${APP_ROOT } /state/cache/huggingface" -type f | grep -q .
37+ find " ${RUNTIME_ROOT } /state/cache/huggingface" -type f | grep -q .
3738}
3839
3940echo " === deploy start $( date -u ' +%Y-%m-%d %H:%M:%S UTC' ) commit=${commit_sha} ==="
@@ -53,7 +54,7 @@ docker build --pull -t "${build_tag}" -t "${REPO_NAME}:latest" .
5354if ! host_cache_has_model; then
5455 echo " === bootstrapping host model cache ==="
5556 if docker ps -a --format ' {{.Names}}' | grep -qx " ${CONTAINER_NAME} " ; then
56- docker cp " ${CONTAINER_NAME} :/root/.cache/huggingface/." " ${APP_ROOT } /state/cache/huggingface/" > /dev/null 2>&1 || true
57+ docker cp " ${CONTAINER_NAME} :/root/.cache/huggingface/." " ${RUNTIME_ROOT } /state/cache/huggingface/" > /dev/null 2>&1 || true
5758 fi
5859fi
5960
@@ -63,7 +64,7 @@ if ! host_cache_has_model; then
6364 -e HF_HOME=/state/cache/huggingface \
6465 -e SENTENCE_TRANSFORMERS_HOME=/state/cache/sentence_transformers \
6566 -e TRANSFORMERS_CACHE=/state/cache/huggingface/transformers \
66- -v " ${APP_ROOT } /state:/state" \
67+ -v " ${RUNTIME_ROOT } /state:/state" \
6768 " ${build_tag} " \
6869 python -c " from sentence_transformers import SentenceTransformer; SentenceTransformer('${EMBEDDER_NAME} ')"
6970fi
@@ -81,8 +82,8 @@ docker run -d \
8182 -e HF_HOME=/state/cache/huggingface \
8283 -e SENTENCE_TRANSFORMERS_HOME=/state/cache/sentence_transformers \
8384 -e TRANSFORMERS_CACHE=/state/cache/huggingface/transformers \
84- -v " ${APP_ROOT } /data:/data" \
85- -v " ${APP_ROOT } /state:/state" \
85+ -v " ${RUNTIME_ROOT } /data:/data" \
86+ -v " ${RUNTIME_ROOT } /state:/state" \
8687 " ${build_tag} " > /dev/null
8788
8889healthy=" false"
@@ -114,8 +115,8 @@ if [ "${healthy}" != "true" ]; then
114115 -e HF_HOME=/state/cache/huggingface \
115116 -e SENTENCE_TRANSFORMERS_HOME=/state/cache/sentence_transformers \
116117 -e TRANSFORMERS_CACHE=/state/cache/huggingface/transformers \
117- -v " ${APP_ROOT } /data:/data" \
118- -v " ${APP_ROOT } /state:/state" \
118+ -v " ${RUNTIME_ROOT } /data:/data" \
119+ -v " ${RUNTIME_ROOT } /state:/state" \
119120 " ${rollback_image} " > /dev/null
120121 fi
121122 exit 1
0 commit comments