添加python构建的支持
This commit is contained in:
parent
22b37720ca
commit
05c670a173
|
|
@ -260,3 +260,14 @@ repositories:
|
||||||
artifact_path: dist
|
artifact_path: dist
|
||||||
docker_path: docker/wvp/web/html/dist
|
docker_path: docker/wvp/web/html/dist
|
||||||
docker_service: wvp-web
|
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 # 需要重新构建镜像
|
||||||
|
|
|
||||||
|
|
@ -513,6 +513,62 @@ class GitMonitor:
|
||||||
)
|
)
|
||||||
return False
|
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 部署
|
# 4. Docker 部署
|
||||||
compose_dir = repo_path / 'docker'
|
compose_dir = repo_path / 'docker'
|
||||||
service_name = repo_config['docker_service']
|
service_name = repo_config['docker_service']
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue