a-cloud-all/.devops/start.sh

69 lines
1.9 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# DevOps 监听器启动脚本
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
VENV_PATH="$SCRIPT_DIR/path/to/venv"
echo "=========================================="
echo "RuoYi-Cloud DevOps 自动化部署系统"
echo "=========================================="
# 检查 Python 环境
if ! command -v python3 &> /dev/null; then
echo "错误: 未找到 python3"
exit 1
fi
# 检测操作系统
OS_TYPE="$(uname -s)"
echo "检测到操作系统: $OS_TYPE"
# 如果是 macOS设置虚拟环境
if [[ "$OS_TYPE" == "Darwin" ]]; then
echo "macOS 系统,配置虚拟环境..."
# 检查虚拟环境是否存在
if [ ! -f "$VENV_PATH/bin/activate" ]; then
echo "虚拟环境不存在,创建虚拟环境: $VENV_PATH"
python3 -m venv "$VENV_PATH"
fi
# 激活虚拟环境
echo "激活虚拟环境: $VENV_PATH"
source "$VENV_PATH/bin/activate"
echo "✓ 虚拟环境已激活"
fi
# 检查依赖(如果在虚拟环境中,跳过系统级安装)
if [ -z "$VIRTUAL_ENV" ]; then
echo "检查 Python 依赖..."
if ! python3 -c "import yaml" 2>/dev/null; then
echo "警告: 未找到 PyYAML尝试安装..."
pip3 install --user PyYAML || echo "请手动安装: pip3 install --user PyYAML"
fi
if ! python3 -c "import flask" 2>/dev/null; then
echo "警告: 未找到 Flask尝试安装..."
pip3 install --user flask || echo "请手动安装: pip3 install --user flask"
fi
else
echo "检测到虚拟环境: $VIRTUAL_ENV"
if ! python3 -c "import yaml" 2>/dev/null; then
echo "安装 PyYAML..."
pip install PyYAML
fi
if ! python3 -c "import flask" 2>/dev/null; then
echo "安装 Flask..."
pip install flask
fi
fi
# 进入项目根目录
cd "$PROJECT_ROOT"
# 启动监听器
echo "启动 Git 监听器..."
python3 .devops/monitor.py "$@"