a-cloud-all/.devops/scripts/init/nacos.py

56 lines
1.3 KiB
Python
Raw Normal View History

2026-01-10 15:15:45 +08:00
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Nacos 初始化模块
"""
import subprocess
from pathlib import Path
import sys
# 添加父目录到路径
sys.path.insert(0, str(Path(__file__).parent.parent))
from log import Logger
def init_nacos(project_root):
"""
初始化 Nacos
参数
project_root: 项目根目录
返回
bool: 成功返回 True失败返回 False
"""
try:
project_root = Path(project_root).resolve()
Logger.separator()
Logger.info("开始初始化 Nacos")
Logger.separator()
Logger.info(f"项目根目录: {project_root}")
docker_dir = project_root / "docker"
# 构建并启动 Nacos 容器
Logger.info(f"执行目录: {docker_dir}")
2026-01-10 15:21:06 +08:00
if not Logger.run_command("docker-compose build --no-cache ruoyi-nacos", docker_dir):
2026-01-10 15:15:45 +08:00
Logger.error("Nacos 镜像构建失败")
return False
Logger.info("Nacos 镜像构建成功")
2026-01-10 15:21:06 +08:00
if not Logger.run_command("docker-compose up -d ruoyi-nacos", docker_dir):
2026-01-10 15:15:45 +08:00
Logger.error("Nacos 容器启动失败")
return False
Logger.info("Nacos 容器启动成功")
Logger.info("Nacos 初始化完成")
return True
except Exception as e:
Logger.error(f"Nacos 初始化异常: {e}")
return False