A web update

pull/22/head
雷二猛 2019-12-23 23:03:45 +08:00
parent 8638039198
commit 95ad5a149b
4 changed files with 48 additions and 50 deletions

View File

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

View File

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

View File

@ -28,7 +28,7 @@ class Ext1Setup2 extends React.Component {
<Form.Item required label="目标主机仓库路径" help="此目录用于存储应用的历史版本,例如:/data/spug/repos">
<Input value={info['dst_repo']} onChange={e => info['dst_repo'] = e.target.value} placeholder="请输入目标主机仓库路径"/>
</Form.Item>
<Form.Item required label="保留历史版本数量" help="早于指定数量的历史版本将无法回滚">
<Form.Item required label="保留历史版本数量" help="早于指定数量的历史版本会被删除,以释放空间">
<Input value={info['versions']} onChange={e => info['versions'] = e.target.value} placeholder="请输入保留历史版本数量"/>
</Form.Item>
<Form.Item required label="发布目标主机">

View File

@ -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()}/>
<Collapse defaultActiveKey={1} className={styles.collapse}>
<Collapse.Panel showArrow={false} key={1} header={
store.request.type === '1' ?
<Steps>
<Steps.Step {...this.getStatus('local', 0)} title="建立连接"/>
<Steps.Step {...this.getStatus('local', 1)} title="发布准备"/>
<Steps.Step {...this.getStatus('local', 2)} title="检出前任务"/>
<Steps.Step {...this.getStatus('local', 3)} title="执行检出"/>
<Steps.Step {...this.getStatus('local', 4)} title="检出后任务"/>
<Steps.Step {...this.getStatus('local', 5)} title="执行打包"/>
</Steps> : <Steps style={{width: 400}}>
<Steps.Step {...this.getStatus('local', 0)} title="建立连接"/>
<Steps.Step {...this.getStatus('local', 1)} title="发布准备"/>
</Steps>}>
<Steps>
<Steps.Step {...this.getStatus('local', 0)} title="建立连接"/>
<Steps.Step {...this.getStatus('local', 1)} title="发布准备"/>
<Steps.Step {...this.getStatus('local', 2)} title="检出前任务"/>
<Steps.Step {...this.getStatus('local', 3)} title="执行检出"/>
<Steps.Step {...this.getStatus('local', 4)} title="检出后任务"/>
<Steps.Step {...this.getStatus('local', 5)} title="执行打包"/>
</Steps>}>
<pre className={styles.console}>{lds.get(store.outputs, 'local.data')}</pre>
</Collapse.Panel>
</Collapse>