From 95ad5a149bab8e8e2f544968753f920d5b56fe71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=B7=E4=BA=8C=E7=8C=9B?= Date: Mon, 23 Dec 2019 23:03:45 +0800 Subject: [PATCH] A web update --- spug_api/apps/deploy/utils.py | 68 ++++++++++----------- spug_api/apps/deploy/views.py | 6 +- spug_web/src/pages/deploy/app/Ext1Setup2.js | 2 +- spug_web/src/pages/deploy/do/index.js | 22 +++---- 4 files changed, 48 insertions(+), 50 deletions(-) diff --git a/spug_api/apps/deploy/utils.py b/spug_api/apps/deploy/utils.py index 9a2e5ef..6ae0a2d 100644 --- a/spug_api/apps/deploy/utils.py +++ b/spug_api/apps/deploy/utils.py @@ -51,33 +51,32 @@ def _ext1_deploy(request, req, helper, env): else: tree_ish = extras[1] env.update(TAG=extras[1]) - if req.type == '1': - helper.local(f'cd {REPOS_DIR} && rm -rf {req.app_id}_*') - helper.send_step('local', 1, '完成\r\n') + helper.local(f'cd {REPOS_DIR} && rm -rf {req.app_id}_*') + helper.send_step('local', 1, '完成\r\n') - if extend.hook_pre_server: - helper.send_step('local', 2, f'{human_time()} 检出前任务...\r\n') - helper.local(f'cd /tmp && {extend.hook_pre_server}', env) + if extend.hook_pre_server: + helper.send_step('local', 2, f'{human_time()} 检出前任务...\r\n') + helper.local(f'cd /tmp && {extend.hook_pre_server}', env) - helper.send_step('local', 3, f'{human_time()} 执行检出... ') - git_dir = os.path.join(REPOS_DIR, str(app.id)) - command = f'cd {git_dir} && git archive --prefix={env.VERSION}/ {tree_ish} | (cd .. && tar xf -)' - helper.local(command) - helper.send_step('local', 3, '完成\r\n') + helper.send_step('local', 3, f'{human_time()} 执行检出... ') + git_dir = os.path.join(REPOS_DIR, str(app.id)) + command = f'cd {git_dir} && git archive --prefix={env.VERSION}/ {tree_ish} | (cd .. && tar xf -)' + helper.local(command) + helper.send_step('local', 3, '完成\r\n') - if extend.hook_post_server: - helper.send_step('local', 4, f'{human_time()} 检出后任务...\r\n') - helper.local(f'cd {os.path.join(REPOS_DIR, env.VERSION)} && {extend.hook_post_server}', env) + if extend.hook_post_server: + helper.send_step('local', 4, f'{human_time()} 检出后任务...\r\n') + helper.local(f'cd {os.path.join(REPOS_DIR, env.VERSION)} && {extend.hook_post_server}', env) - helper.send_step('local', 5, f'\r\n{human_time()} 执行打包... ') - filter_rule, exclude, contain = json.loads(extend.filter_rule), '', env.VERSION - files = helper.parse_filter_rule(filter_rule['data']) - if files: - if filter_rule['type'] == 'exclude': - exclude = ' '.join(f'--exclude={x}' for x in files) - else: - contain = ' '.join(f'{env.VERSION}/{x}' for x in files) - helper.local(f'cd {REPOS_DIR} && tar zcf {env.VERSION}.tar.gz {exclude} {contain}') + helper.send_step('local', 5, f'\r\n{human_time()} 执行打包... ') + filter_rule, exclude, contain = json.loads(extend.filter_rule), '', env.VERSION + files = helper.parse_filter_rule(filter_rule['data']) + if files: + if filter_rule['type'] == 'exclude': + exclude = ' '.join(f'--exclude={x}' for x in files) + else: + contain = ' '.join(f'{env.VERSION}/{x}' for x in files) + helper.local(f'cd {REPOS_DIR} && tar zcf {env.VERSION}.tar.gz {exclude} {contain}') helper.send_step('local', 6, f'完成') with futures.ThreadPoolExecutor(max_workers=min(16, os.cpu_count() + 4)) as executor: threads = [] @@ -101,19 +100,18 @@ def _deploy_host(helper, h_id, extend, env): code, _ = ssh.exec_command(f'mkdir -p {extend.dst_repo} && [ -e {extend.dst_dir} ] && [ ! -L {extend.dst_dir} ]') if code == 0: helper.send_error(host.id, f'please make sure the {extend.dst_dir!r} is not exists.') - if env.DEPLOY_TYPE == '1': - # clean - clean_command = f'ls -rd {env.APP_ID}_* | tail -n +{extend.versions + 1} | xargs rm -rf' - helper.remote(host.id, ssh, f'cd {extend.dst_repo} && rm -rf {env.VERSION} && {clean_command}') - # transfer files - tar_gz_file = f'{env.VERSION}.tar.gz' - try: - ssh.put_file(os.path.join(REPOS_DIR, tar_gz_file), os.path.join(extend.dst_repo, tar_gz_file)) - except Exception as e: - helper.send_error(host.id, f'exception: {e}') + # clean + clean_command = f'ls -rd {env.APP_ID}_* | tail -n +{extend.versions + 1} | xargs rm -rf' + helper.remote(host.id, ssh, f'cd {extend.dst_repo} && rm -rf {env.VERSION} && {clean_command}') + # transfer files + tar_gz_file = f'{env.VERSION}.tar.gz' + try: + ssh.put_file(os.path.join(REPOS_DIR, tar_gz_file), os.path.join(extend.dst_repo, tar_gz_file)) + except Exception as e: + helper.send_error(host.id, f'exception: {e}') - command = f'cd {extend.dst_repo} && tar xf {tar_gz_file} && rm -f {env.APP_ID}_*.tar.gz' - helper.remote(host.id, ssh, command) + command = f'cd {extend.dst_repo} && tar xf {tar_gz_file} && rm -f {env.APP_ID}_*.tar.gz' + helper.remote(host.id, ssh, command) helper.send_step(h_id, 1, '完成\r\n') # pre host diff --git a/spug_api/apps/deploy/views.py b/spug_api/apps/deploy/views.py index deb50f5..4888286 100644 --- a/spug_api/apps/deploy/views.py +++ b/spug_api/apps/deploy/views.py @@ -67,7 +67,11 @@ class RequestView(View): req = DeployRequest.objects.filter(pk=form.id).first() if not req: return json_response(error='未找到指定发布申请') - pre_req = DeployRequest.objects.filter(app_id=req.app_id, id__lt=req.id, status='3').first() + pre_req = DeployRequest.objects.filter( + app_id=req.app_id, + type='1', + id__lt=req.id, + version__isnull=False).first() if not pre_req: return json_response(error='未找到该应用可以用于回滚的版本') if form.action == 'check': diff --git a/spug_web/src/pages/deploy/app/Ext1Setup2.js b/spug_web/src/pages/deploy/app/Ext1Setup2.js index 10b6bff..c824541 100644 --- a/spug_web/src/pages/deploy/app/Ext1Setup2.js +++ b/spug_web/src/pages/deploy/app/Ext1Setup2.js @@ -28,7 +28,7 @@ class Ext1Setup2 extends React.Component { info['dst_repo'] = e.target.value} placeholder="请输入目标主机仓库路径"/> - + info['versions'] = e.target.value} placeholder="请输入保留历史版本数量"/> diff --git a/spug_web/src/pages/deploy/do/index.js b/spug_web/src/pages/deploy/do/index.js index be2e9c0..dd87fab 100644 --- a/spug_web/src/pages/deploy/do/index.js +++ b/spug_web/src/pages/deploy/do/index.js @@ -27,7 +27,7 @@ class Index extends React.Component { componentWillUnmount() { if (this.socket) this.socket.close(); - store.request = { targets: []}; + store.request = {targets: []}; store.outputs = {}; } @@ -97,18 +97,14 @@ class Index extends React.Component { onBack={() => history.goBack()}/> - - - - - - - : - - - }> + + + + + + + + }>
{lds.get(store.outputs, 'local.data')}