Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add BKSharedResBaseJSURL conf #3331

Merged
merged 4 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions bcs-services/bcs-bscp/cmd/ui/etc/bscp-ui.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
base_conf:
app_code: ""
app_secret: ""
bk_paas_host: ""
time_zone: Asia/Shanghai
language_code: en
language_code: en-us
run_env: dev

bcs_conf:
host: ""
token: ""
jwt_public_key: ""

feed_addr: ""
web:
route_prefix: /bscp/ui
host: ""
route_prefix: ""
preferred_domains: ""

etcd:
endpoints: 127.0.0.1:2379
ca: ""
cert: ""
key: ""
frontend_conf:
docs: {}
hosts:
bk_iam_host: ""
bk_cmdb_host: ""
bscp_api_url: ""
bk_nodeman_host: ""
bk_shared_res_url: ""
helper: ""
enable_bk_notice: false
23 changes: 12 additions & 11 deletions bcs-services/bcs-bscp/cmd/ui/service/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,17 +175,18 @@ func (s *WebServer) subRouter() http.Handler {

shouldProxyAPI := config.G.IsDevMode()
conf := &bscp.IndexConfig{
StaticURL: path.Join(config.G.Web.RoutePrefix, "/web"),
RunEnv: config.G.Base.RunEnv,
ProxyAPI: shouldProxyAPI,
SiteURL: config.G.Web.RoutePrefix,
APIURL: config.G.Frontend.Host.BSCPAPIURL,
IAMHost: config.G.Frontend.Host.BKIAMHost,
CMDBHost: config.G.Frontend.Host.BKCMDBHost,
EnableBKNotice: config.G.Frontend.EnableBKNotice,
Helper: config.G.Frontend.Helper,
FeedAddr: config.G.Base.FeedAddr,
NodeManHost: config.G.Frontend.Host.BKNODEMANHOST,
StaticURL: path.Join(config.G.Web.RoutePrefix, "/web"),
RunEnv: config.G.Base.RunEnv,
ProxyAPI: shouldProxyAPI,
SiteURL: config.G.Web.RoutePrefix,
APIURL: config.G.Frontend.Host.BSCPAPIURL,
IAMHost: config.G.Frontend.Host.BKIAMHost,
CMDBHost: config.G.Frontend.Host.BKCMDBHost,
BKSharedResBaseJSURL: config.G.Frontend.Host.BKSharedResBaseJSURL,
EnableBKNotice: config.G.Frontend.EnableBKNotice,
Helper: config.G.Frontend.Helper,
FeedAddr: config.G.Base.FeedAddr,
NodeManHost: config.G.Frontend.Host.BKNODEMANHOST,
}

if shouldProxyAPI {
Expand Down
46 changes: 24 additions & 22 deletions bcs-services/bcs-bscp/embed.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,18 @@ var (

// IndexConfig 前端配置
type IndexConfig struct {
RunEnv string
StaticURL string
IAMHost string
CMDBHost string
APIURL string
SiteURL string // vue 路由前缀
EnableBKNotice bool // 是否启用蓝鲸通知中心
Helper string
ProxyAPI bool
FeedAddr string
NodeManHost string
RunEnv string
StaticURL string
IAMHost string
CMDBHost string
APIURL string
SiteURL string // vue 路由前缀
EnableBKNotice bool // 是否启用蓝鲸通知中心
Helper string
ProxyAPI bool
FeedAddr string
BKSharedResBaseJSURL string // 规则是${bkSharedResUrl}/${目录名 aka app_code}/base.js
NodeManHost string
}

// EmbedWebServer 前端 web server
Expand Down Expand Up @@ -159,17 +160,18 @@ func (e *EmbedWeb) RenderIndexHandler(conf *IndexConfig) http.Handler {

fn := func(w http.ResponseWriter, r *http.Request) {
tplData := map[string]string{
"BK_STATIC_URL": conf.StaticURL,
"RUN_ENV": conf.RunEnv,
"BK_BCS_BSCP_API": conf.APIURL,
"BK_IAM_HOST": conf.IAMHost,
"BK_CC_HOST": conf.CMDBHost,
"BK_BSCP_CONFIG": bscpConfig,
"SITE_URL": conf.SiteURL,
"ENABLE_BK_NOTICE": strconv.FormatBool(conf.EnableBKNotice),
"HELPER": conf.Helper,
"FEED_ADDR": conf.FeedAddr,
"BK_NODE_HOST": conf.NodeManHost,
"BK_STATIC_URL": conf.StaticURL,
"RUN_ENV": conf.RunEnv,
"BK_BCS_BSCP_API": conf.APIURL,
"BK_IAM_HOST": conf.IAMHost,
"BK_CC_HOST": conf.CMDBHost,
"BK_SHARED_RES_BASE_JS_URL": conf.BKSharedResBaseJSURL,
"BK_BSCP_CONFIG": bscpConfig,
"SITE_URL": conf.SiteURL,
"ENABLE_BK_NOTICE": strconv.FormatBool(conf.EnableBKNotice),
"HELPER": conf.Helper,
"FEED_ADDR": conf.FeedAddr,
"BK_NODE_HOST": conf.NodeManHost,
}

// 本地开发模式 / 代理请求
Expand Down
3 changes: 3 additions & 0 deletions bcs-services/bcs-bscp/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ func (c *Configuration) init() error {
if err := c.Web.init(); err != nil {
return err
}
if err := c.Frontend.initResBaseJSURL(c.Base.AppCode); err != nil {
return err
}

return nil
}
Expand Down
34 changes: 30 additions & 4 deletions bcs-services/bcs-bscp/pkg/config/frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,20 @@
// Package config xxx
package config

import (
"fmt"
"net/url"
"path"
)

// HostConf host conf
type HostConf struct {
BKIAMHost string `yaml:"bk_iam_host"` // 权限中心
BKCMDBHost string `yaml:"bk_cmdb_host"` // 配置平台
BSCPAPIURL string `yaml:"bscp_api_url"` // bscp api地址
BKNODEMANHOST string `yaml:"bk_nodeman_host"` // 节点管理地址
BKIAMHost string `yaml:"bk_iam_host"` // 权限中心
BKCMDBHost string `yaml:"bk_cmdb_host"` // 配置平台
BSCPAPIURL string `yaml:"bscp_api_url"` // bscp api地址
BKNODEMANHOST string `yaml:"bk_nodeman_host"` // 节点管理地址
BKSharedResURL string `yaml:"bk_shared_res_url"` // 对应运维公共变量bkSharedResUrl, PaaS环境变量BKPAAS_SHARED_RES_URL
BKSharedResBaseJSURL string `yaml:"-"` // 规则是${bkSharedResUrl}/${目录名 aks app_code}/base.js
}

// FrontendConf docs and host conf
Expand All @@ -37,3 +45,21 @@ func defaultUIConf() *FrontendConf {
}
return c
}

func (c *FrontendConf) initResBaseJSURL(appCode string) error {
if c.Host.BKSharedResURL == "" {
return nil
}
if appCode == "" {
return fmt.Errorf("initResBaseJSURL: app_code is required")
}

u, err := url.Parse(c.Host.BKSharedResURL)
if err != nil {
return err
}
u.Path = path.Join(u.Path, appCode, "base.js")

c.Host.BKSharedResBaseJSURL = u.String()
return nil
}
Loading