Commit 5a4d9590 authored by 金凯强's avatar 金凯强 🎨

修复一些bug

parent b5d5d2cf
# -*- coding:utf-8 -*-
import os
import time
from huansi_utils.exception.exception import HSException
from huansi_utils.server.service_uc import HSBaseUCService
......@@ -28,6 +29,7 @@ class InstallService(HSBaseUCService):
:param HSCUSCODE:
:return:
'''
time.sleep(15)
self.delete_setting_file()
s1 = os.system("docker run --rm -t -i -v /etc/gitlab-runner:/etc/gitlab-runner gitlab/gitlab-runner register \
-n -u http://47.110.145.204:8085/ -r WwpzH4qk19KjvAjEwoTz --executor docker --docker-image docker \
......@@ -38,9 +40,10 @@ class InstallService(HSBaseUCService):
self._edit_runner_setting()
self._remove_old_runner_container()
self.start_runner()
return {"message": "安装runner成功"}
def _edit_runner_setting(self):
os.system("sudo chmod 777 /etc/gitlab-runner/config.toml")
os.system("chmod 777 /etc/gitlab-runner/config.toml")
with open('/etc/gitlab-runner/config.toml', 'r') as f:
s = f.read()
a = s.replace('volumes = ["/cache"]',
......
......@@ -51,7 +51,7 @@ class UpgradeService():
if not actual_image_verison:
raise HSException(f'找不到对应的{app_image_id}的镜像')
logger.info(f'镜像{app_image_id}的镜像版本号为{actual_image_verison}')
logger.info(f'镜像{app_image_id}的镜像版本号为{actual_image_verison}')
# tag它
if actual_image_verison == '<none>':
......@@ -63,11 +63,14 @@ class UpgradeService():
pass
# 找到app_list
app_list = self.get_app_list_from_compose_file(docker_compose_file_dir)
logger.info('compose中的app_list为:{}'.format(app_list))
# docker-compose
project_info = ConnectionService().get_project_info()
host_ip = project_info['host_ip']
# 调用本机的docker-compose
ssh_conenct = SSHConnect(user_name='root', password='huansi.net', host_port='1111', host_ip=host_ip)
with ssh_conenct as ssh:
# todo 处理*的情况
out, err = ssh.exec_command(
f'''export HUANSI_REGISTRY_URL=47.110.145.204:8084 &&\
source /etc/profile.d/huansi.sh &&\
......@@ -125,6 +128,10 @@ docker-compose -f /data/upgrade_tools_data/backup/{upgrade_no}/docker-compose.ym
upgrade_back_up_dir = os.path.join(temp_file_dir, 'backup', upgrade_no)
with ssh_conenct as ssh:
# 验证远端服务器有没有按照docker
self.validate_remote_server_install_docker(ssh)
for files in os.listdir(upgrade_back_up_dir):
path = os.path.join(upgrade_back_up_dir, files)
# 隐藏文件不复制
......@@ -283,3 +290,15 @@ docker-compose -f /data/upgrade_tools_data/backup/{upgrade_no}/docker-compose.ym
upgrade_no = app_info['upgrade_no']
return upgrade_no
def validate_remote_server_install_docker(self, ssh):
'''
验证远端服务器是否安装docker
:param ssh:
:return:
'''
out, err = ssh.exec_command('docker -v')
if 'Docker version' not in out or err:
logger.info('验证远端服务器是否安装docker日志:{}'.format(err))
raise HSException('远端服务器未安装docker,请先安装后再升级')
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