deploy.sh 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #!/usr/bin/env sh
  2. # Linux deployment. No .env sourcing; all commands run from this checkout.
  3. set -eu
  4. if [ "${1:-}" = '--env-file-only' ]; then
  5. export DEPLOY_API_ENV_FILE_ONLY=1
  6. shift
  7. fi
  8. case "$0" in
  9. */*) SCRIPT_DIR=${0%/*} ;;
  10. *) SCRIPT_DIR=. ;;
  11. esac
  12. REPO_ROOT=$(CDPATH= cd -- "$SCRIPT_DIR" && pwd)
  13. cd "$REPO_ROOT"
  14. ACTION=${1:-deploy}
  15. case "$ACTION" in
  16. help|-h|--help)
  17. echo 'Optional first argument: --env-file-only (QCC/DeepSeek and DMS connection settings from .env; direct process restart inherits; systemd needs unit configuration)'
  18. echo 'Usage: sh deploy.sh [deploy|update-knowledge|restart|start|stop|status|check "company full name"|check-milvus|check-redis|check-dms|check-deepseek|check-qcc "company full name"]'
  19. echo 'deploy: install uv/Python/dependencies/models; initialize missing knowledge; restart API'
  20. echo 'update-knowledge: prepare/verify with old API running; then stop, publish and start'
  21. echo 'restart: sync isolated dependencies; stop this checkout API and start new code'
  22. echo 'check: run all five diagnostics; check-milvus/redis/dms/deepseek/qcc: run only one'
  23. echo 'Configuration and operational details: docs/deployment.md'
  24. exit 0 ;;
  25. deploy|update-knowledge|restart|start|stop|status|serve|check|check-milvus|check-redis|check-dms|check-deepseek|check-qcc) ;;
  26. *) echo 'Unknown deployment action. Run sh deploy.sh help.' >&2; exit 2 ;;
  27. esac
  28. case "$ACTION" in
  29. check|check-qcc)
  30. [ "$#" -eq 2 ] && [ -n "$2" ] || { echo 'This check requires one exact company name.' >&2; exit 2; } ;;
  31. *) [ "$#" -le 1 ] || { echo 'Only one action is accepted.' >&2; exit 2; } ;;
  32. esac
  33. [ "$(uname -s)" = Linux ] || { echo 'deploy.sh requires Linux with /proc.' >&2; exit 2; }
  34. export UV_CACHE_DIR="${UV_CACHE_DIR:-$REPO_ROOT/.uv-cache}"
  35. case "$ACTION" in
  36. start|stop|status|serve|check|check-milvus|check-redis|check-dms|check-deepseek|check-qcc)
  37. SERVICE_PYTHON="$REPO_ROOT/.venv/bin/python"
  38. if [ -f output/deploy/python-path ]; then
  39. IFS= read -r SERVICE_PYTHON < output/deploy/python-path
  40. fi
  41. [ -x "$SERVICE_PYTHON" ] || { echo 'Run sh deploy.sh deploy first.' >&2; exit 1; }
  42. case "$ACTION" in
  43. check|check-qcc) exec "$SERVICE_PYTHON" scripts/deploy.py "$ACTION" "$2" ;;
  44. esac
  45. exec "$SERVICE_PYTHON" scripts/deploy.py "$ACTION" ;;
  46. esac
  47. export PATH="$HOME/.local/bin:$PATH"
  48. unset DEPLOY_OFFLINE UV_OFFLINE
  49. if ! command -v uv >/dev/null 2>&1; then
  50. [ "${AUTO_INSTALL_UV:-1}" = 1 ] || { echo 'uv missing; AUTO_INSTALL_UV=0.' >&2; exit 1; }
  51. installer=$(mktemp)
  52. trap 'rm -f "$installer"' EXIT HUP INT TERM
  53. if command -v curl >/dev/null 2>&1; then
  54. curl --fail --location --silent --show-error https://astral.sh/uv/install.sh -o "$installer"
  55. else
  56. wget -q https://astral.sh/uv/install.sh -O "$installer"
  57. fi
  58. UV_NO_MODIFY_PATH=1 sh "$installer"
  59. rm -f "$installer"
  60. trap - EXIT HUP INT TERM
  61. fi
  62. command -v uv >/dev/null 2>&1 || { echo 'uv installation failed.' >&2; exit 1; }
  63. PYTHON_VERSION=$(tr -d '\r\n' < .python-version)
  64. uv python install "$PYTHON_VERSION"
  65. DEPLOY_PYTHON=$(uv python find --managed-python "$PYTHON_VERSION")
  66. # The controller is outside service environments; each sync builds a new environment.
  67. exec "$DEPLOY_PYTHON" scripts/deploy.py "$ACTION"