Skip to content

Commit a9ec312

Browse files
authored
Merge pull request #620 from nickcdon/main
🔧 调整前端部署脚本
2 parents d9e99ea + 9fdad3a commit a9ec312

11 files changed

Lines changed: 207 additions & 155 deletions

File tree

scripts/web/init.sh

Lines changed: 48 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
1-
#!/usr/bin/env bash
1+
#!/bin/bash
22

3-
CURRENT_SCRIPT_PATH=$(cd "$(dirname "${BASH_SOURCE[0]}")";pwd)
4-
TCA_SCRIPT_ROOT=${TCA_SCRIPT_ROOT:-"$(cd $(dirname $CURRENT_SCRIPT_PATH); pwd)"}
5-
export TCA_PROJECT_PATH=${TCA_PROJECT_PATH:-"$( cd $(dirname $TCA_SCRIPT_ROOT); pwd )"}
3+
set -eo pipefail
4+
5+
# 当前脚本执行目录
6+
CURRENT_SCRIPT_PATH=$(
7+
cd "$(dirname "${BASH_SOURCE[0]}")"
8+
pwd
9+
)
10+
11+
TCA_SCRIPT_ROOT=${TCA_SCRIPT_ROOT:-"$(dirname "${CURRENT_SCRIPT_PATH}")"}
12+
13+
export TCA_PROJECT_PATH=${TCA_PROJECT_PATH:-"$(dirname "${TCA_SCRIPT_ROOT}")"}
614
export TCA_WEB_PATH=$TCA_PROJECT_PATH/web
715
export TCA_WEB_DEPLOY_SOURCE_PATH=$TCA_WEB_PATH/tca-deploy-source
816

9-
source $TCA_SCRIPT_ROOT/utils.sh
10-
source $TCA_SCRIPT_ROOT/config.sh
17+
# shellcheck disable=SC1091
18+
source "$TCA_SCRIPT_ROOT"/utils.sh
19+
# shellcheck disable=SC1091
20+
source "$TCA_SCRIPT_ROOT"/config.sh
1121

1222
# 微前端基座
1323
MICRO_FRONTEND_FRAMEWORK="framework"
@@ -16,52 +26,35 @@ MICRO_FRONTEND_DOCUMENT="tca-document"
1626
# 子微前端
1727
MICRO_FRONTEND_APPS="login tca-layout tca-analysis tca-manage"
1828

19-
function check_unzip_command() {
20-
if command_exists unzip; then
21-
return 0
22-
else
23-
return 1
24-
fi
25-
}
26-
27-
# 由于原来各个微前端采用了不同的nginx conf,后为简化开源版前端部署已重新调整配置,为兼容旧版此处默认使用清楚逻辑
28-
function clear_old_nginx_conf() {
29-
# 清除各个应用的nginx conf文件
30-
MICRO_FRONTEND="$MICRO_FRONTEND_FRAMEWORK $MICRO_FRONTEND_APPS $MICRO_FRONTEND_DOCUMENT"
31-
for app in $MICRO_FRONTEND; do
32-
rm -f $NGINX_CONF_PATH/$app.conf
33-
done
34-
}
35-
3629
# 清理资源文件
3730
function clear_assets() {
3831
LOG_WARN "将路径下的资源文件和前端nginx配置备份到 ${TCA_WEB_DEPLOY_PATH}_bak 下..."
3932
if [ -d "$TCA_WEB_DEPLOY_PATH" ]; then
40-
cp -r $TCA_WEB_DEPLOY_PATH/ ${TCA_WEB_DEPLOY_PATH}_bak/
33+
cp -r "$TCA_WEB_DEPLOY_PATH"/ "${TCA_WEB_DEPLOY_PATH}"_bak/
4134
fi
42-
35+
4336
if [ -d "$NGINX_CONF_PATH/tca_ingress.conf" ]; then
44-
cp -r $NGINX_CONF_PATH/tca_ingress.conf ${TCA_WEB_DEPLOY_PATH}_bak/
37+
cp -r "$NGINX_CONF_PATH"/tca_ingress.conf "${TCA_WEB_DEPLOY_PATH}"_bak/
4538
fi
4639

4740
LOG_INFO "开始清理路径下的资源文件 $TCA_WEB_DEPLOY_PATH ..."
48-
rm -rf $TCA_WEB_DEPLOY_PATH/
41+
rm -rf "${TCA_WEB_DEPLOY_PATH:?}"/
4942
LOG_INFO "开始清理前端nginx配置 ..."
50-
rm -f $NGINX_CONF_PATH/tca_ingress.conf
43+
rm -f "$NGINX_CONF_PATH"/tca_ingress.conf
5144
}
5245

5346
# 解压编译后文件
5447
function init_unzip_build() {
5548
LOG_INFO "解压编译后文件到 $TCA_WEB_DEPLOY_PATH ..."
56-
rm -rf $TCA_WEB_DEPLOY_PATH/
57-
mkdir -p $TCA_WEB_DEPLOY_PATH
58-
cd $TCA_WEB_DEPLOY_SOURCE_PATH/build_zip/
49+
rm -rf "${TCA_WEB_DEPLOY_PATH:?}"/
50+
mkdir -p "$TCA_WEB_DEPLOY_PATH"
51+
cd "$TCA_WEB_DEPLOY_SOURCE_PATH"/build_zip/
5952
# 遍历并解压
6053
MICRO_FRONTEND="$MICRO_FRONTEND_FRAMEWORK $MICRO_FRONTEND_APPS $MICRO_FRONTEND_DOCUMENT"
6154
for app in $MICRO_FRONTEND; do
62-
unzip -q -o $app.zip -d $TCA_WEB_DEPLOY_PATH/$app
55+
unzip -q -o "$app".zip -d "$TCA_WEB_DEPLOY_PATH"/"$app"
6356
done
64-
cd $TCA_WEB_DEPLOY_SOURCE_PATH
57+
cd "$TCA_WEB_DEPLOY_SOURCE_PATH"
6558
}
6659

6760
# 初始化配置 framework
@@ -85,8 +78,8 @@ function init_framework_web() {
8578
"
8679
LOG_INFO "[INFO]:index.html RUNTIME is enabled"
8780
LOG_INFO "[INFO]: change 404.html, unsupported-browser.html"
88-
sed -i "$replace_content" $FRAMEWORK_DEPLOY_PATH/404.html
89-
sed -i "$replace_content" $FRAMEWORK_DEPLOY_PATH/unsupported-browser.html
81+
sed -i "$replace_content" "$FRAMEWORK_DEPLOY_PATH"/404.html
82+
sed -i "$replace_content" "$FRAMEWORK_DEPLOY_PATH"/unsupported-browser.html
9083

9184
LOG_INFO "[INFO]: change index.html"
9285
sed \
@@ -95,12 +88,12 @@ function init_framework_web() {
9588
s|__MICRO_FRONTEND_API__|$MICRO_FRONTEND_API|g; \
9689
s|__MICRO_FRONTEND_SETTING_API__|$MICRO_FRONTEND_SETTING_API|g; \
9790
" \
98-
$FRAMEWORK_DEPLOY_PATH/index.runtime.html >$FRAMEWORK_DEPLOY_PATH/index.html
91+
"$FRAMEWORK_DEPLOY_PATH"/index.runtime.html >"$FRAMEWORK_DEPLOY_PATH"/index.html
9992

10093
LOG_INFO "conf 配置迁移 ..."
10194
# 将conf目录中的配置文件拷贝到 $MICRO_FRONTEND_FRAMEWORK static目录下
102-
cp $TCA_WEB_DEPLOY_SOURCE_PATH/conf/settings.json $FRAMEWORK_DEPLOY_PATH/static/settings.json
103-
cp $TCA_WEB_DEPLOY_SOURCE_PATH/conf/configs.json $FRAMEWORK_DEPLOY_PATH/static/configs.json
95+
cp "$TCA_WEB_DEPLOY_SOURCE_PATH"/conf/settings.json "$FRAMEWORK_DEPLOY_PATH"/static/settings.json
96+
cp "$TCA_WEB_DEPLOY_SOURCE_PATH"/conf/configs.json "$FRAMEWORK_DEPLOY_PATH"/static/configs.json
10497
LOG_INFO "$MICRO_FRONTEND_FRAMEWORK 配置完毕"
10598
}
10699

@@ -111,7 +104,7 @@ function init_web_nginx() {
111104
if [ "$IS_DOCKER" == "TRUE" ]; then
112105
SET_DEFAULT_SERVER="default_server"
113106
fi
114-
apps=$(echo $MICRO_FRONTEND_APPS | sed 's/[ ]/\\|/g')
107+
apps=$(echo "$MICRO_FRONTEND_APPS" | sed 's/[ ]/\\|/g')
115108
sed \
116109
"
117110
s|SERVER_NAME|$TCA_WEB_HOST|g; \
@@ -124,27 +117,27 @@ function init_web_nginx() {
124117
s|MICRO_FRONTEND_DOCUMENT|$MICRO_FRONTEND_DOCUMENT|g; \
125118
s|MICRO_FRONTEND_APPS|$apps|g; \
126119
" \
127-
$TCA_WEB_DEPLOY_SOURCE_PATH/nginx/ingress.conf >$NGINX_CONF_PATH/tca_ingress.conf
120+
"$TCA_WEB_DEPLOY_SOURCE_PATH"/nginx/ingress.conf >"$NGINX_CONF_PATH"/tca_ingress.conf
128121
}
129122

130123
# 打印环境变量配置
131124
function log_env() {
132-
LOG_INFO "============================前端配置说明============================"
133-
LOG_INFO "| 前端服务端口: TCA_WEB_PORT --- $TCA_WEB_PORT"
134-
LOG_INFO "| 前端服务SERVER_NAME: TCA_WEB_HOST --- $TCA_WEB_HOST"
135-
LOG_INFO "| 前端服务访问的后端地址: SERVER_ENV --- $TCA_SERVER_ADDR"
136-
LOG_INFO "| 前端服务NGINX配置地址: NGINX_CONF_PATH --- $NGINX_CONF_PATH"
137-
LOG_INFO "| 前端服务资源部署地址: WEB_DEPLOY_PATH --- $TCA_WEB_DEPLOY_PATH"
138-
LOG_INFO "| 前端服务日志地址: NGINX_LOG_PATH --- $NGINX_LOG_PATH"
139-
LOG_INFO "========================end 前端配置说明 end========================"
125+
LOG_INFO "============================前端配置说明============================"
126+
LOG_INFO "| 前端服务端口: TCA_WEB_PORT --- $TCA_WEB_PORT"
127+
LOG_INFO "| 前端服务SERVER_NAME: TCA_WEB_HOST --- $TCA_WEB_HOST"
128+
LOG_INFO "| 前端服务访问的后端地址: SERVER_ENV --- $TCA_SERVER_ADDR"
129+
LOG_INFO "| 前端服务NGINX配置地址: NGINX_CONF_PATH --- $NGINX_CONF_PATH"
130+
LOG_INFO "| 前端服务资源部署地址: WEB_DEPLOY_PATH --- $TCA_WEB_DEPLOY_PATH"
131+
LOG_INFO "| 前端服务日志地址: NGINX_LOG_PATH --- $NGINX_LOG_PATH"
132+
LOG_INFO "========================end 前端配置说明 end========================"
140133
}
141134

142135
function init_web_config() {
143-
check_unzip_command || error_exit "unzip command not installed"
144-
clear_old_nginx_conf
145-
clear_assets
146-
init_unzip_build
147-
init_framework_web
148-
init_web_nginx
149-
log_env
136+
# 校验是否存在unzip命令
137+
command_exists unzip || error_exit "unzip command not installed"
138+
clear_assets
139+
init_unzip_build
140+
init_framework_web
141+
init_web_nginx
142+
log_env
150143
}

web/packages/shared/component/authority/index.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,17 @@ interface AuthorityProps {
2929
selectStyle?: any;
3030
placeholder?: string;
3131
required?: boolean;
32+
allowClear?: boolean;
3233
}
3334

3435
const Authority = (props: AuthorityProps) => {
35-
const { form, name, label, initAuth, getAuthList, selectStyle = {}, placeholder, required } = props;
36+
const { form, name, label, initAuth, getAuthList, selectStyle = {}, placeholder, required, allowClear } = props;
3637
const [sshAuthList, setSshAuthList] = useState<any>([]);
3738
const [httpAuthList, setHttpAuthList] = useState<any>([]);
3839
const [oauthAuthList, setOauthAuthList] = useState<any>([]);
3940
const [authLoading, setAuthLoading] = useState(false);
4041

41-
const setCurAuth = (sshList = sshAuthList, httpList = httpAuthList) => {
42+
const setCurAuth = (sshList = sshAuthList, httpList = httpAuthList, oauthList = oauthAuthList) => {
4243
// 设置初始值
4344
if (initAuth[SCM_MAP[initAuth.auth_type]]?.id) {
4445
form.setFieldsValue({ [name]: `${initAuth.auth_type}#${initAuth[SCM_MAP[initAuth.auth_type]]?.id}` });
@@ -59,6 +60,13 @@ const Authority = (props: AuthorityProps) => {
5960
) {
6061
setHttpAuthList([initAuth.scm_account, ...httpList]);
6162
}
63+
if (
64+
initAuth.scm_oauth
65+
&& initAuth.auth_type === AUTH_TYPE.OAUTH
66+
&& !find(oauthAuthList, { id: initAuth.scm_oauth?.id })
67+
) {
68+
setOauthAuthList([initAuth.scm_oauth, ...oauthList]);
69+
}
6270
};
6371

6472
const getAuth = () => {
@@ -104,6 +112,7 @@ const Authority = (props: AuthorityProps) => {
104112
placeholder={placeholder}
105113
getPopupContainer={() => document.body}
106114
optionLabelProp="label"
115+
allowClear={allowClear}
107116
>
108117
{!isEmpty(oauthAuthList) && (
109118
<OptGroup label={AUTH_TYPE_TXT.OAUTH}>

web/packages/shared/component/search/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ const Search = ({
103103
Object.keys(searchParams).forEach((key) => {
104104
params[key] = '';
105105
});
106+
form.setFieldsValue(params);
106107
onRouteHandle(params);
107108
callback?.(params);
108109
};

web/packages/tca-layout/src/constant/index.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ export const DEFAULT_TEAM_PAGER = {
2020

2121
export enum RepoTypeEnum {
2222
GIT = 'git',
23-
SVN = 'svn'
23+
SVN = 'svn',
24+
ZIP = 'link'
2425
}
2526

2627
export const REPO_TYPE_CHOICES = {
@@ -29,3 +30,11 @@ export const REPO_TYPE_CHOICES = {
2930
};
3031

3132
export const REPO_TYPE_OPTIONS = generateOptions(REPO_TYPE_CHOICES);
33+
34+
export const TOOLLIB_REPO_TYPE_CHOICES = {
35+
[RepoTypeEnum.GIT]: 'GIT',
36+
[RepoTypeEnum.SVN]: 'SVN',
37+
[RepoTypeEnum.ZIP]: 'ZIP',
38+
};
39+
40+
export const TOOLLIB_REPO_TYPE_OPTIONS = generateOptions(TOOLLIB_REPO_TYPE_CHOICES);

web/packages/tca-layout/src/modules/nodes/node-tasks-modal.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ const NodeTaskModal = ({ visible, nodeId, onCancel }: NodeTaskModalProps) => {
100100
title={t('子任务')}
101101
dataIndex="task_name"
102102
width={100}
103+
render={(taskName: string) => (
104+
<EllipsisTemplate maxWidth={100}>
105+
{taskName}
106+
</EllipsisTemplate>
107+
)}
103108
/>
104109
<Column
105110
title={t('执行状态')}

web/packages/tca-layout/src/modules/tool-libs/create-libs.tsx

Lines changed: 45 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ import { isEmpty, fromPairs, toPairs, get } from 'lodash';
66
import { Modal, Form, Input, Select, Tooltip, Button, message, Space } from 'coding-oa-uikit';
77
import TrashIcon from 'coding-oa-uikit/lib/icon/Trash';
88
import QuestionCircle from 'coding-oa-uikit/lib/icon/QuestionCircle';
9+
import AttentionIcon from 'coding-oa-uikit/lib/icon/AttentionRed';
910
import Authority from '@tencent/micro-frontend-shared/component/authority';
1011
import { UserAPI } from '@plat/api';
1112

1213
import { addToolLib, getLibDetail, updateToolLib } from '@src/services/tools';
13-
import { REPO_TYPE_OPTIONS, RepoTypeEnum, SCM_MAP, LIB_ENV, LIB_TYPE } from '@src/constant';
14+
import { TOOLLIB_REPO_TYPE_OPTIONS, RepoTypeEnum, SCM_MAP, LIB_ENV, LIB_TYPE } from '@src/constant';
1415

1516
import style from './style.scss';
1617

@@ -35,18 +36,20 @@ const CreateToollibs = (props: CreateToollibsProps) => {
3536
const { orgSid, visible, libId, isSuperuser, onClose, callback } = props;
3637
const [form] = Form.useForm();
3738
const [detail, setDetail] = useState<any>({});
39+
const [zipWarningVisible, setZipWarningVisible] = useState<boolean>(false);
3840
const isEdit = !!libId;
3941

4042
useEffect(() => {
4143
if (visible && libId) {
42-
getLibDetail(orgSid, libId).then((res) => {
44+
getLibDetail(orgSid, libId).then((res: any) => {
4345
setDetail(res);
46+
setZipWarningVisible(res?.scm_type === RepoTypeEnum.ZIP);
4447
form.resetFields();
4548
});
46-
}
47-
48-
if (visible) {
49+
} else if (visible) {
4950
form.resetFields();
51+
setDetail({});
52+
setZipWarningVisible(false);
5053
}
5154
}, [visible]);
5255

@@ -184,16 +187,15 @@ const CreateToollibs = (props: CreateToollibsProps) => {
184187
label="依赖仓库地址"
185188
name="scm_url"
186189
required
190+
help={zipWarningVisible && <span style={{ color: '#eb333f' }}><AttentionIcon />请勿使用不明来源的文件链接,避免潜在的安全风险。</span>}
187191
>
188192
<Input.Group compact>
189193
<Form.Item name='scm_type' noStyle>
190-
<Select style={{ width: '15%' }}>
191-
{REPO_TYPE_OPTIONS.map((item: any, index: number) => (
192-
<Option key={index} value={item.value}>
193-
{item.label}
194-
</Option>
195-
))}
196-
</Select>
194+
<Select
195+
style={{ width: '16%' }}
196+
onChange={(value: RepoTypeEnum) => setZipWarningVisible(value === RepoTypeEnum.ZIP)}
197+
options={TOOLLIB_REPO_TYPE_OPTIONS}
198+
/>
197199
</Form.Item>
198200
<Form.Item
199201
name='scm_url'
@@ -202,32 +204,40 @@ const CreateToollibs = (props: CreateToollibsProps) => {
202204
{ required: true, message: '依赖仓库地址' },
203205
]}
204206
>
205-
<Input style={{ width: '85%' }} />
207+
<Input style={{ width: '84%' }} />
206208
</Form.Item>
207209
</Input.Group>
208210
</Form.Item>
209-
<Authority
210-
form={form}
211-
name='scm'
212-
label={(
213-
<span>
214-
凭证
215-
<Tooltip
216-
getPopupContainer={() => document.body}
217-
title='拉取依赖仓库所需的凭证,如果是github公开仓库,可以不提供凭证。'
218-
><QuestionCircle className={style.questionIcon} /></Tooltip>
219-
</span>
220-
)}
221-
getAuthList={[
222-
UserAPI.authSSH().get,
223-
UserAPI.authAccount().get,
224-
UserAPI.getOAuthInfos,
225-
UserAPI.getPlatformStatus,
226-
]}
227-
initAuth={detail.scm_auth}
228-
selectStyle={{ width: 360 }}
229-
placeholder='github公开仓库可不提供凭证'
230-
/>
211+
<Form.Item
212+
noStyle
213+
shouldUpdate={(prevValues: any, currentValues: any) => prevValues.scm_type !== currentValues.scm_type
214+
}
215+
>
216+
{({ getFieldValue }: { getFieldValue: any }) => (getFieldValue('scm_type') !== RepoTypeEnum.ZIP && (
217+
<Authority
218+
form={form}
219+
name='scm'
220+
label={(
221+
<span>
222+
凭证
223+
<Tooltip
224+
getPopupContainer={() => document.body}
225+
title='拉取依赖仓库所需的凭证,如果是github公开仓库,可以不提供凭证。'
226+
><QuestionCircle className={style.questionIcon} /></Tooltip>
227+
</span>
228+
)}
229+
getAuthList={[
230+
UserAPI.authSSH().get,
231+
UserAPI.authAccount().get,
232+
UserAPI.getOAuthInfos,
233+
UserAPI.getPlatformStatus,
234+
]}
235+
initAuth={detail.scm_auth}
236+
selectStyle={{ width: 360 }}
237+
placeholder='github公开仓库可不提供凭证'
238+
/>
239+
))}
240+
</Form.Item>
231241
<Form.Item
232242
name="envs"
233243
label={(

web/packages/tca-layout/src/modules/tool-libs/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ export const ToolLibs = () => {
134134
<Column
135135
title='依赖系统'
136136
dataIndex='lib_os'
137-
render={(os: string) => os.split(';').map((item: string) => (
137+
render={(os: string) => os?.split(';').map((item: string) => (
138138
<Tag key={item}>{get(LIB_ENV, item, item)}</Tag>
139139
))}
140140
/>

0 commit comments

Comments
 (0)