From 1bcf54cdea5f8a5216080983666045000ea2d679 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=B7=E4=BA=8C=E7=8C=9B?= Date: Fri, 27 Dec 2019 19:33:41 +0800 Subject: [PATCH] A web update --- spug_api/apps/deploy/utils.py | 37 ++++++++++++++++++--- spug_web/src/pages/deploy/app/Ext2Setup3.js | 4 +-- spug_web/src/pages/deploy/do/Ext1Index.js | 2 +- spug_web/src/pages/deploy/do/Ext2Index.js | 8 ++--- 4 files changed, 40 insertions(+), 11 deletions(-) diff --git a/spug_api/apps/deploy/utils.py b/spug_api/apps/deploy/utils.py index 74ed363..ed3e19e 100644 --- a/spug_api/apps/deploy/utils.py +++ b/spug_api/apps/deploy/utils.py @@ -78,24 +78,39 @@ def _ext1_deploy(request, req, helper, env): contain = ' '.join(f'{env.SPUG_VERSION}/{x}' for x in files) helper.local(f'cd {REPOS_DIR} && tar zcf {env.SPUG_VERSION}.tar.gz {exclude} {contain}') helper.send_step('local', 6, f'完成') - with futures.ThreadPoolExecutor(max_workers=min(16, os.cpu_count() + 4)) as executor: + with futures.ThreadPoolExecutor(max_workers=min(10, os.cpu_count() + 5)) as executor: threads = [] for h_id in json.loads(req.host_ids): - threads.append(executor.submit(_deploy_host, helper, h_id, extend, env)) + threads.append(executor.submit(_deploy_ext1_host, helper, h_id, extend, env)) for t in futures.as_completed(threads): if t.exception(): raise t.exception() def _ext2_deploy(request, req, helper, env): - app = req.app extend = req.app.extend_obj extras = json.loads(req.extra) + host_actions = json.loads(extend.host_actions) + server_actions = json.loads(extend.server_actions) if extras and extras[0]: env.update({'SPUG_RELEASE': extras[0]}) + step = 2 + for action in server_actions: + helper.send_step('local', step, f'\r\n{human_time()} {action["title"]}...\r\n') + helper.local(f'cd /tmp && {action["data"]}', env) + step += 1 + helper.send_step('local', 100, '完成\r\n' if step == 2 else '\r\n') + if host_actions: + with futures.ThreadPoolExecutor(max_workers=min(10, os.cpu_count() + 5)) as executor: + threads = [] + for h_id in json.loads(req.host_ids): + threads.append(executor.submit(_deploy_ext2_host, helper, h_id, host_actions, env)) + for t in futures.as_completed(threads): + if t.exception(): + raise t.exception() -def _deploy_host(helper, h_id, extend, env): +def _deploy_ext1_host(helper, h_id, extend, env): helper.send_step(h_id, 1, f'{human_time()} 数据准备... ') host = Host.objects.filter(pk=h_id).first() if not host: @@ -140,6 +155,20 @@ def _deploy_host(helper, h_id, extend, env): helper.send_step(h_id, 5, f'\r\n{human_time()} ** 发布成功 **') +def _deploy_ext2_host(helper, h_id, actions, env): + helper.send_step(h_id, 1, f'{human_time()} 数据准备... ') + host = Host.objects.filter(pk=h_id).first() + if not host: + helper.send_error(h_id, 'no such host') + ssh = host.get_ssh() + helper.send_step(h_id, 2, '完成\r\n') + for index, action in enumerate(actions): + helper.send_step(h_id, 2 + index, f'{human_time()} {action["title"]}...\r\n') + helper.remote(host.id, ssh, f'cd /tmp && {action["data"]}', env) + + helper.send_step(h_id, 100, f'\r\n{human_time()}** 发布成功 **') + + class Helper: def __init__(self, rds, token): self.rds = rds diff --git a/spug_web/src/pages/deploy/app/Ext2Setup3.js b/spug_web/src/pages/deploy/app/Ext2Setup3.js index facc5bc..e7825c8 100644 --- a/spug_web/src/pages/deploy/app/Ext2Setup3.js +++ b/spug_web/src/pages/deploy/app/Ext2Setup3.js @@ -70,7 +70,7 @@ class Ext2Setup3 extends React.Component { ))} - @@ -97,7 +97,7 @@ class Ext2Setup3 extends React.Component { ))} - diff --git a/spug_web/src/pages/deploy/do/Ext1Index.js b/spug_web/src/pages/deploy/do/Ext1Index.js index 5efda14..81a3a2f 100644 --- a/spug_web/src/pages/deploy/do/Ext1Index.js +++ b/spug_web/src/pages/deploy/do/Ext1Index.js @@ -27,7 +27,7 @@ class Ext1Index extends React.Component { componentWillUnmount() { if (this.socket) this.socket.close(); - store.request = {targets: []}; + store.request = {targets: [], host_actions: [], server_actions: []}; store.outputs = {}; } diff --git a/spug_web/src/pages/deploy/do/Ext2Index.js b/spug_web/src/pages/deploy/do/Ext2Index.js index 67f1f8b..f7b418c 100644 --- a/spug_web/src/pages/deploy/do/Ext2Index.js +++ b/spug_web/src/pages/deploy/do/Ext2Index.js @@ -73,7 +73,7 @@ class Ext1Index extends React.Component { for (let item of [{id: 'local'}, ...store.request.targets]) { if (lds.get(store.outputs, `${item.id}.status`) === 'error') { return 发布异常 - } else if (lds.get(store.outputs, `${item.id}.step`, -1) < 5) { + } else if (lds.get(store.outputs, `${item.id}.step`, -1) < 100) { return 发布中 } } @@ -101,7 +101,7 @@ class Ext1Index extends React.Component { {server_actions.map((item, index) => ( - + ))} }>
{lds.get(store.outputs, 'local.data')}
@@ -119,8 +119,8 @@ class Ext1Index extends React.Component { {item.title} - {host_actions.map((item, index) => ( - + {host_actions.map((action, index) => ( + ))} }>