A web update

pull/22/head
雷二猛 2019-12-27 19:33:41 +08:00
parent 9bb9a84780
commit 1bcf54cdea
4 changed files with 40 additions and 11 deletions

View File

@ -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

View File

@ -70,7 +70,7 @@ class Ext2Setup3 extends React.Component {
</div>
))}
<Form.Item wrapperCol={{span: 14, offset: 6}}>
<Button type="dashed" block onClick={() => server_actions.push({target: 'server'})}>
<Button type="dashed" block onClick={() => server_actions.push({})}>
<Icon type="plus"/>添加本地执行动作在服务端本地执行
</Button>
</Form.Item>
@ -97,7 +97,7 @@ class Ext2Setup3 extends React.Component {
</div>
))}
<Form.Item wrapperCol={{span: 14, offset: 6}}>
<Button type="dashed" block onClick={() => host_actions.push({target: 'server'})}>
<Button type="dashed" block onClick={() => host_actions.push({})}>
<Icon type="plus"/>添加目标主机执行动作在部署目标主机执行
</Button>
</Form.Item>

View File

@ -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 = {};
}

View File

@ -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 <Tag color="red">发布异常</Tag>
} else if (lds.get(store.outputs, `${item.id}.step`, -1) < 5) {
} else if (lds.get(store.outputs, `${item.id}.step`, -1) < 100) {
return <Tag color="blue">发布中</Tag>
}
}
@ -101,7 +101,7 @@ class Ext1Index extends React.Component {
<Steps.Step {...this.getStatus('local', 0)} title="建立连接"/>
<Steps.Step {...this.getStatus('local', 1)} title="发布准备"/>
{server_actions.map((item, index) => (
<Steps.Step {...this.getStatus('local', 2)} key={index} title={item.title}/>
<Steps.Step {...this.getStatus('local', 2 + index)} key={index} title={item.title}/>
))}
</Steps>}>
<pre className={styles.ext1Console}>{lds.get(store.outputs, 'local.data')}</pre>
@ -119,8 +119,8 @@ class Ext1Index extends React.Component {
<b>{item.title}</b>
<Steps size="small" style={{maxWidth: 150 + host_actions.length * 150}}>
<Steps.Step {...this.getStatus(item.id, 1)} title="数据准备"/>
{host_actions.map((item, index) => (
<Steps.Step {...this.getStatus(item.id, 2)} key={index} title={item.title}/>
{host_actions.map((action, index) => (
<Steps.Step {...this.getStatus(item.id, 2 + index)} key={index} title={action.title}/>
))}
</Steps>
</div>}>