Skip to content

Commit

Permalink
Merge pull request #620 from nickcdon/main
Browse files Browse the repository at this point in the history
🔧 调整前端部署脚本
  • Loading branch information
Lingghh committed Sep 20, 2022
2 parents d9e99ea + 9fdad3a commit a9ec312
Show file tree
Hide file tree
Showing 11 changed files with 207 additions and 155 deletions.
103 changes: 48 additions & 55 deletions scripts/web/init.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
#!/usr/bin/env bash
#!/bin/bash

CURRENT_SCRIPT_PATH=$(cd "$(dirname "${BASH_SOURCE[0]}")";pwd)
TCA_SCRIPT_ROOT=${TCA_SCRIPT_ROOT:-"$(cd $(dirname $CURRENT_SCRIPT_PATH); pwd)"}
export TCA_PROJECT_PATH=${TCA_PROJECT_PATH:-"$( cd $(dirname $TCA_SCRIPT_ROOT); pwd )"}
set -eo pipefail

# 当前脚本执行目录
CURRENT_SCRIPT_PATH=$(
cd "$(dirname "${BASH_SOURCE[0]}")"
pwd
)

TCA_SCRIPT_ROOT=${TCA_SCRIPT_ROOT:-"$(dirname "${CURRENT_SCRIPT_PATH}")"}

export TCA_PROJECT_PATH=${TCA_PROJECT_PATH:-"$(dirname "${TCA_SCRIPT_ROOT}")"}
export TCA_WEB_PATH=$TCA_PROJECT_PATH/web
export TCA_WEB_DEPLOY_SOURCE_PATH=$TCA_WEB_PATH/tca-deploy-source

source $TCA_SCRIPT_ROOT/utils.sh
source $TCA_SCRIPT_ROOT/config.sh
# shellcheck disable=SC1091
source "$TCA_SCRIPT_ROOT"/utils.sh
# shellcheck disable=SC1091
source "$TCA_SCRIPT_ROOT"/config.sh

# 微前端基座
MICRO_FRONTEND_FRAMEWORK="framework"
Expand All @@ -16,52 +26,35 @@ MICRO_FRONTEND_DOCUMENT="tca-document"
# 子微前端
MICRO_FRONTEND_APPS="login tca-layout tca-analysis tca-manage"

function check_unzip_command() {
if command_exists unzip; then
return 0
else
return 1
fi
}

# 由于原来各个微前端采用了不同的nginx conf,后为简化开源版前端部署已重新调整配置,为兼容旧版此处默认使用清楚逻辑
function clear_old_nginx_conf() {
# 清除各个应用的nginx conf文件
MICRO_FRONTEND="$MICRO_FRONTEND_FRAMEWORK $MICRO_FRONTEND_APPS $MICRO_FRONTEND_DOCUMENT"
for app in $MICRO_FRONTEND; do
rm -f $NGINX_CONF_PATH/$app.conf
done
}

# 清理资源文件
function clear_assets() {
LOG_WARN "将路径下的资源文件和前端nginx配置备份到 ${TCA_WEB_DEPLOY_PATH}_bak 下..."
if [ -d "$TCA_WEB_DEPLOY_PATH" ]; then
cp -r $TCA_WEB_DEPLOY_PATH/ ${TCA_WEB_DEPLOY_PATH}_bak/
cp -r "$TCA_WEB_DEPLOY_PATH"/ "${TCA_WEB_DEPLOY_PATH}"_bak/
fi

if [ -d "$NGINX_CONF_PATH/tca_ingress.conf" ]; then
cp -r $NGINX_CONF_PATH/tca_ingress.conf ${TCA_WEB_DEPLOY_PATH}_bak/
cp -r "$NGINX_CONF_PATH"/tca_ingress.conf "${TCA_WEB_DEPLOY_PATH}"_bak/
fi

LOG_INFO "开始清理路径下的资源文件 $TCA_WEB_DEPLOY_PATH ..."
rm -rf $TCA_WEB_DEPLOY_PATH/
rm -rf "${TCA_WEB_DEPLOY_PATH:?}"/
LOG_INFO "开始清理前端nginx配置 ..."
rm -f $NGINX_CONF_PATH/tca_ingress.conf
rm -f "$NGINX_CONF_PATH"/tca_ingress.conf
}

# 解压编译后文件
function init_unzip_build() {
LOG_INFO "解压编译后文件到 $TCA_WEB_DEPLOY_PATH ..."
rm -rf $TCA_WEB_DEPLOY_PATH/
mkdir -p $TCA_WEB_DEPLOY_PATH
cd $TCA_WEB_DEPLOY_SOURCE_PATH/build_zip/
rm -rf "${TCA_WEB_DEPLOY_PATH:?}"/
mkdir -p "$TCA_WEB_DEPLOY_PATH"
cd "$TCA_WEB_DEPLOY_SOURCE_PATH"/build_zip/
# 遍历并解压
MICRO_FRONTEND="$MICRO_FRONTEND_FRAMEWORK $MICRO_FRONTEND_APPS $MICRO_FRONTEND_DOCUMENT"
for app in $MICRO_FRONTEND; do
unzip -q -o $app.zip -d $TCA_WEB_DEPLOY_PATH/$app
unzip -q -o "$app".zip -d "$TCA_WEB_DEPLOY_PATH"/"$app"
done
cd $TCA_WEB_DEPLOY_SOURCE_PATH
cd "$TCA_WEB_DEPLOY_SOURCE_PATH"
}

# 初始化配置 framework
Expand All @@ -85,8 +78,8 @@ function init_framework_web() {
"
LOG_INFO "[INFO]:index.html RUNTIME is enabled"
LOG_INFO "[INFO]: change 404.html, unsupported-browser.html"
sed -i "$replace_content" $FRAMEWORK_DEPLOY_PATH/404.html
sed -i "$replace_content" $FRAMEWORK_DEPLOY_PATH/unsupported-browser.html
sed -i "$replace_content" "$FRAMEWORK_DEPLOY_PATH"/404.html
sed -i "$replace_content" "$FRAMEWORK_DEPLOY_PATH"/unsupported-browser.html

LOG_INFO "[INFO]: change index.html"
sed \
Expand All @@ -95,12 +88,12 @@ function init_framework_web() {
s|__MICRO_FRONTEND_API__|$MICRO_FRONTEND_API|g; \
s|__MICRO_FRONTEND_SETTING_API__|$MICRO_FRONTEND_SETTING_API|g; \
" \
$FRAMEWORK_DEPLOY_PATH/index.runtime.html >$FRAMEWORK_DEPLOY_PATH/index.html
"$FRAMEWORK_DEPLOY_PATH"/index.runtime.html >"$FRAMEWORK_DEPLOY_PATH"/index.html

LOG_INFO "conf 配置迁移 ..."
# 将conf目录中的配置文件拷贝到 $MICRO_FRONTEND_FRAMEWORK static目录下
cp $TCA_WEB_DEPLOY_SOURCE_PATH/conf/settings.json $FRAMEWORK_DEPLOY_PATH/static/settings.json
cp $TCA_WEB_DEPLOY_SOURCE_PATH/conf/configs.json $FRAMEWORK_DEPLOY_PATH/static/configs.json
cp "$TCA_WEB_DEPLOY_SOURCE_PATH"/conf/settings.json "$FRAMEWORK_DEPLOY_PATH"/static/settings.json
cp "$TCA_WEB_DEPLOY_SOURCE_PATH"/conf/configs.json "$FRAMEWORK_DEPLOY_PATH"/static/configs.json
LOG_INFO "$MICRO_FRONTEND_FRAMEWORK 配置完毕"
}

Expand All @@ -111,7 +104,7 @@ function init_web_nginx() {
if [ "$IS_DOCKER" == "TRUE" ]; then
SET_DEFAULT_SERVER="default_server"
fi
apps=$(echo $MICRO_FRONTEND_APPS | sed 's/[ ]/\\|/g')
apps=$(echo "$MICRO_FRONTEND_APPS" | sed 's/[ ]/\\|/g')
sed \
"
s|SERVER_NAME|$TCA_WEB_HOST|g; \
Expand All @@ -124,27 +117,27 @@ function init_web_nginx() {
s|MICRO_FRONTEND_DOCUMENT|$MICRO_FRONTEND_DOCUMENT|g; \
s|MICRO_FRONTEND_APPS|$apps|g; \
" \
$TCA_WEB_DEPLOY_SOURCE_PATH/nginx/ingress.conf >$NGINX_CONF_PATH/tca_ingress.conf
"$TCA_WEB_DEPLOY_SOURCE_PATH"/nginx/ingress.conf >"$NGINX_CONF_PATH"/tca_ingress.conf
}

# 打印环境变量配置
function log_env() {
LOG_INFO "============================前端配置说明============================"
LOG_INFO "| 前端服务端口: TCA_WEB_PORT --- $TCA_WEB_PORT"
LOG_INFO "| 前端服务SERVER_NAME: TCA_WEB_HOST --- $TCA_WEB_HOST"
LOG_INFO "| 前端服务访问的后端地址: SERVER_ENV --- $TCA_SERVER_ADDR"
LOG_INFO "| 前端服务NGINX配置地址: NGINX_CONF_PATH --- $NGINX_CONF_PATH"
LOG_INFO "| 前端服务资源部署地址: WEB_DEPLOY_PATH --- $TCA_WEB_DEPLOY_PATH"
LOG_INFO "| 前端服务日志地址: NGINX_LOG_PATH --- $NGINX_LOG_PATH"
LOG_INFO "========================end 前端配置说明 end========================"
LOG_INFO "============================前端配置说明============================"
LOG_INFO "| 前端服务端口: TCA_WEB_PORT --- $TCA_WEB_PORT"
LOG_INFO "| 前端服务SERVER_NAME: TCA_WEB_HOST --- $TCA_WEB_HOST"
LOG_INFO "| 前端服务访问的后端地址: SERVER_ENV --- $TCA_SERVER_ADDR"
LOG_INFO "| 前端服务NGINX配置地址: NGINX_CONF_PATH --- $NGINX_CONF_PATH"
LOG_INFO "| 前端服务资源部署地址: WEB_DEPLOY_PATH --- $TCA_WEB_DEPLOY_PATH"
LOG_INFO "| 前端服务日志地址: NGINX_LOG_PATH --- $NGINX_LOG_PATH"
LOG_INFO "========================end 前端配置说明 end========================"
}

function init_web_config() {
check_unzip_command || error_exit "unzip command not installed"
clear_old_nginx_conf
clear_assets
init_unzip_build
init_framework_web
init_web_nginx
log_env
# 校验是否存在unzip命令
command_exists unzip || error_exit "unzip command not installed"
clear_assets
init_unzip_build
init_framework_web
init_web_nginx
log_env
}
13 changes: 11 additions & 2 deletions web/packages/shared/component/authority/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,17 @@ interface AuthorityProps {
selectStyle?: any;
placeholder?: string;
required?: boolean;
allowClear?: boolean;
}

const Authority = (props: AuthorityProps) => {
const { form, name, label, initAuth, getAuthList, selectStyle = {}, placeholder, required } = props;
const { form, name, label, initAuth, getAuthList, selectStyle = {}, placeholder, required, allowClear } = props;
const [sshAuthList, setSshAuthList] = useState<any>([]);
const [httpAuthList, setHttpAuthList] = useState<any>([]);
const [oauthAuthList, setOauthAuthList] = useState<any>([]);
const [authLoading, setAuthLoading] = useState(false);

const setCurAuth = (sshList = sshAuthList, httpList = httpAuthList) => {
const setCurAuth = (sshList = sshAuthList, httpList = httpAuthList, oauthList = oauthAuthList) => {
// 设置初始值
if (initAuth[SCM_MAP[initAuth.auth_type]]?.id) {
form.setFieldsValue({ [name]: `${initAuth.auth_type}#${initAuth[SCM_MAP[initAuth.auth_type]]?.id}` });
Expand All @@ -59,6 +60,13 @@ const Authority = (props: AuthorityProps) => {
) {
setHttpAuthList([initAuth.scm_account, ...httpList]);
}
if (
initAuth.scm_oauth
&& initAuth.auth_type === AUTH_TYPE.OAUTH
&& !find(oauthAuthList, { id: initAuth.scm_oauth?.id })
) {
setOauthAuthList([initAuth.scm_oauth, ...oauthList]);
}
};

const getAuth = () => {
Expand Down Expand Up @@ -104,6 +112,7 @@ const Authority = (props: AuthorityProps) => {
placeholder={placeholder}
getPopupContainer={() => document.body}
optionLabelProp="label"
allowClear={allowClear}
>
{!isEmpty(oauthAuthList) && (
<OptGroup label={AUTH_TYPE_TXT.OAUTH}>
Expand Down
1 change: 1 addition & 0 deletions web/packages/shared/component/search/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ const Search = ({
Object.keys(searchParams).forEach((key) => {
params[key] = '';
});
form.setFieldsValue(params);
onRouteHandle(params);
callback?.(params);
};
Expand Down
11 changes: 10 additions & 1 deletion web/packages/tca-layout/src/constant/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ export const DEFAULT_TEAM_PAGER = {

export enum RepoTypeEnum {
GIT = 'git',
SVN = 'svn'
SVN = 'svn',
ZIP = 'link'
}

export const REPO_TYPE_CHOICES = {
Expand All @@ -29,3 +30,11 @@ export const REPO_TYPE_CHOICES = {
};

export const REPO_TYPE_OPTIONS = generateOptions(REPO_TYPE_CHOICES);

export const TOOLLIB_REPO_TYPE_CHOICES = {
[RepoTypeEnum.GIT]: 'GIT',
[RepoTypeEnum.SVN]: 'SVN',
[RepoTypeEnum.ZIP]: 'ZIP',
};

export const TOOLLIB_REPO_TYPE_OPTIONS = generateOptions(TOOLLIB_REPO_TYPE_CHOICES);
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ const NodeTaskModal = ({ visible, nodeId, onCancel }: NodeTaskModalProps) => {
title={t('子任务')}
dataIndex="task_name"
width={100}
render={(taskName: string) => (
<EllipsisTemplate maxWidth={100}>
{taskName}
</EllipsisTemplate>
)}
/>
<Column
title={t('执行状态')}
Expand Down
80 changes: 45 additions & 35 deletions web/packages/tca-layout/src/modules/tool-libs/create-libs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import { isEmpty, fromPairs, toPairs, get } from 'lodash';
import { Modal, Form, Input, Select, Tooltip, Button, message, Space } from 'coding-oa-uikit';
import TrashIcon from 'coding-oa-uikit/lib/icon/Trash';
import QuestionCircle from 'coding-oa-uikit/lib/icon/QuestionCircle';
import AttentionIcon from 'coding-oa-uikit/lib/icon/AttentionRed';
import Authority from '@tencent/micro-frontend-shared/component/authority';
import { UserAPI } from '@plat/api';

import { addToolLib, getLibDetail, updateToolLib } from '@src/services/tools';
import { REPO_TYPE_OPTIONS, RepoTypeEnum, SCM_MAP, LIB_ENV, LIB_TYPE } from '@src/constant';
import { TOOLLIB_REPO_TYPE_OPTIONS, RepoTypeEnum, SCM_MAP, LIB_ENV, LIB_TYPE } from '@src/constant';

import style from './style.scss';

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

useEffect(() => {
if (visible && libId) {
getLibDetail(orgSid, libId).then((res) => {
getLibDetail(orgSid, libId).then((res: any) => {
setDetail(res);
setZipWarningVisible(res?.scm_type === RepoTypeEnum.ZIP);
form.resetFields();
});
}

if (visible) {
} else if (visible) {
form.resetFields();
setDetail({});
setZipWarningVisible(false);
}
}, [visible]);

Expand Down Expand Up @@ -184,16 +187,15 @@ const CreateToollibs = (props: CreateToollibsProps) => {
label="依赖仓库地址"
name="scm_url"
required
help={zipWarningVisible && <span style={{ color: '#eb333f' }}><AttentionIcon />请勿使用不明来源的文件链接,避免潜在的安全风险。</span>}
>
<Input.Group compact>
<Form.Item name='scm_type' noStyle>
<Select style={{ width: '15%' }}>
{REPO_TYPE_OPTIONS.map((item: any, index: number) => (
<Option key={index} value={item.value}>
{item.label}
</Option>
))}
</Select>
<Select
style={{ width: '16%' }}
onChange={(value: RepoTypeEnum) => setZipWarningVisible(value === RepoTypeEnum.ZIP)}
options={TOOLLIB_REPO_TYPE_OPTIONS}
/>
</Form.Item>
<Form.Item
name='scm_url'
Expand All @@ -202,32 +204,40 @@ const CreateToollibs = (props: CreateToollibsProps) => {
{ required: true, message: '依赖仓库地址' },
]}
>
<Input style={{ width: '85%' }} />
<Input style={{ width: '84%' }} />
</Form.Item>
</Input.Group>
</Form.Item>
<Authority
form={form}
name='scm'
label={(
<span>
凭证
<Tooltip
getPopupContainer={() => document.body}
title='拉取依赖仓库所需的凭证,如果是github公开仓库,可以不提供凭证。'
><QuestionCircle className={style.questionIcon} /></Tooltip>
</span>
)}
getAuthList={[
UserAPI.authSSH().get,
UserAPI.authAccount().get,
UserAPI.getOAuthInfos,
UserAPI.getPlatformStatus,
]}
initAuth={detail.scm_auth}
selectStyle={{ width: 360 }}
placeholder='github公开仓库可不提供凭证'
/>
<Form.Item
noStyle
shouldUpdate={(prevValues: any, currentValues: any) => prevValues.scm_type !== currentValues.scm_type
}
>
{({ getFieldValue }: { getFieldValue: any }) => (getFieldValue('scm_type') !== RepoTypeEnum.ZIP && (
<Authority
form={form}
name='scm'
label={(
<span>
凭证
<Tooltip
getPopupContainer={() => document.body}
title='拉取依赖仓库所需的凭证,如果是github公开仓库,可以不提供凭证。'
><QuestionCircle className={style.questionIcon} /></Tooltip>
</span>
)}
getAuthList={[
UserAPI.authSSH().get,
UserAPI.authAccount().get,
UserAPI.getOAuthInfos,
UserAPI.getPlatformStatus,
]}
initAuth={detail.scm_auth}
selectStyle={{ width: 360 }}
placeholder='github公开仓库可不提供凭证'
/>
))}
</Form.Item>
<Form.Item
name="envs"
label={(
Expand Down
2 changes: 1 addition & 1 deletion web/packages/tca-layout/src/modules/tool-libs/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export const ToolLibs = () => {
<Column
title='依赖系统'
dataIndex='lib_os'
render={(os: string) => os.split(';').map((item: string) => (
render={(os: string) => os?.split(';').map((item: string) => (
<Tag key={item}>{get(LIB_ENV, item, item)}</Tag>
))}
/>
Expand Down
Loading

0 comments on commit a9ec312

Please sign in to comment.