From 4d86288ab5b011f0c9cd9bc83a40a7a8a63f0a4a Mon Sep 17 00:00:00 2001 From: vapao Date: Sun, 7 Feb 2021 23:52:46 +0800 Subject: [PATCH] upgrade deploy --- spug_api/apps/app/models.py | 4 - spug_api/apps/app/views.py | 4 - spug_web/src/pages/deploy/app/AddSelect.js | 3 +- spug_web/src/pages/deploy/app/Ext1Form.js | 6 +- spug_web/src/pages/deploy/app/Ext1Setup1.js | 19 +- spug_web/src/pages/deploy/app/Ext1Setup2.js | 168 +++++++------ spug_web/src/pages/deploy/app/Ext1Setup3.js | 247 +++++--------------- spug_web/src/pages/deploy/app/Table.js | 2 +- spug_web/src/pages/deploy/app/store.js | 2 + 9 files changed, 171 insertions(+), 284 deletions(-) diff --git a/spug_api/apps/app/models.py b/spug_api/apps/app/models.py index 696d962..f8db656 100644 --- a/spug_api/apps/app/models.py +++ b/spug_api/apps/app/models.py @@ -74,10 +74,7 @@ class DeployExtend1(models.Model, ModelMixin): deploy = models.OneToOneField(Deploy, primary_key=True, on_delete=models.CASCADE) git_repo = models.CharField(max_length=255) dst_dir = models.CharField(max_length=255) - dst_repo = models.CharField(max_length=255) - versions = models.IntegerField() filter_rule = models.TextField() - custom_envs = models.TextField() hook_pre_server = models.TextField(null=True) hook_post_server = models.TextField(null=True) hook_pre_host = models.TextField(null=True) @@ -86,7 +83,6 @@ class DeployExtend1(models.Model, ModelMixin): def to_dict(self, *args, **kwargs): tmp = super().to_dict(*args, **kwargs) tmp['filter_rule'] = json.loads(self.filter_rule) - tmp['custom_envs'] = '\n'.join(f'{k}={v}' for k, v in json.loads(self.custom_envs).items()) return tmp def __repr__(self): diff --git a/spug_api/apps/app/views.py b/spug_api/apps/app/views.py index 7ee998c..1fe117b 100644 --- a/spug_api/apps/app/views.py +++ b/spug_api/apps/app/views.py @@ -120,10 +120,7 @@ class DeployView(View): extend_form, error = JsonParser( Argument('git_repo', handler=str.strip, help='请输入git仓库地址'), Argument('dst_dir', handler=str.strip, help='请输入发布目标路径'), - Argument('dst_repo', handler=str.strip, help='请输入目标仓库路径'), - Argument('versions', type=int, help='请输入保留历史版本数量'), Argument('filter_rule', type=dict, help='参数错误'), - Argument('custom_envs', handler=str.strip, required=False), Argument('hook_pre_server', handler=str.strip, default=''), Argument('hook_post_server', handler=str.strip, default=''), Argument('hook_pre_host', handler=str.strip, default=''), @@ -133,7 +130,6 @@ class DeployView(View): return json_response(error=error) extend_form.dst_dir = extend_form.dst_dir.rstrip('/') extend_form.filter_rule = json.dumps(extend_form.filter_rule) - extend_form.custom_envs = json.dumps(parse_envs(extend_form.custom_envs)) if form.id: extend = DeployExtend1.objects.filter(deploy_id=form.id).first() if extend.git_repo != extend_form.git_repo: diff --git a/spug_web/src/pages/deploy/app/AddSelect.js b/spug_web/src/pages/deploy/app/AddSelect.js index 4db9ca4..f48eb43 100644 --- a/spug_web/src/pages/deploy/app/AddSelect.js +++ b/spug_web/src/pages/deploy/app/AddSelect.js @@ -19,8 +19,7 @@ class AddSelect extends React.Component { git_type: 'branch', is_audit: false, rst_notify: {mode: '0'}, - versions: 10, - host_ids: [undefined], + host_ids: [], filter_rule: {type: 'contain', data: ''} } }; diff --git a/spug_web/src/pages/deploy/app/Ext1Form.js b/spug_web/src/pages/deploy/app/Ext1Form.js index db0ac28..1ac6233 100644 --- a/spug_web/src/pages/deploy/app/Ext1Form.js +++ b/spug_web/src/pages/deploy/app/Ext1Form.js @@ -23,15 +23,15 @@ export default observer(function Ext1From() { return ( store.ext1Visible = false} footer={null}> - - + + {store.page === 0 && } {store.page === 1 && } diff --git a/spug_web/src/pages/deploy/app/Ext1Setup1.js b/spug_web/src/pages/deploy/app/Ext1Setup1.js index 19dba54..e4bd4cb 100644 --- a/spug_web/src/pages/deploy/app/Ext1Setup1.js +++ b/spug_web/src/pages/deploy/app/Ext1Setup1.js @@ -8,6 +8,7 @@ import { observer } from 'mobx-react'; import { Link } from 'react-router-dom'; import { Switch, Form, Input, Select, Button } from 'antd'; import envStore from 'pages/config/environment/store'; +import Selector from 'pages/host/Selector'; import store from './store'; export default observer(function Ext1Setup1() { @@ -41,6 +42,10 @@ export default observer(function Ext1Setup1() { 新建环境 + + {info.host_ids.length > 0 && `已选择 ${info.host_ids.length} 台`} + + info['git_repo'] = e.target.value} placeholder="请输入Git仓库地址"/> @@ -60,9 +65,10 @@ export default observer(function Ext1Setup1() { }> info['rst_notify']['mode'] = v}> + info['dst_dir'] = e.target.value} - placeholder="请输入目标主机部署路径"/> - - - info['dst_repo'] = e.target.value} placeholder="请输入目标主机仓库路径"/> - - - info['versions'] = e.target.value} placeholder="请输入保留历史版本数量"/> - - - {info['host_ids'].map((id, index) => ( - - - {!store.isReadOnly && info['host_ids'].length > 1 && ( - store.delHost(index)} /> - )} - - ))} - - - - - - - - - - ) - } -} - -export default Ext1Setup2 + const info = store.deploy; + return ( +
+ + info['filter_rule']['data'] = cleanCommand(v)} + style={{border: '1px solid #e8e8e8'}}/> + + 可使用 {Tips},请避免在此修改已跟踪的文件,防止在检出代码时失败。}> + info['hook_pre_server'] = cleanCommand(v)} + style={{border: '1px solid #e8e8e8'}}/> + + 可使用 {Tips},大多数情况下在此进行构建操作。}> + info['hook_post_server'] = cleanCommand(v)} + style={{border: '1px solid #e8e8e8'}}/> + + + + + +
+ ) +}) diff --git a/spug_web/src/pages/deploy/app/Ext1Setup3.js b/spug_web/src/pages/deploy/app/Ext1Setup3.js index 4f5cfc6..954870e 100644 --- a/spug_web/src/pages/deploy/app/Ext1Setup3.js +++ b/spug_web/src/pages/deploy/app/Ext1Setup3.js @@ -3,210 +3,79 @@ * Copyright (c) * Released under the AGPL-3.0 License. */ -import React from 'react'; +import React, {useState} from 'react'; import { observer } from 'mobx-react'; -import { GitlabOutlined, InfoCircleOutlined, SettingOutlined, SwapOutlined } from '@ant-design/icons'; -import { Form, Row, Col, Button, Radio, Tooltip, message } from 'antd'; -import { LinkButton } from 'components'; +import { Form, Button, Input, message } from 'antd'; import Editor from 'react-ace'; import 'ace-builds/src-noconflict/mode-text'; import 'ace-builds/src-noconflict/mode-sh'; import 'ace-builds/src-noconflict/theme-tomorrow'; +import { http, cleanCommand } from 'libs'; import store from './store'; -import http from 'libs/http'; -import styles from './index.module.css'; -import { cleanCommand } from "../../../libs"; -@observer -class Ext1Setup3 extends React.Component { - constructor(props) { - super(props); - this.helpMap = { - '2': - Spug 内置了一些全局变量,这些变量可以直接使用,请参考官方文档: - 全局变量 - , - '3': '在部署 Spug 的服务器上运行,可以执行任意自定义命令。', - '4': '在部署 Spug 的服务器上运行,当前目录为检出后待发布的源代码目录,可执行任意自定义命令。', - '5': '在发布的目标主机上运行,当前目录为目标主机上待发布的源代码目录,可执行任意自定义命令。', - '6': '在发布的目标主机上运行,当前目录为已发布的应用目录,可执行任意自定义命令。' - }; - this.state = { - loading: false, - full: '' - } - } +export default observer(function () { + const [loading, setLoading] = useState(false); + const Tips = ( + 内置全局变量 + ) - handleSubmit = () => { - this.setState({loading: true}); + function handleSubmit() { + setLoading(true); const info = store.deploy; info['app_id'] = store.app_id; info['extend'] = '1'; - info['host_ids'] = info['host_ids'].filter(x => x); http.post('/api/app/deploy/', info) .then(() => { message.success('保存成功'); store.loadDeploys(store.app_id); store.ext1Visible = false - }, () => this.setState({loading: false})) - }; - - handleFullscreen = (id) => { - if (this.state.full) { - this.setState({full: ''}) - } else { - this.setState({full: id}) - } + }, () => setLoading(false)) } - FilterLabel = (props) => ( -
-
文件过滤 :
- store.deploy['filter_rule']['type'] = e.target.value}> - 包含 - - - - - 排除 - - - - - -
- this.handleFullscreen('1')}>{this.state.full ? '退出全屏' : '全屏'} -
-
- ); - - NormalLabel = (props) => ( -
-
{props.title} :
- - - -
- this.handleFullscreen(props.id)}>{this.state.full ? '退出全屏' : '全屏'} -
-
- ); - - render() { - const info = store.deploy; - const {full} = this.state; - return ( - - - -
- - info['filter_rule']['data'] = cleanCommand(v)} - style={{border: '1px solid #e8e8e8'}}/> -
-
- - info['hook_pre_server'] = cleanCommand(v)} - style={{border: '1px solid #e8e8e8'}}/> -
-
- - info['hook_pre_host'] = cleanCommand(v)} - style={{border: '1px solid #e8e8e8'}}/> -
- - -
- - 基础设置 -
-
- - 检出代码 -
-
- - 版本切换 -
- - -
- - info['custom_envs'] = cleanCommand(v)} - style={{border: '1px solid #e8e8e8'}}/> -
-
- - info['hook_post_server'] = cleanCommand(v)} - style={{border: '1px solid #e8e8e8'}}/> -
-
- - info['hook_post_host'] = cleanCommand(v)} - style={{border: '1px solid #e8e8e8'}}/> -
- -
- - - - -
- ) - } -} - -export default Ext1Setup3 + const info = store.deploy; + return ( +
+ + info['dst_dir'] = e.target.value} placeholder="请输入部署目标路径" /> + + 可使用 {Tips},此时还未进行文件变更,可进行一些发布前置操作。}> + info['hook_pre_host'] = cleanCommand(v)} + style={{border: '1px solid #e8e8e8'}}/> + + 可使用 {Tips},可以在发布后进行重启服务等操作。}> + info['hook_post_host'] = cleanCommand(v)} + style={{border: '1px solid #e8e8e8'}}/> + + + + + +
+ ) +}) \ No newline at end of file diff --git a/spug_web/src/pages/deploy/app/Table.js b/spug_web/src/pages/deploy/app/Table.js index c000872..d7b8a09 100644 --- a/spug_web/src/pages/deploy/app/Table.js +++ b/spug_web/src/pages/deploy/app/Table.js @@ -91,7 +91,7 @@ class ComTable extends React.Component { }; expandedRowRender = (record) => { - if (record['deploys'] === undefined) { + if (!record.isLoaded) { store.loadDeploys(record.id) } diff --git a/spug_web/src/pages/deploy/app/store.js b/spug_web/src/pages/deploy/app/store.js index fd219ef..6c84051 100644 --- a/spug_web/src/pages/deploy/app/store.js +++ b/spug_web/src/pages/deploy/app/store.js @@ -18,6 +18,7 @@ class Store { @observable addVisible = false; @observable ext1Visible = false; @observable ext2Visible = false; + @observable selectorVisible = false; @observable f_name; @observable f_desc; @@ -47,6 +48,7 @@ class Store { }; loadDeploys = (app_id) => { + this.records[`a${app_id}`].isLoaded = true; return http.get('/api/app/deploy/', {params: {app_id}}) .then(res => this.records[`a${app_id}`]['deploys'] = res) };