diff --git a/spug_api/apps/deploy/models.py b/spug_api/apps/deploy/models.py
index 2cd7ed0..3070efd 100644
--- a/spug_api/apps/deploy/models.py
+++ b/spug_api/apps/deploy/models.py
@@ -47,7 +47,7 @@ class DeployRequest(models.Model, ModelMixin):
@property
def is_quick_deploy(self):
- if self.deploy.extend == '1' and self.extra:
+ if self.type == '1' and self.deploy.extend == '1' and self.extra:
extra = json.loads(self.extra)
return extra[0] in ('branch', 'tag')
return False
diff --git a/spug_api/apps/deploy/urls.py b/spug_api/apps/deploy/urls.py
index 1fdb7be..424dd04 100644
--- a/spug_api/apps/deploy/urls.py
+++ b/spug_api/apps/deploy/urls.py
@@ -7,6 +7,7 @@ from .views import *
urlpatterns = [
path('request/', RequestView.as_view()),
+ path('request/info/', get_request_info),
path('request/ext1/', post_request_ext1),
path('request/ext1/rollback/', post_request_ext1_rollback),
path('request/ext2/', post_request_ext2),
diff --git a/spug_api/apps/deploy/utils.py b/spug_api/apps/deploy/utils.py
index 3d1b9d9..b826162 100644
--- a/spug_api/apps/deploy/utils.py
+++ b/spug_api/apps/deploy/utils.py
@@ -173,25 +173,28 @@ def _deploy_ext1_host(req, helper, h_id, env):
f'mkdir -p {extend.dst_repo} && [ -e {extend.dst_dir} ] && [ ! -L {extend.dst_dir} ]')
if code == 0:
helper.send_error(host.id, f'检测到该主机的发布目录 {extend.dst_dir!r} 已存在,为了数据安全请自行备份后删除该目录,Spug 将会创建并接管该目录。')
- # clean
- clean_command = f'ls -d {extend.deploy_id}_* 2> /dev/null | sort -t _ -rnk2 | tail -n +{extend.versions + 1} | xargs rm -rf'
- helper.remote_raw(host.id, ssh, f'cd {extend.dst_repo} && {clean_command}')
- # transfer files
- tar_gz_file = f'{req.spug_version}.tar.gz'
- try:
- ssh.put_file(os.path.join(REPOS_DIR, 'build', tar_gz_file), os.path.join(extend.dst_repo, tar_gz_file))
- except Exception as e:
- helper.send_error(host.id, f'Exception: {e}')
+ if req.type == '1':
+ # clean
+ clean_command = f'ls -d {extend.deploy_id}_* 2> /dev/null | sort -t _ -rnk2 | tail -n +{extend.versions + 1} | xargs rm -rf'
+ helper.remote_raw(host.id, ssh, f'cd {extend.dst_repo} && {clean_command}')
+ # transfer files
+ tar_gz_file = f'{req.spug_version}.tar.gz'
+ try:
+ ssh.put_file(os.path.join(REPOS_DIR, 'build', 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} && rm -rf {req.spug_version} && tar xf {tar_gz_file} && rm -f {req.deploy_id}_*.tar.gz'
- helper.remote_raw(host.id, ssh, command)
- helper.send_step(h_id, 1, '\033[32m完成√\033[0m\r\n')
+ command = f'cd {extend.dst_repo} && rm -rf {req.spug_version} && tar xf {tar_gz_file} && rm -f {req.deploy_id}_*.tar.gz'
+ helper.remote_raw(host.id, ssh, command)
+ helper.send_step(h_id, 1, '\033[32m完成√\033[0m\r\n')
+ else:
+ helper.send_step(h_id, 1, '\033[33m跳过√\033[0m\r\n')
# pre host
repo_dir = os.path.join(extend.dst_repo, req.spug_version)
if extend.hook_pre_host:
helper.send_step(h_id, 2, f'{human_time()} 发布前任务... \r\n')
- command = f'cd {repo_dir} ; {extend.hook_pre_host}'
+ command = f'cd {repo_dir} && {extend.hook_pre_host}'
helper.remote(host.id, ssh, command)
# do deploy
@@ -202,7 +205,7 @@ def _deploy_ext1_host(req, helper, h_id, env):
# post host
if extend.hook_post_host:
helper.send_step(h_id, 4, f'{human_time()} 发布后任务... \r\n')
- command = f'cd {extend.dst_dir} ; {extend.hook_post_host}'
+ command = f'cd {extend.dst_dir} && {extend.hook_post_host}'
helper.remote(host.id, ssh, command)
helper.send_step(h_id, 100, f'\r\n{human_time()} ** \033[32m发布成功\033[0m **')
@@ -237,7 +240,7 @@ def _deploy_ext2_host(helper, h_id, actions, env, spug_version):
command += f'&& rm -rf {action["dst"]} && mv /tmp/{spug_version}/{sd_dst} {action["dst"]} '
command += f'&& rm -rf /tmp/{spug_version}* && echo "transfer completed"'
else:
- command = f'cd /tmp ; {action["data"]}'
+ command = f'cd /tmp && {action["data"]}'
helper.remote(host.id, ssh, command)
helper.send_step(h_id, 100, f'\r\n{human_time()} ** \033[32m发布成功\033[0m **')
diff --git a/spug_api/apps/deploy/views.py b/spug_api/apps/deploy/views.py
index 7bef9ec..1b0f7b2 100644
--- a/spug_api/apps/deploy/views.py
+++ b/spug_api/apps/deploy/views.py
@@ -334,6 +334,18 @@ def post_request_ext2(request):
return json_response(error=error)
+def get_request_info(request):
+ form, error = JsonParser(
+ Argument('id', type=int, help='参数错误')
+ ).parse(request.GET)
+ if error is None:
+ req = DeployRequest.objects.get(pk=form.id)
+ response = req.to_dict(selects=('status', 'reason'))
+ response['status_alias'] = req.get_status_display()
+ return json_response(response)
+ return json_response(error=error)
+
+
def do_upload(request):
repos_dir = settings.REPOS_DIR
file = request.FILES['file']
diff --git a/spug_web/src/pages/deploy/request/Ext1Console.js b/spug_web/src/pages/deploy/request/Ext1Console.js
index 4e5117b..fc73a4f 100644
--- a/spug_web/src/pages/deploy/request/Ext1Console.js
+++ b/spug_web/src/pages/deploy/request/Ext1Console.js
@@ -15,6 +15,8 @@ import store from './store';
function Ext1Console(props) {
const outputs = useLocalStore(() => ({}));
const terms = useLocalStore(() => ({}));
+ const [mini, setMini] = useState(false);
+ const [visible, setVisible] = useState(true);
const [fetching, setFetching] = useState(true);
useEffect(props.request.mode === 'read' ? readDeploy : doDeploy, [])
@@ -39,7 +41,7 @@ function Ext1Console(props) {
Object.assign(outputs, res.outputs)
setTimeout(() => setFetching(false), 100)
socket = _makeSocket()
- store.fetchRecords()
+ store.fetchInfo(props.request.id)
})
return () => socket && socket.close()
}
@@ -85,8 +87,8 @@ function Ext1Console(props) {
}
function switchMiniMode() {
- const value = store.tabModes[props.request.id];
- store.tabModes[props.request.id] = !value
+ setMini(true)
+ setVisible(false)
}
function handleSetTerm(term, key) {
@@ -97,86 +99,90 @@ function Ext1Console(props) {
}
let {local, ...hosts} = outputs;
- return store.tabModes[props.request.id] ? (
-