From 05c670a173d25d90e9d1f06f31e059f872a1d023 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E5=B0=8F=E4=BA=91?= Date: Sat, 31 Jan 2026 14:55:24 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0python=E6=9E=84=E5=BB=BA?= =?UTF-8?q?=E7=9A=84=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .devops/config.yaml | 11 +++++++++ .devops/monitor.py | 56 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) diff --git a/.devops/config.yaml b/.devops/config.yaml index 70d28a3..defd8da 100644 --- a/.devops/config.yaml +++ b/.devops/config.yaml @@ -260,3 +260,14 @@ repositories: artifact_path: dist docker_path: docker/wvp/web/html/dist docker_service: wvp-web + + # HYF 后端服务 + - name: hyf-backend + url: http://th.local.t-aaron.com:13000/THENG/hyf-backend.git + path: hyf-backend + type: python + build_commands: [] # Python 项目不需要构建,直接复制源码 + artifact_path: . # 复制整个项目目录 + docker_path: docker/hyf_backend/src + docker_service: hyf-backend + docker_build: true # 需要重新构建镜像 diff --git a/.devops/monitor.py b/.devops/monitor.py index 3ba59a6..0727ee2 100644 --- a/.devops/monitor.py +++ b/.devops/monitor.py @@ -513,6 +513,62 @@ class GitMonitor: ) return False + elif repo_config['type'] == 'python': + # Python 项目 - 直接复制源码到 docker 目录 + Logger.separator() + Logger.info("开始 Python 项目部署") + Logger.separator() + + source_path = repo_path / repo_config['path'] + target_dir = repo_path / repo_config['docker_path'] + + Logger.info(f"源码目录: {source_path}") + Logger.info(f"目标目录: {target_dir}") + + try: + # 清空目标目录(保留 .gitkeep 等隐藏文件) + if target_dir.exists(): + import shutil + for item in target_dir.iterdir(): + if not item.name.startswith('.'): + if item.is_dir(): + shutil.rmtree(item) + else: + item.unlink() + Logger.info("清空目标目录完成") + else: + target_dir.mkdir(parents=True, exist_ok=True) + Logger.info("创建目标目录完成") + + # 复制源码到目标目录 + import shutil + for item in source_path.iterdir(): + if item.name in ['.git', '__pycache__', '.pytest_cache', '.venv', 'venv']: + continue # 跳过不需要的目录 + + target_item = target_dir / item.name + if item.is_dir(): + if target_item.exists(): + shutil.rmtree(target_item) + shutil.copytree(item, target_item) + else: + shutil.copy2(item, target_item) + + Logger.info("源码复制完成") + + except Exception as e: + error_msg = f"Python 项目源码复制失败: {str(e)}" + Logger.error(error_msg) + if self.dingtalk_notifier: + duration = time.time() - start_time + self.dingtalk_notifier.send_build_failure( + repo_name=repo_name, + branch=self.global_branch, + commit_hash=commit_hash, + error_msg=error_msg + ) + return False + # 4. Docker 部署 compose_dir = repo_path / 'docker' service_name = repo_config['docker_service']