mirror of https://github.com/openspug/spug
U 优化自定义发布数据传输
parent
e80249c311
commit
ba4f561aa6
|
@ -22,7 +22,7 @@ def auto_deploy(request, deploy_id, kind):
|
||||||
if kind == 'branch' and _kind == 'heads':
|
if kind == 'branch' and _kind == 'heads':
|
||||||
commit_id = body['after']
|
commit_id = body['after']
|
||||||
if commit_id != '0000000000000000000000000000000000000000' and ref == request.GET.get('name'):
|
if commit_id != '0000000000000000000000000000000000000000' and ref == request.GET.get('name'):
|
||||||
message = _parse_message(body, repo)[:20]
|
message = _parse_message(body, repo)
|
||||||
Thread(target=_dispatch, args=(deploy_id, ref, commit_id, message)).start()
|
Thread(target=_dispatch, args=(deploy_id, ref, commit_id, message)).start()
|
||||||
return HttpResponse(status=202)
|
return HttpResponse(status=202)
|
||||||
elif kind == 'tag' and _kind == 'tags':
|
elif kind == 'tag' and _kind == 'tags':
|
||||||
|
@ -82,7 +82,7 @@ def _parse_message(body, repo):
|
||||||
message = body['commits'][0].get('message', '')
|
message = body['commits'][0].get('message', '')
|
||||||
else:
|
else:
|
||||||
raise ValueError(f'repo {repo} is not supported')
|
raise ValueError(f'repo {repo} is not supported')
|
||||||
return message
|
return message[:20].strip()
|
||||||
|
|
||||||
|
|
||||||
def _dispatch(deploy_id, ref, commit_id=None, message=None):
|
def _dispatch(deploy_id, ref, commit_id=None, message=None):
|
||||||
|
|
|
@ -131,7 +131,10 @@ def _ext2_deploy(req, helper, env):
|
||||||
if action.get('type') == 'transfer':
|
if action.get('type') == 'transfer':
|
||||||
action['src'] = render_str(action.get('src', '').strip().rstrip('/'), env)
|
action['src'] = render_str(action.get('src', '').strip().rstrip('/'), env)
|
||||||
action['dst'] = render_str(action['dst'].strip().rstrip('/'), env)
|
action['dst'] = render_str(action['dst'].strip().rstrip('/'), env)
|
||||||
if action.get('src_mode') == '1':
|
if action.get('src_mode') == '1': # upload when publish
|
||||||
|
extra = json.loads(req.extra)
|
||||||
|
if 'name' in extra:
|
||||||
|
action['name'] = extra['name']
|
||||||
break
|
break
|
||||||
helper.send_step('local', step, f'{human_time()} 检测到来源为本地路径的数据传输动作,执行打包... \r\n')
|
helper.send_step('local', step, f'{human_time()} 检测到来源为本地路径的数据传输动作,执行打包... \r\n')
|
||||||
action['src'] = action['src'].rstrip('/ ')
|
action['src'] = action['src'].rstrip('/ ')
|
||||||
|
@ -263,7 +266,14 @@ def _deploy_ext2_host(helper, h_id, actions, env, spug_version):
|
||||||
if action.get('type') == 'transfer':
|
if action.get('type') == 'transfer':
|
||||||
if action.get('src_mode') == '1':
|
if action.get('src_mode') == '1':
|
||||||
try:
|
try:
|
||||||
ssh.put_file(os.path.join(REPOS_DIR, env.SPUG_DEPLOY_ID, spug_version), action['dst'])
|
dst = action['dst']
|
||||||
|
command = f'[ -e {dst} ] || mkdir -p $(dirname {dst}); [ -d {dst} ]'
|
||||||
|
code, _ = ssh.exec_command_raw(command)
|
||||||
|
if code == 0: # is dir
|
||||||
|
if not action.get('name'):
|
||||||
|
raise RuntimeError('internal error 1002')
|
||||||
|
dst = dst.rstrip('/') + '/' + action['name']
|
||||||
|
ssh.put_file(os.path.join(REPOS_DIR, env.SPUG_DEPLOY_ID, spug_version), dst)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
helper.send_error(host.id, f'Exception: {e}')
|
helper.send_error(host.id, f'Exception: {e}')
|
||||||
helper.send_info(host.id, 'transfer completed\r\n')
|
helper.send_info(host.id, 'transfer completed\r\n')
|
||||||
|
|
Loading…
Reference in New Issue