Commit 19d52cf1 authored by 金凯强's avatar 金凯强 🎨

测试

parent 82a0a5c4
......@@ -33,51 +33,51 @@ class UpgradeService():
sql = f'''select * from app_upgrade_log_dtl where log_id={log_id}'''
image_info_list = session.query_sql(sql)
# 找出升级版本号
upgrade_no = data.get('upgrade_no')
# 找到这个版本备份的compose文件
docker_compose_file_dir = self.find_compose_by_upgrade_no(upgrade_no)
# 挨个去找对应版本中的镜像然后逐一tag
for image_info in image_info_list:
app_image_id = image_info['app_image_id']
app_image_name = image_info['app_image_name']
# 系统中找镜像,如果镜像是None,重新tag,如果不是None,就不用处理了
find_image_command = "docker images |grep " + app_image_id[:12] + " | awk '{print $2}'"
with os.popen(find_image_command) as command:
actual_image_verison = command.read()
if not actual_image_verison:
raise HSException(f'找不到对应的{app_image_id}的镜像')
logger.info(f'镜像{app_image_id}的镜像版本号为{actual_image_verison}')
# tag它
if actual_image_verison == '<none>':
logger.info(f'tag镜像{app_image_id}为{app_image_name}')
res = os.system(f'docker tag {app_image_id[:12]} {app_image_name}')
if res == 1: raise HSException(f'Tag{app_image_name}镜像失败')
else:
# 有版本就不管
pass
# 找到app_list
app_list = self.get_app_list_from_compose_file(docker_compose_file_dir)
# docker-compose
project_info = ConnectionService().get_project_info()
host_ip = project_info['host_ip']
ssh_conenct = SSHConnect(user_name='root', password='huansi.net', host_port='1111', host_ip=host_ip)
with ssh_conenct as ssh:
out, err = ssh.exec_command(
f'''export HUANSI_REGISTRY_URL=47.110.145.204:8084 &&\
# 找出升级版本号
upgrade_no = data.get('')
# 找到这个版本备份的compose文件
docker_compose_file_dir = self.find_compose_by_upgrade_no(upgrade_no)
# 挨个去找对应版本中的镜像然后逐一tag
for image_info in image_info_list:
app_image_id = image_info['app_image_id']
app_image_name = image_info['app_image_name']
# 系统中找镜像,如果镜像是None,重新tag,如果不是None,就不用处理了
find_image_command = "docker images |grep " + app_image_id[:12] + " | awk '{print $2}'"
with os.popen(find_image_command) as command:
actual_image_verison = command.read()
if not actual_image_verison:
raise HSException(f'找不到对应的{app_image_id}的镜像')
logger.info(f'镜像{app_image_id}的镜像版本号为{actual_image_verison}')
# tag它
if actual_image_verison == '<none>':
logger.info(f'tag镜像{app_image_id}为{app_image_name}')
res = os.system(f'docker tag {app_image_id[:12]} {app_image_name}')
if res == 1: raise HSException(f'Tag{app_image_name}镜像失败')
else:
# 有版本就不管
pass
# 找到app_list
app_list = self.get_app_list_from_compose_file(docker_compose_file_dir)
# docker-compose
project_info = ConnectionService().get_project_info()
host_ip = project_info['host_ip']
ssh_conenct = SSHConnect(user_name='root', password='huansi.net', host_port='1111', host_ip=host_ip)
with ssh_conenct as ssh:
out, err = ssh.exec_command(
f'''export HUANSI_REGISTRY_URL=47.110.145.204:8084 &&\
source /etc/profile.d/huansi.sh &&\
docker-compose -f /data/upgrade_tools_data/backup/{upgrade_no}/docker-compose.yml -p deploy up -d --force-recreate --no-deps {app_list}''')
# 会有问题,docker-compose编译的时候,会把过程放到err上,所以注释这段
# if err:
# raise HSException(f'回滚失败:{err}')
if err:
logger.info(f"有报错信息:{err}")
logger.info(f'回滚{app_list}成功:{out}')
# 会有问题,docker-compose编译的时候,会把过程放到err上,所以注释这段
# if err:
# raise HSException(f'回滚失败:{err}')
if err:
logger.info(f"有报错信息:{err}")
logger.info(f'回滚{app_list}成功:{out}')
with db_driver as session:
# 对应的版本信息修改为当前版本
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment