deploy-offline.sh 4.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #!/usr/bin/env sh
  2. # Linux offline deployment using the extracted single release archive.
  3. set -eu
  4. if [ "${1:-}" = '--env-file-only' ]; then
  5. export DEPLOY_API_ENV_FILE_ONLY=1
  6. shift
  7. fi
  8. CALLER_DIR=$(pwd)
  9. case "$0" in
  10. */*) SCRIPT_DIR=${0%/*} ;;
  11. *) SCRIPT_DIR=. ;;
  12. esac
  13. REPO_ROOT=$(CDPATH= cd -- "$SCRIPT_DIR" && pwd)
  14. cd "$REPO_ROOT"
  15. ACTION=${1:-deploy}
  16. case "$ACTION" in
  17. help|-h|--help)
  18. echo 'Optional first argument: --env-file-only (QCC/DeepSeek and DMS connection settings from .env; direct process restart inherits; systemd needs unit configuration)'
  19. echo 'Example: sh deploy-offline.sh --env-file-only check-qcc "company full name"'
  20. echo 'Usage: sh deploy-offline.sh [deploy|import-knowledge|restart|start|stop|status|check-milvus|check-redis|check-dms|check-deepseek|check-qcc "company full name"|check "company full name"]'
  21. echo 'deploy: use the preinstalled .venv and packaged snapshot; never download'
  22. echo 'Usage: sh deploy-offline.sh import-knowledge [ZIP_PATH [DATABASE]]'
  23. echo 'Talent: sh deploy-offline.sh import-knowledge ZIP_PATH [DATABASE] --agent talent [--db-prefix talent_knowledge]'
  24. echo 'The agent selects a separate prepared directory and database prefix; mismatched packages are rejected.'
  25. echo 'import-knowledge: replace the full snapshot, or only the named library; preserve old versions'
  26. echo 'DATABASE: policy | finance | qa | article | service_guide | service_catalog'
  27. echo 'ZIP_PATH defaults to output/knowledge-snapshot.zip; relative paths use the caller directory'
  28. echo 'Configuration and prerequisites: docs/deployment.md'
  29. exit 0 ;;
  30. deploy|import-knowledge|restart|start|stop|status|serve|check|check-milvus|check-redis|check-dms|check-deepseek|check-qcc) ;;
  31. *) echo 'Unknown offline deployment action.' >&2; exit 2 ;;
  32. esac
  33. case "$ACTION" in
  34. check|check-qcc)
  35. [ "$#" -eq 2 ] && [ -n "$2" ] || { echo 'This check requires one exact company name.' >&2; exit 2; } ;;
  36. import-knowledge)
  37. # Preserve argument boundaries while resolving only the optional ZIP path.
  38. shift
  39. if [ "$#" -gt 0 ]; then
  40. case "$1" in --*) echo 'ZIP_PATH must precede target options.' >&2; exit 2 ;; esac
  41. [ -n "$1" ] || { echo 'ZIP_PATH must not be empty.' >&2; exit 2; }
  42. case "$1" in /*) KNOWLEDGE_ZIP=$1 ;; *) KNOWLEDGE_ZIP=$CALLER_DIR/$1 ;; esac
  43. shift
  44. set -- "$KNOWLEDGE_ZIP" "$@"
  45. fi
  46. # Validate before invoking Python (also works in offline shell probes).
  47. IMPORT_POSITION=0
  48. EXPECT_VALUE=''
  49. for IMPORT_ARG in "$@"; do
  50. IMPORT_POSITION=$((IMPORT_POSITION + 1))
  51. if [ "$IMPORT_POSITION" -eq 1 ]; then continue; fi
  52. if [ -n "$EXPECT_VALUE" ]; then
  53. case "$EXPECT_VALUE:$IMPORT_ARG" in
  54. agent:business|agent:talent) ;;
  55. prefix:*) case "$IMPORT_ARG" in ''|*[!A-Za-z0-9_]*|[!A-Za-z]*) echo 'Invalid database prefix.' >&2; exit 2 ;; esac ;;
  56. *) echo 'Invalid knowledge target.' >&2; exit 2 ;;
  57. esac
  58. EXPECT_VALUE=''
  59. else
  60. case "$IMPORT_ARG" in
  61. --agent) EXPECT_VALUE=agent ;;
  62. --db-prefix) EXPECT_VALUE=prefix ;;
  63. policy|finance|qa|article|service_guide|service_catalog)
  64. [ "$IMPORT_POSITION" -eq 2 ] || { echo 'Library must follow ZIP_PATH.' >&2; exit 2; } ;;
  65. *) echo 'Unknown knowledge import argument.' >&2; exit 2 ;;
  66. esac
  67. fi
  68. done
  69. [ -z "$EXPECT_VALUE" ] || { echo 'Missing knowledge target value.' >&2; exit 2; } ;;
  70. *) [ "$#" -le 1 ] || { echo 'Only one action is accepted.' >&2; exit 2; } ;;
  71. esac
  72. [ "$(uname -s)" = Linux ] || { echo 'deploy-offline.sh requires Linux.' >&2; exit 2; }
  73. export DEPLOY_OFFLINE=1 HF_HUB_OFFLINE=1 TRANSFORMERS_OFFLINE=1
  74. export EMBEDDING_MODEL_PATH="$REPO_ROOT/models/bge-large-zh-v1.5"
  75. SERVICE_PYTHON="$REPO_ROOT/.venv/bin/python"
  76. [ -x "$SERVICE_PYTHON" ] || { echo 'Offline deployment requires the preinstalled .venv/bin/python.' >&2; exit 1; }
  77. case "$ACTION" in
  78. check|check-qcc) exec "$SERVICE_PYTHON" scripts/deploy.py "$ACTION" "$2" ;;
  79. import-knowledge)
  80. exec "$SERVICE_PYTHON" scripts/deploy.py "$ACTION" "$@" ;;
  81. esac
  82. exec "$SERVICE_PYTHON" scripts/deploy.py "$ACTION"