This commit is contained in:
		
							parent
							
								
									5a893702ee
								
							
						
					
					
						commit
						76571a6b0b
					
				| @ -54,7 +54,7 @@ func (p *plugin) Find(ctx context.Context, req *config.Request) (*drone.Config, | |||||||
| 	// 4. 根据文件树以及原始配置文件的信息,组装需要构建的服务的ci信息 | 	// 4. 根据文件树以及原始配置文件的信息,组装需要构建的服务的ci信息 | ||||||
| 	// 4.1 api | 	// 4.1 api | ||||||
| 	modifiedApiList := getModifiedApi(cfg.Api, modifiedFileList) | 	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 { | 	if err != nil { | ||||||
| 		logrus.Error(err) | 		logrus.Error(err) | ||||||
| 		return nil, err | 		return nil, err | ||||||
| @ -62,7 +62,7 @@ func (p *plugin) Find(ctx context.Context, req *config.Request) (*drone.Config, | |||||||
| 
 | 
 | ||||||
| 	// 4.2 service | 	// 4.2 service | ||||||
| 	modifiedServiceList := getModifiedService(cfg.Service, modifiedFileList) | 	modifiedServiceList := getModifiedService(cfg.Service, modifiedFileList) | ||||||
| 	destinationService, err := modifiedServiceList.toDestinationConfig(cfg.Name) | 	destinationService, err := modifiedServiceList.toDestinationConfig(cfg.Name, cfg.toServiceEnv()) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		logrus.Error(err) | 		logrus.Error(err) | ||||||
| 		return nil, err | 		return nil, err | ||||||
|  | |||||||
| @ -3,6 +3,7 @@ package config_handler | |||||||
| import ( | import ( | ||||||
| 	"git.icechen.cn/pkg/drone_plugin/git" | 	"git.icechen.cn/pkg/drone_plugin/git" | ||||||
| 	"gopkg.in/yaml.v3" | 	"gopkg.in/yaml.v3" | ||||||
|  | 	"strings" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| const TypeMonorepo = "monorepo" // 单库类型 | const TypeMonorepo = "monorepo" // 单库类型 | ||||||
| @ -15,6 +16,15 @@ type Config struct { | |||||||
| 	Service ServiceList `json:"service" yaml:"service"` | 	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 ( | type ( | ||||||
| 	ApiList []Api | 	ApiList []Api | ||||||
| 	Api     struct { | 	Api     struct { | ||||||
| @ -24,7 +34,6 @@ type ( | |||||||
| 		Port string `json:"port" yaml:"port"` | 		Port string `json:"port" yaml:"port"` | ||||||
| 	} | 	} | ||||||
| ) | ) | ||||||
| 
 |  | ||||||
| type ( | type ( | ||||||
| 	ServiceList []Service | 	ServiceList []Service | ||||||
| 	Service     struct { | 	Service     struct { | ||||||
|  | |||||||
| @ -2,21 +2,12 @@ package config_handler | |||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
| 	"git.icechen.cn/pkg/drone_plugin/go_handler" | 	"git.icechen.cn/pkg/drone_plugin/go_handler" | ||||||
| 	"strings" |  | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| func (sl ServiceList) toServiceEnv() map[string]string { | func (sl ServiceList) toDestinationConfig(nameSpace string, serviceEnv map[string]string) (string, error) { | ||||||
| 	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) { |  | ||||||
| 	retConfig := "" | 	retConfig := "" | ||||||
| 	for _, service := range sl { | 	for _, service := range sl { | ||||||
| 		config, err := service.toDestinationConfig(nameSpace, sl.toServiceEnv()) | 		config, err := service.toDestinationConfig(nameSpace, serviceEnv) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			return "", err | 			return "", err | ||||||
| 		} | 		} | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user