mirror of https://github.com/openspug/spug
U 优化发布执行展示效果
parent
b42b12aa88
commit
6709feffeb
|
@ -4,7 +4,7 @@
|
||||||
from django_redis import get_redis_connection
|
from django_redis import get_redis_connection
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.db import close_old_connections
|
from django.db import close_old_connections
|
||||||
from libs.utils import AttrDict, render_str
|
from libs.utils import AttrDict, render_str, human_seconds_time
|
||||||
from apps.host.models import Host
|
from apps.host.models import Host
|
||||||
from apps.config.utils import compose_configs
|
from apps.config.utils import compose_configs
|
||||||
from apps.repository.models import Repository
|
from apps.repository.models import Repository
|
||||||
|
@ -15,6 +15,7 @@ from concurrent import futures
|
||||||
from functools import partial
|
from functools import partial
|
||||||
import json
|
import json
|
||||||
import uuid
|
import uuid
|
||||||
|
import time
|
||||||
import os
|
import os
|
||||||
|
|
||||||
REPOS_DIR = settings.REPOS_DIR
|
REPOS_DIR = settings.REPOS_DIR
|
||||||
|
@ -131,6 +132,7 @@ def _ext1_deploy(req, helper, env):
|
||||||
|
|
||||||
|
|
||||||
def _ext2_deploy(req, helper, env):
|
def _ext2_deploy(req, helper, env):
|
||||||
|
flag = time.time()
|
||||||
extend, step = req.deploy.extend_obj, 1
|
extend, step = req.deploy.extend_obj, 1
|
||||||
host_actions = json.loads(extend.host_actions)
|
host_actions = json.loads(extend.host_actions)
|
||||||
server_actions = json.loads(extend.server_actions)
|
server_actions = json.loads(extend.server_actions)
|
||||||
|
@ -192,8 +194,9 @@ def _ext2_deploy(req, helper, env):
|
||||||
helper.send_info('local', '打包完成\r\n')
|
helper.send_info('local', '打包完成\r\n')
|
||||||
helper.add_callback(partial(os.remove, os.path.join(sp_dir, tar_gz_file)))
|
helper.add_callback(partial(os.remove, os.path.join(sp_dir, tar_gz_file)))
|
||||||
|
|
||||||
|
human_time = human_seconds_time(time.time() - flag)
|
||||||
if host_actions:
|
if host_actions:
|
||||||
helper.send_success('local', '\r\n** 执行完成 **', status='success')
|
helper.send_success('local', f'\r\n** 执行完成,耗时:{human_time} **', status='success')
|
||||||
if req.deploy.is_parallel:
|
if req.deploy.is_parallel:
|
||||||
threads, latest_exception = [], None
|
threads, latest_exception = [], None
|
||||||
max_workers = max(10, os.cpu_count() * 5)
|
max_workers = max(10, os.cpu_count() * 5)
|
||||||
|
@ -230,10 +233,11 @@ def _ext2_deploy(req, helper, env):
|
||||||
raise e
|
raise e
|
||||||
else:
|
else:
|
||||||
req.fail_host_ids = []
|
req.fail_host_ids = []
|
||||||
helper.send_success('local', '\r\n** 发布成功 **', status='success')
|
helper.send_success('local', f'\r\n** 发布成功,耗时:{human_time} **', status='success')
|
||||||
|
|
||||||
|
|
||||||
def _deploy_ext1_host(req, helper, h_id, env):
|
def _deploy_ext1_host(req, helper, h_id, env):
|
||||||
|
flag = time.time()
|
||||||
helper.send_clear(h_id)
|
helper.send_clear(h_id)
|
||||||
helper.send_info(h_id, '数据准备... ', status='doing')
|
helper.send_info(h_id, '数据准备... ', status='doing')
|
||||||
host = Host.objects.filter(pk=h_id).first()
|
host = Host.objects.filter(pk=h_id).first()
|
||||||
|
@ -292,10 +296,12 @@ def _deploy_ext1_host(req, helper, h_id, env):
|
||||||
command = f'cd {extend.dst_dir} && {extend.hook_post_host}'
|
command = f'cd {extend.dst_dir} && {extend.hook_post_host}'
|
||||||
helper.remote(host.id, ssh, command)
|
helper.remote(host.id, ssh, command)
|
||||||
|
|
||||||
helper.send_success(h_id, '\r\n** 发布成功 **', status='success')
|
human_time = human_seconds_time(time.time() - flag)
|
||||||
|
helper.send_success(h_id, f'\r\n** 发布成功,耗时:{human_time} **', status='success')
|
||||||
|
|
||||||
|
|
||||||
def _deploy_ext2_host(helper, h_id, actions, env, spug_version):
|
def _deploy_ext2_host(helper, h_id, actions, env, spug_version):
|
||||||
|
flag = time.time()
|
||||||
host = Host.objects.filter(pk=h_id).first()
|
host = Host.objects.filter(pk=h_id).first()
|
||||||
if not host:
|
if not host:
|
||||||
helper.send_error(h_id, 'no such host')
|
helper.send_error(h_id, 'no such host')
|
||||||
|
@ -339,5 +345,5 @@ def _deploy_ext2_host(helper, h_id, actions, env, spug_version):
|
||||||
helper.send_info(h_id, f'{action["title"]}...\r\n')
|
helper.send_info(h_id, f'{action["title"]}...\r\n')
|
||||||
command = f'cd /tmp && {action["data"]}'
|
command = f'cd /tmp && {action["data"]}'
|
||||||
helper.remote(host.id, ssh, command)
|
helper.remote(host.id, ssh, command)
|
||||||
|
human_time = human_seconds_time(time.time() - flag)
|
||||||
helper.send_success(h_id, f'\r\n** 发布成功 **', status='success')
|
helper.send_success(h_id, f'\r\n** 发布成功,耗时:{human_time} **', status='success')
|
||||||
|
|
|
@ -59,7 +59,7 @@ class Job:
|
||||||
for code, out in self.ssh.exec_command_with_stream(self.command, self.env):
|
for code, out in self.ssh.exec_command_with_stream(self.command, self.env):
|
||||||
self.send(out)
|
self.send(out)
|
||||||
human_time = human_seconds_time(time.time() - flag)
|
human_time = human_seconds_time(time.time() - flag)
|
||||||
self.send(f'\r\n\x1b[36m** 执行结束,总耗时:{human_time} **\x1b[0m')
|
self.send(f'\r\n\x1b[36m** 执行结束,耗时:{human_time} **\x1b[0m')
|
||||||
except socket.timeout:
|
except socket.timeout:
|
||||||
code = 130
|
code = 130
|
||||||
self.send('\r\n\x1b[31m### Time out\x1b[0m')
|
self.send('\r\n\x1b[31m### Time out\x1b[0m')
|
||||||
|
|
|
@ -4,13 +4,14 @@
|
||||||
from django_redis import get_redis_connection
|
from django_redis import get_redis_connection
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.db import close_old_connections
|
from django.db import close_old_connections
|
||||||
from libs.utils import AttrDict, human_datetime, render_str
|
from libs.utils import AttrDict, human_datetime, render_str, human_seconds_time
|
||||||
from apps.repository.models import Repository
|
from apps.repository.models import Repository
|
||||||
from apps.app.utils import fetch_repo
|
from apps.app.utils import fetch_repo
|
||||||
from apps.config.utils import compose_configs
|
from apps.config.utils import compose_configs
|
||||||
from apps.deploy.helper import Helper
|
from apps.deploy.helper import Helper
|
||||||
import json
|
import json
|
||||||
import uuid
|
import uuid
|
||||||
|
import time
|
||||||
import os
|
import os
|
||||||
|
|
||||||
REPOS_DIR = settings.REPOS_DIR
|
REPOS_DIR = settings.REPOS_DIR
|
||||||
|
@ -77,6 +78,7 @@ def dispatch(rep: Repository, helper=None):
|
||||||
|
|
||||||
|
|
||||||
def _build(rep: Repository, helper, env):
|
def _build(rep: Repository, helper, env):
|
||||||
|
flag = time.time()
|
||||||
extend = rep.deploy.extend_obj
|
extend = rep.deploy.extend_obj
|
||||||
git_dir = os.path.join(REPOS_DIR, str(rep.deploy_id))
|
git_dir = os.path.join(REPOS_DIR, str(rep.deploy_id))
|
||||||
build_dir = os.path.join(REPOS_DIR, rep.spug_version)
|
build_dir = os.path.join(REPOS_DIR, rep.spug_version)
|
||||||
|
@ -115,4 +117,5 @@ def _build(rep: Repository, helper, env):
|
||||||
contain = ' '.join(f'{rep.spug_version}/{x}' for x in files)
|
contain = ' '.join(f'{rep.spug_version}/{x}' for x in files)
|
||||||
helper.local(f'mkdir -p {BUILD_DIR} && cd {REPOS_DIR} && tar zcf {tar_file} {exclude} {contain}')
|
helper.local(f'mkdir -p {BUILD_DIR} && cd {REPOS_DIR} && tar zcf {tar_file} {exclude} {contain}')
|
||||||
helper.send_success('local', '完成√\r\n')
|
helper.send_success('local', '完成√\r\n')
|
||||||
helper.send_success('local', '\r\n** 构建成功 **\r\n', status='success')
|
human_time = human_seconds_time(time.time() - flag)
|
||||||
|
helper.send_success('local', f'\r\n** 构建成功,耗时:{human_time} **\r\n', status='success')
|
||||||
|
|
|
@ -239,9 +239,11 @@ function Console(props) {
|
||||||
)}
|
)}
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
)}
|
)}
|
||||||
<Tooltip title="打开web终端">
|
{cItem.id !== 'local' && (
|
||||||
<CodeOutlined className={styles.icon} onClick={() => openTerminal(current)}/>
|
<Tooltip title="打开web终端">
|
||||||
</Tooltip>
|
<CodeOutlined className={styles.icon} onClick={() => openTerminal(current)}/>
|
||||||
|
</Tooltip>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
<div className={styles.termContainer}>
|
<div className={styles.termContainer}>
|
||||||
<div ref={el} className={styles.term}/>
|
<div ref={el} className={styles.term}/>
|
||||||
|
|
Loading…
Reference in New Issue