From 419d2cf287a395a6b5d22b431670dab87f8fd733 Mon Sep 17 00:00:00 2001 From: ifooth Date: Tue, 2 Jul 2024 17:33:23 +0800 Subject: [PATCH 1/4] feat: add BKSharedResBaseJSURL conf --- bcs-services/bcs-bscp/cmd/ui/etc/bscp-ui.yml | 23 ++++++---- bcs-services/bcs-bscp/cmd/ui/service/web.go | 23 +++++----- bcs-services/bcs-bscp/embed.go | 46 ++++++++++---------- bcs-services/bcs-bscp/pkg/config/config.go | 3 ++ bcs-services/bcs-bscp/pkg/config/web.go | 29 ++++++++++-- 5 files changed, 78 insertions(+), 46 deletions(-) diff --git a/bcs-services/bcs-bscp/cmd/ui/etc/bscp-ui.yml b/bcs-services/bcs-bscp/cmd/ui/etc/bscp-ui.yml index d718aca29a..14d1de2e6b 100644 --- a/bcs-services/bcs-bscp/cmd/ui/etc/bscp-ui.yml +++ b/bcs-services/bcs-bscp/cmd/ui/etc/bscp-ui.yml @@ -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: "" - + bk_shared_res_url: "" 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: "" + helper: "" + enable_bk_notice: false diff --git a/bcs-services/bcs-bscp/cmd/ui/service/web.go b/bcs-services/bcs-bscp/cmd/ui/service/web.go index 2821b0d053..46d3120e36 100644 --- a/bcs-services/bcs-bscp/cmd/ui/service/web.go +++ b/bcs-services/bcs-bscp/cmd/ui/service/web.go @@ -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, + BKSharedResBaseJSURL: config.G.Web.BKSharedResBaseJSURL, + 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, } if shouldProxyAPI { diff --git a/bcs-services/bcs-bscp/embed.go b/bcs-services/bcs-bscp/embed.go index 73b3dd8a84..13ec50825f 100644 --- a/bcs-services/bcs-bscp/embed.go +++ b/bcs-services/bcs-bscp/embed.go @@ -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}/${目录名 aks app_code}/base.js + NodeManHost string } // EmbedWebServer 前端 web server @@ -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, } // 本地开发模式 / 代理请求 diff --git a/bcs-services/bcs-bscp/pkg/config/config.go b/bcs-services/bcs-bscp/pkg/config/config.go index 500b8c3f5f..b59907af79 100644 --- a/bcs-services/bcs-bscp/pkg/config/config.go +++ b/bcs-services/bcs-bscp/pkg/config/config.go @@ -41,6 +41,9 @@ func (c *Configuration) init() error { if err := c.Web.init(); err != nil { return err } + if err := c.Web.initResBaseJSURL(c.Base.AppCode); err != nil { + return err + } return nil } diff --git a/bcs-services/bcs-bscp/pkg/config/web.go b/bcs-services/bcs-bscp/pkg/config/web.go index c6481494a2..bd436c668b 100644 --- a/bcs-services/bcs-bscp/pkg/config/web.go +++ b/bcs-services/bcs-bscp/pkg/config/web.go @@ -13,16 +13,19 @@ package config import ( + "fmt" "net/url" "path" ) // WebConf web 相关配置 type WebConf struct { - Host string `yaml:"host"` - RoutePrefix string `yaml:"route_prefix"` // vue路由, 静态资源前缀 - PreferredDomains string `yaml:"preferred_domains"` - BaseURL *url.URL `yaml:"-"` + Host string `yaml:"host"` + RoutePrefix string `yaml:"route_prefix"` // vue路由, 静态资源前缀 + PreferredDomains string `yaml:"preferred_domains"` + BaseURL *url.URL `yaml:"-"` + BKSharedResURL string `yaml:"bk_shared_res_url"` // 对应运维公共变量bkSharedResUrl, PaaS环境变量BKPAAS_SHARED_RES_URL + BKSharedResBaseJSURL string `yaml:"-"` // 规则是${bkSharedResUrl}/${目录名 aks app_code}/base.js } // init 初始化 @@ -37,6 +40,24 @@ func (c *WebConf) init() error { return nil } +func (c *WebConf) initResBaseJSURL(appCode string) error { + if c.BKSharedResURL == "" { + return nil + } + if appCode == "" { + return fmt.Errorf("initResBaseJSURL: app_code is required") + } + + u, err := url.Parse(c.BKSharedResURL) + if err != nil { + return err + } + u.Path = path.Join(u.Path, appCode, "base.js") + + c.BKSharedResBaseJSURL = u.String() + return nil +} + // defaultWebConf 默认配置 func defaultWebConf() *WebConf { c := &WebConf{ From dd3113f8a554dca7d93ed0a35d99a1843765eaaf Mon Sep 17 00:00:00 2001 From: ifooth Date: Tue, 2 Jul 2024 17:47:17 +0800 Subject: [PATCH 2/4] feat: add BKSharedResBaseJSURL conf --- bcs-services/bcs-bscp/cmd/ui/etc/bscp-ui.yml | 2 +- bcs-services/bcs-bscp/cmd/ui/service/web.go | 2 +- bcs-services/bcs-bscp/pkg/config/config.go | 2 +- bcs-services/bcs-bscp/pkg/config/frontend.go | 34 +++++++++++++++++--- bcs-services/bcs-bscp/pkg/config/web.go | 29 +++-------------- 5 files changed, 37 insertions(+), 32 deletions(-) diff --git a/bcs-services/bcs-bscp/cmd/ui/etc/bscp-ui.yml b/bcs-services/bcs-bscp/cmd/ui/etc/bscp-ui.yml index 14d1de2e6b..796bfa66bf 100644 --- a/bcs-services/bcs-bscp/cmd/ui/etc/bscp-ui.yml +++ b/bcs-services/bcs-bscp/cmd/ui/etc/bscp-ui.yml @@ -10,7 +10,6 @@ web: host: "" route_prefix: "" preferred_domains: "" - bk_shared_res_url: "" etcd: endpoints: 127.0.0.1:2379 ca: "" @@ -23,5 +22,6 @@ frontend_conf: bk_cmdb_host: "" bscp_api_url: "" bk_nodeman_host: "" + bk_shared_res_url: "" helper: "" enable_bk_notice: false diff --git a/bcs-services/bcs-bscp/cmd/ui/service/web.go b/bcs-services/bcs-bscp/cmd/ui/service/web.go index 46d3120e36..c4fbeba375 100644 --- a/bcs-services/bcs-bscp/cmd/ui/service/web.go +++ b/bcs-services/bcs-bscp/cmd/ui/service/web.go @@ -179,10 +179,10 @@ func (s *WebServer) subRouter() http.Handler { RunEnv: config.G.Base.RunEnv, ProxyAPI: shouldProxyAPI, SiteURL: config.G.Web.RoutePrefix, - BKSharedResBaseJSURL: config.G.Web.BKSharedResBaseJSURL, 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, diff --git a/bcs-services/bcs-bscp/pkg/config/config.go b/bcs-services/bcs-bscp/pkg/config/config.go index b59907af79..b1da5d64ca 100644 --- a/bcs-services/bcs-bscp/pkg/config/config.go +++ b/bcs-services/bcs-bscp/pkg/config/config.go @@ -41,7 +41,7 @@ func (c *Configuration) init() error { if err := c.Web.init(); err != nil { return err } - if err := c.Web.initResBaseJSURL(c.Base.AppCode); err != nil { + if err := c.Frontend.initResBaseJSURL(c.Base.AppCode); err != nil { return err } diff --git a/bcs-services/bcs-bscp/pkg/config/frontend.go b/bcs-services/bcs-bscp/pkg/config/frontend.go index ab0961b733..ef27143f7c 100644 --- a/bcs-services/bcs-bscp/pkg/config/frontend.go +++ b/bcs-services/bcs-bscp/pkg/config/frontend.go @@ -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 @@ -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 +} diff --git a/bcs-services/bcs-bscp/pkg/config/web.go b/bcs-services/bcs-bscp/pkg/config/web.go index bd436c668b..c6481494a2 100644 --- a/bcs-services/bcs-bscp/pkg/config/web.go +++ b/bcs-services/bcs-bscp/pkg/config/web.go @@ -13,19 +13,16 @@ package config import ( - "fmt" "net/url" "path" ) // WebConf web 相关配置 type WebConf struct { - Host string `yaml:"host"` - RoutePrefix string `yaml:"route_prefix"` // vue路由, 静态资源前缀 - PreferredDomains string `yaml:"preferred_domains"` - BaseURL *url.URL `yaml:"-"` - BKSharedResURL string `yaml:"bk_shared_res_url"` // 对应运维公共变量bkSharedResUrl, PaaS环境变量BKPAAS_SHARED_RES_URL - BKSharedResBaseJSURL string `yaml:"-"` // 规则是${bkSharedResUrl}/${目录名 aks app_code}/base.js + Host string `yaml:"host"` + RoutePrefix string `yaml:"route_prefix"` // vue路由, 静态资源前缀 + PreferredDomains string `yaml:"preferred_domains"` + BaseURL *url.URL `yaml:"-"` } // init 初始化 @@ -40,24 +37,6 @@ func (c *WebConf) init() error { return nil } -func (c *WebConf) initResBaseJSURL(appCode string) error { - if c.BKSharedResURL == "" { - return nil - } - if appCode == "" { - return fmt.Errorf("initResBaseJSURL: app_code is required") - } - - u, err := url.Parse(c.BKSharedResURL) - if err != nil { - return err - } - u.Path = path.Join(u.Path, appCode, "base.js") - - c.BKSharedResBaseJSURL = u.String() - return nil -} - // defaultWebConf 默认配置 func defaultWebConf() *WebConf { c := &WebConf{ From d99d1f48e9409f766948b7f10ac90209ae40dfd5 Mon Sep 17 00:00:00 2001 From: ifooth Date: Tue, 2 Jul 2024 17:52:06 +0800 Subject: [PATCH 3/4] feat: add BKSharedResBaseJSURL conf --- bcs-services/bcs-bscp/embed.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bcs-services/bcs-bscp/embed.go b/bcs-services/bcs-bscp/embed.go index 13ec50825f..c2cd26971f 100644 --- a/bcs-services/bcs-bscp/embed.go +++ b/bcs-services/bcs-bscp/embed.go @@ -57,7 +57,7 @@ type IndexConfig struct { Helper string ProxyAPI bool FeedAddr string - BKSharedResBaseJSURL string // 规则是${bkSharedResUrl}/${目录名 aks app_code}/base.js + BKSharedResBaseJSURL string // 规则是${bkSharedResUrl}/${目录名 aka app_code}/base.js NodeManHost string } From 7d49a3b91a87d260089f34dc07a0b8effae8f0fc Mon Sep 17 00:00:00 2001 From: ifooth Date: Wed, 3 Jul 2024 11:48:44 +0800 Subject: [PATCH 4/4] feat: add BKSharedResBaseJSURL conf --- bcs-services/bcs-bscp/pkg/config/frontend.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bcs-services/bcs-bscp/pkg/config/frontend.go b/bcs-services/bcs-bscp/pkg/config/frontend.go index ef27143f7c..dcd4052abb 100644 --- a/bcs-services/bcs-bscp/pkg/config/frontend.go +++ b/bcs-services/bcs-bscp/pkg/config/frontend.go @@ -26,7 +26,7 @@ type HostConf struct { 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 + BKSharedResBaseJSURL string `yaml:"-"` // 规则是${bkSharedResUrl}/${目录名 aka app_code}/base.js } // FrontendConf docs and host conf