From 76571a6b0b57238bdd72d668de4cc8b1aa2ac1d8 Mon Sep 17 00:00:00 2001 From: icechen Date: Thu, 30 Dec 2021 00:41:38 +0800 Subject: [PATCH] update --- config_handler/config_handler.go | 4 ++-- config_handler/real_config.go | 11 ++++++++++- config_handler/service_config.go | 13 ++----------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/config_handler/config_handler.go b/config_handler/config_handler.go index 19736c1..d998a28 100644 --- a/config_handler/config_handler.go +++ b/config_handler/config_handler.go @@ -54,7 +54,7 @@ func (p *plugin) Find(ctx context.Context, req *config.Request) (*drone.Config, // 4. 根据文件树以及原始配置文件的信息,组装需要构建的服务的ci信息 // 4.1 api modifiedApiList := getModifiedApi(cfg.Api, modifiedFileList) - destinationApi, err := modifiedApiList.toDestinationConfig(cfg.Name, cfg.Service.toServiceEnv()) + destinationApi, err := modifiedApiList.toDestinationConfig(cfg.Name, cfg.toServiceEnv()) if err != nil { logrus.Error(err) return nil, err @@ -62,7 +62,7 @@ func (p *plugin) Find(ctx context.Context, req *config.Request) (*drone.Config, // 4.2 service modifiedServiceList := getModifiedService(cfg.Service, modifiedFileList) - destinationService, err := modifiedServiceList.toDestinationConfig(cfg.Name) + destinationService, err := modifiedServiceList.toDestinationConfig(cfg.Name, cfg.toServiceEnv()) if err != nil { logrus.Error(err) return nil, err diff --git a/config_handler/real_config.go b/config_handler/real_config.go index 4209ddf..6f59a16 100644 --- a/config_handler/real_config.go +++ b/config_handler/real_config.go @@ -3,6 +3,7 @@ package config_handler import ( "git.icechen.cn/pkg/drone_plugin/git" "gopkg.in/yaml.v3" + "strings" ) const TypeMonorepo = "monorepo" // 单库类型 @@ -15,6 +16,15 @@ type Config struct { Service ServiceList `json:"service" yaml:"service"` } +func (c Config) toServiceEnv() map[string]string { + sl := c.Service + retMap := make(map[string]string) + for _, service := range sl { + retMap[strings.ToUpper("SERVICE_"+service.Name)] = c.Name + "-" + service.Name + ":" + service.Port + } + return retMap +} + type ( ApiList []Api Api struct { @@ -24,7 +34,6 @@ type ( Port string `json:"port" yaml:"port"` } ) - type ( ServiceList []Service Service struct { diff --git a/config_handler/service_config.go b/config_handler/service_config.go index b7db56c..379de54 100644 --- a/config_handler/service_config.go +++ b/config_handler/service_config.go @@ -2,21 +2,12 @@ package config_handler import ( "git.icechen.cn/pkg/drone_plugin/go_handler" - "strings" ) -func (sl ServiceList) toServiceEnv() map[string]string { - retMap := make(map[string]string) - for _, service := range sl { - retMap[strings.ToUpper("SERVICE_"+service.Name)] = service.Name + ":" + service.Port - } - return retMap -} - -func (sl ServiceList) toDestinationConfig(nameSpace string) (string, error) { +func (sl ServiceList) toDestinationConfig(nameSpace string, serviceEnv map[string]string) (string, error) { retConfig := "" for _, service := range sl { - config, err := service.toDestinationConfig(nameSpace, sl.toServiceEnv()) + config, err := service.toDestinationConfig(nameSpace, serviceEnv) if err != nil { return "", err }