@@ -5,10 +5,10 @@ import (
|
||||
"git.icechen.cn/pkg/drone_plugin/go_handler"
|
||||
)
|
||||
|
||||
func (al ApiList) toDestinationConfig(nameSpace string, deployEnv consts.Env, serviceEnv map[string]string) (string, error) {
|
||||
func (al ApiList) toDestinationConfig(deployEnv consts.Env) (string, error) {
|
||||
retConfig := ""
|
||||
for _, api := range al {
|
||||
config, err := api.toDestinationConfig(nameSpace, deployEnv, serviceEnv)
|
||||
config, err := api.toDestinationConfig(deployEnv)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -17,20 +17,19 @@ func (al ApiList) toDestinationConfig(nameSpace string, deployEnv consts.Env, se
|
||||
return retConfig, nil
|
||||
}
|
||||
|
||||
func (a Api) toDestinationConfig(nameSpace string, deployEnv consts.Env, serviceEnv map[string]string) (string, error) {
|
||||
func (a Api) toDestinationConfig(deployEnv consts.Env) (string, error) {
|
||||
var handler Handler
|
||||
switch a.Type {
|
||||
case go_handler.TypeGolang:
|
||||
handler = go_handler.GoApiHandler{
|
||||
NameSpace: nameSpace,
|
||||
Name: a.Name,
|
||||
AliasName: a.AliasName,
|
||||
Root: a.Root,
|
||||
Port: a.Port,
|
||||
Host: a.Host,
|
||||
Path: a.Path,
|
||||
ServiceEnv: serviceEnv,
|
||||
DeployEnv: deployEnv,
|
||||
NameSpace: a.Namespace,
|
||||
Name: a.Name,
|
||||
AliasName: a.AliasName,
|
||||
Root: a.Root,
|
||||
Port: a.Port,
|
||||
Host: a.Host,
|
||||
Path: a.Path,
|
||||
DeployEnv: deployEnv,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ func (p *plugin) Find(ctx context.Context, req *config.Request) (*drone.Config,
|
||||
// 4. 根据文件树以及原始配置文件的信息,组装需要构建的服务的ci信息
|
||||
// 4.1 api
|
||||
modifiedApiList := getModifiedApi(cfg.Api, modifiedFileList, foundAppByMessage(req.Build.Message), foundAppByParams(req.Build.Params))
|
||||
destinationApi, err := modifiedApiList.toDestinationConfig(cfg.Name, getDeployEnv(req), cfg.toServiceEnv())
|
||||
destinationApi, err := modifiedApiList.toDestinationConfig(getDeployEnv(req))
|
||||
if err != nil {
|
||||
logrus.Error(err)
|
||||
return nil, err
|
||||
@@ -70,7 +70,7 @@ func (p *plugin) Find(ctx context.Context, req *config.Request) (*drone.Config,
|
||||
|
||||
// 4.2 service
|
||||
modifiedServiceList := getModifiedService(cfg.Service, modifiedFileList, foundAppByMessage(req.Build.Message), foundAppByParams(req.Build.Params))
|
||||
destinationService, err := modifiedServiceList.toDestinationConfig(cfg.Name, getDeployEnv(req), cfg.toServiceEnv())
|
||||
destinationService, err := modifiedServiceList.toDestinationConfig(getDeployEnv(req))
|
||||
if err != nil {
|
||||
logrus.Error(err)
|
||||
return nil, err
|
||||
@@ -136,8 +136,13 @@ func getDeployApiByAppSlice(api ApiList, appSlice []string) ApiList {
|
||||
ret := make(ApiList, 0)
|
||||
for _, app := range appSlice {
|
||||
for _, a := range api {
|
||||
if "api-"+a.Name == strings.TrimSpace(app) {
|
||||
ret = append(ret, a)
|
||||
appWithNamespace := strings.Split(app, ".")
|
||||
if len(appWithNamespace) == 2 {
|
||||
name := appWithNamespace[0]
|
||||
namespace := appWithNamespace[1]
|
||||
if a.Namespace == strings.TrimSpace(namespace) && "api-"+a.Name == strings.TrimSpace(name) {
|
||||
ret = append(ret, a)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -166,8 +171,13 @@ func getDeployServiceByAppSlice(service ServiceList, appSlice []string) ServiceL
|
||||
ret := make(ServiceList, 0)
|
||||
for _, app := range appSlice {
|
||||
for _, s := range service {
|
||||
if "service-"+s.Name == strings.TrimSpace(app) {
|
||||
ret = append(ret, s)
|
||||
appWithNamespace := strings.Split(app, ".")
|
||||
if len(appWithNamespace) == 2 {
|
||||
name := appWithNamespace[0]
|
||||
namespace := appWithNamespace[1]
|
||||
if s.Namespace == strings.TrimSpace(namespace) && "service-"+s.Name == strings.TrimSpace(name) {
|
||||
ret = append(ret, s)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package config_handler
|
||||
import (
|
||||
"git.icechen.cn/pkg/drone_plugin/git"
|
||||
"gopkg.in/yaml.v3"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const TypeMonorepo = "monorepo" // 单库类型
|
||||
@@ -16,18 +15,10 @@ 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 {
|
||||
Namespace string `json:"namespace" yaml:"namespace"`
|
||||
Name string `json:"name" yaml:"name"`
|
||||
AliasName string `json:"alias_name" yaml:"aliasName"`
|
||||
Root string `json:"root" yaml:"root"`
|
||||
@@ -37,9 +28,11 @@ type (
|
||||
Path string `json:"path" yaml:"path"`
|
||||
}
|
||||
)
|
||||
|
||||
type (
|
||||
ServiceList []Service
|
||||
Service struct {
|
||||
Namespace string `json:"namespace" yaml:"namespace"`
|
||||
Name string `json:"name" yaml:"name"`
|
||||
AliasName string `json:"alias_name" yaml:"aliasName"`
|
||||
Root string `json:"root" yaml:"root"`
|
||||
|
||||
@@ -5,10 +5,10 @@ import (
|
||||
"git.icechen.cn/pkg/drone_plugin/go_handler"
|
||||
)
|
||||
|
||||
func (sl ServiceList) toDestinationConfig(nameSpace string, deployEnv consts.Env, serviceEnv map[string]string) (string, error) {
|
||||
func (sl ServiceList) toDestinationConfig(deployEnv consts.Env) (string, error) {
|
||||
retConfig := ""
|
||||
for _, service := range sl {
|
||||
config, err := service.toDestinationConfig(nameSpace, deployEnv, serviceEnv)
|
||||
config, err := service.toDestinationConfig(deployEnv)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -17,18 +17,17 @@ func (sl ServiceList) toDestinationConfig(nameSpace string, deployEnv consts.Env
|
||||
return retConfig, nil
|
||||
}
|
||||
|
||||
func (s Service) toDestinationConfig(nameSpace string, deployEnv consts.Env, serviceEnv map[string]string) (string, error) {
|
||||
func (s Service) toDestinationConfig(deployEnv consts.Env) (string, error) {
|
||||
var handler Handler
|
||||
switch s.Type {
|
||||
case go_handler.TypeGolang:
|
||||
handler = go_handler.GoServiceHandler{
|
||||
NameSpace: nameSpace,
|
||||
Name: s.Name,
|
||||
AliasName: s.AliasName,
|
||||
Root: s.Root,
|
||||
Port: s.Port,
|
||||
ServiceEnv: serviceEnv,
|
||||
DeployEnv: deployEnv,
|
||||
NameSpace: s.Namespace,
|
||||
Name: s.Name,
|
||||
AliasName: s.AliasName,
|
||||
Root: s.Root,
|
||||
Port: s.Port,
|
||||
DeployEnv: deployEnv,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user