修改 thingsboard 部署
This commit is contained in:
parent
c5c65c2a46
commit
a0fe9edf59
|
|
@ -51,10 +51,16 @@ infrastructure:
|
|||
|
||||
- name: wvp-pro
|
||||
docker_service: wvp-pro
|
||||
pre_deploy_commands:
|
||||
- cd wvpjar && mvn clean package -DskipTests
|
||||
- cp wvpjar/target/wvp-pro-*.jar docker/wvp/wvpjar/jar/
|
||||
wait_time: 30 # WVP 后端需要等待 MySQL、Redis 和 zlmediakit
|
||||
|
||||
- name: wvp-web
|
||||
docker_service: wvp-web
|
||||
pre_deploy_commands:
|
||||
- cd wvpweb && npm install && npm run build:prod
|
||||
- cp -r wvpweb/dist docker/wvp/web/html/
|
||||
wait_time: 10 # Nginx 启动较快
|
||||
|
||||
- name: thingsboard-ce
|
||||
|
|
|
|||
|
|
@ -179,50 +179,85 @@ class GitMonitor:
|
|||
return True
|
||||
|
||||
def init_infrastructure(self):
|
||||
"""初始化基础设施(MySQL、Redis、Nacos)"""
|
||||
"""初始化基础设施服务(动态读取配置)"""
|
||||
repo_path = self.runtime_path / 'a-cloud-all'
|
||||
|
||||
# 检查是否已初始化
|
||||
mysql_flag = repo_path / '.devops' / '.deployed_mysql'
|
||||
redis_flag = repo_path / '.devops' / '.deployed_redis'
|
||||
nacos_flag = repo_path / '.devops' / '.deployed_nacos'
|
||||
|
||||
# 初始化 MySQL
|
||||
if not mysql_flag.exists():
|
||||
Logger.info("初始化 MySQL...")
|
||||
# 从配置文件中获取 MySQL 的预部署命令
|
||||
# 从配置文件读取基础设施列表
|
||||
infra_config = self.config.get('infrastructure', [])
|
||||
mysql_config = next((item for item in infra_config if item['name'] == 'ruoyi-mysql'), None)
|
||||
pre_deploy_commands = mysql_config.get('pre_deploy_commands', []) if mysql_config else []
|
||||
|
||||
if mysql.init_mysql(repo_path, pre_deploy_commands):
|
||||
mysql_flag.parent.mkdir(parents=True, exist_ok=True)
|
||||
mysql_flag.touch()
|
||||
Logger.info("等待 MySQL 启动(30秒)...")
|
||||
time.sleep(30)
|
||||
else:
|
||||
for infra in infra_config:
|
||||
service_name = infra['name']
|
||||
docker_service = infra['docker_service']
|
||||
wait_time = infra.get('wait_time', 10)
|
||||
|
||||
# 检查是否已初始化
|
||||
flag_file = repo_path / '.devops' / f'.deployed_{service_name}'
|
||||
|
||||
if not flag_file.exists():
|
||||
Logger.info(f"初始化 {service_name}...")
|
||||
|
||||
# 执行预部署命令(如果有)
|
||||
pre_deploy_commands = infra.get('pre_deploy_commands', [])
|
||||
if pre_deploy_commands:
|
||||
Logger.info(f"执行 {service_name} 预部署命令...")
|
||||
for cmd in pre_deploy_commands:
|
||||
Logger.info(f"执行命令: {cmd}")
|
||||
result = subprocess.run(
|
||||
cmd,
|
||||
shell=True,
|
||||
cwd=repo_path,
|
||||
capture_output=True,
|
||||
text=True
|
||||
)
|
||||
if result.returncode != 0:
|
||||
Logger.error(f"预部署命令执行失败: {result.stderr}")
|
||||
return False
|
||||
|
||||
# 初始化 Redis
|
||||
if not redis_flag.exists():
|
||||
Logger.info("初始化 Redis...")
|
||||
if redis.init_redis(repo_path):
|
||||
redis_flag.touch()
|
||||
Logger.info("等待 Redis 启动(10秒)...")
|
||||
time.sleep(10)
|
||||
else:
|
||||
# 构建并启动服务
|
||||
docker_dir = repo_path / 'docker'
|
||||
|
||||
# 构建镜像
|
||||
Logger.info(f"构建 {service_name} 镜像...")
|
||||
build_cmd = f"docker-compose build --no-cache {docker_service}"
|
||||
result = subprocess.run(
|
||||
build_cmd,
|
||||
shell=True,
|
||||
cwd=docker_dir,
|
||||
capture_output=True,
|
||||
text=True
|
||||
)
|
||||
|
||||
if result.returncode != 0:
|
||||
Logger.error(f"{service_name} 镜像构建失败: {result.stderr}")
|
||||
return False
|
||||
|
||||
# 初始化 Nacos
|
||||
if not nacos_flag.exists():
|
||||
Logger.info("初始化 Nacos...")
|
||||
if nacos.init_nacos(repo_path):
|
||||
nacos_flag.touch()
|
||||
Logger.info("等待 Nacos 启动(20秒)...")
|
||||
time.sleep(20)
|
||||
else:
|
||||
Logger.info(f"{service_name} 镜像构建成功")
|
||||
|
||||
# 启动容器
|
||||
Logger.info(f"启动 {service_name} 容器...")
|
||||
up_cmd = f"docker-compose up -d {docker_service}"
|
||||
result = subprocess.run(
|
||||
up_cmd,
|
||||
shell=True,
|
||||
cwd=docker_dir,
|
||||
capture_output=True,
|
||||
text=True
|
||||
)
|
||||
|
||||
if result.returncode != 0:
|
||||
Logger.error(f"{service_name} 容器启动失败: {result.stderr}")
|
||||
return False
|
||||
|
||||
Logger.info(f"{service_name} 容器启动成功")
|
||||
|
||||
# 创建标记文件
|
||||
flag_file.parent.mkdir(parents=True, exist_ok=True)
|
||||
flag_file.touch()
|
||||
|
||||
# 等待服务启动
|
||||
Logger.info(f"等待 {service_name} 启动({wait_time}秒)...")
|
||||
time.sleep(wait_time)
|
||||
|
||||
return True
|
||||
|
||||
def deploy(self, repo_config):
|
||||
|
|
|
|||
Loading…
Reference in New Issue