diff --git a/.devops/__pycache__/deployer.cpython-313.pyc b/.devops/__pycache__/deployer.cpython-313.pyc new file mode 100644 index 0000000..d1d837a Binary files /dev/null and b/.devops/__pycache__/deployer.cpython-313.pyc differ diff --git a/.devops/config.yaml b/.devops/config.yaml index 599fe29..b8200eb 100644 --- a/.devops/config.yaml +++ b/.devops/config.yaml @@ -1,5 +1,8 @@ # DevOps 自动化部署配置文件 +# 全局分支配置(所有仓库统一使用此分支) +global_branch: main + # Git 仓库配置 repositories: # 认证服务 @@ -199,8 +202,6 @@ monitor: # 部署配置 deploy: docker_compose_path: ./docker/docker-compose.yml - auto_commit: true # 是否自动提交子模块更新到主仓库 - commit_message: "自动更新子模块: {repo_name} 到最新版本" # 日志配置 logging: diff --git a/.devops/deployer.py b/.devops/deployer.py index bf40d49..538e3c5 100644 --- a/.devops/deployer.py +++ b/.devops/deployer.py @@ -33,10 +33,14 @@ class Deployer: self.runtime_path = Path(runtime_path) self.main_repo_url = config['main_repository']['url'] - self.main_repo_branch = config['main_repository']['branch'] + + # 使用全局分支配置 + self.global_branch = config.get('global_branch', 'main') + self.main_repo_branch = self.global_branch self.logger.info(f"项目根目录: {project_root}") self.logger.info(f"Runtime 目录: {self.runtime_path}") + self.logger.info(f"全局分支: {self.global_branch}") def run_command(self, cmd, cwd=None, timeout=600): """执行命令""" @@ -109,20 +113,17 @@ class Deployer: else: self.logger.info("主仓库已存在,更新代码...") - # 切换到指定分支 + # 切换到配置的主分支 + self.logger.info(f"切换到主分支: {self.main_repo_branch}") if not self.run_command(f"git checkout {self.main_repo_branch}", cwd=repo_path): return False - # 拉取最新代码 + # 拉取主仓库最新代码 + self.logger.info("拉取主仓库最新代码...") if not self.run_command("git pull", cwd=repo_path): return False - # 初始化子模块(如果还没初始化) - if not self.run_command("git submodule update --init --recursive", cwd=repo_path): - return False - - # 更新所有子模块到各自配置的分支 - self.logger.info("更新所有子模块到最新代码...") + # 更新所有子模块到全局配置的分支 if not self.update_all_submodules(repo_path): return False @@ -131,38 +132,14 @@ class Deployer: return True def update_all_submodules(self, repo_path): - """更新所有子模块到各自配置的分支""" - self.logger.info("更新所有子模块到各自配置的分支...") + """更新所有子模块到全局配置的分支""" + self.logger.info(f"更新所有子模块到分支: {self.global_branch}") - # 构建分支映射:子模块路径 -> 分支名 - # 注意:这里假设所有子模块使用相同的分支,如果需要不同分支,需要逐个处理 - # 先尝试使用 git submodule foreach 批量更新 - - # 检查是否所有子模块使用相同的分支 - branches = set(repo['branch'] for repo in self.config['repositories']) - - if len(branches) == 1: - # 所有子模块使用相同分支,可以使用 foreach - branch = branches.pop() - self.logger.info(f"所有子模块使用相同分支 {branch},使用 git submodule foreach 批量更新") - cmd = f"git submodule foreach 'git checkout {branch} && git pull origin {branch}'" - if not self.run_command(cmd, cwd=repo_path, timeout=600): - self.logger.warning("批量更新子模块失败") - return False - else: - # 不同子模块使用不同分支,需要逐个更新 - self.logger.info("子模块使用不同分支,逐个更新...") - for repo_config in self.config['repositories']: - branch = repo_config['branch'] - submodule_path = repo_config['path'] - - self.logger.info(f"更新子模块 {repo_config['name']} 到分支 {branch}") - - # 构建命令:进入子模块,切换分支并拉取 - cmd = f"cd {submodule_path} && git checkout {branch} && git pull origin {branch}" - if not self.run_command(cmd, cwd=repo_path, timeout=300): - self.logger.warning(f"子模块 {repo_config['name']} 更新失败,继续处理其他子模块") - continue + # 使用 git submodule foreach 批量更新所有子模块到全局分支 + cmd = f"git submodule foreach 'git checkout {self.global_branch} && git pull'" + if not self.run_command(cmd, cwd=repo_path, timeout=600): + self.logger.warning("批量更新子模块失败") + return False return True @@ -178,13 +155,12 @@ class Deployer: self.logger.error(f"子模块目录不存在: {submodule_path}") return False - # 切换到指定分支 - branch = repo_config['branch'] - if not self.run_command(f"git checkout {branch}", cwd=submodule_path): + # 切换到全局配置的分支 + if not self.run_command(f"git checkout {self.global_branch}", cwd=submodule_path): return False # 拉取最新代码 - if not self.run_command("git pull origin " + branch, cwd=submodule_path): + if not self.run_command(f"git pull origin {self.global_branch}", cwd=submodule_path): return False self.logger.info(f"子模块更新成功: {repo_config['name']}") diff --git a/.devops/monitor.py b/.devops/monitor.py index 2d3019b..62904bc 100644 --- a/.devops/monitor.py +++ b/.devops/monitor.py @@ -31,7 +31,11 @@ class GitMonitor: self.deployer = Deployer(self.config) self.last_commits = {} # 存储每个仓库的最后一次提交 hash + # 读取全局分支配置 + self.global_branch = self.config.get('global_branch', 'main') + self.logger.info("Git 监听器初始化完成") + self.logger.info(f"监听分支: {self.global_branch}") def _load_config(self): """加载配置文件""" @@ -91,12 +95,11 @@ class GitMonitor: """检查单个仓库是否有新提交""" repo_name = repo_config['name'] repo_url = repo_config['url'] - branch = repo_config['branch'] - self.logger.debug(f"检查仓库: {repo_name}") + self.logger.debug(f"检查仓库: {repo_name} (分支: {self.global_branch})") - # 获取最新提交 - current_commit = self.get_remote_commit(repo_url, branch) + # 获取最新提交(使用全局分支配置) + current_commit = self.get_remote_commit(repo_url, self.global_branch) if not current_commit: self.logger.warning(f"无法获取 {repo_name} 的最新提交") return False diff --git a/ruoyi-gateway b/ruoyi-gateway index 1ea1bbe..d735138 160000 --- a/ruoyi-gateway +++ b/ruoyi-gateway @@ -1 +1 @@ -Subproject commit 1ea1bbeb8f30d6ca34fcb8bb6cfd9b375714aa64 +Subproject commit d735138af013a4771b120712b975d61fafcc1899