2021-12-29 19:40:57 +08:00
|
|
|
package go_handler
|
|
|
|
|
2021-12-30 00:00:25 +08:00
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"text/template"
|
|
|
|
|
2022-01-10 17:51:52 +08:00
|
|
|
"git.icechen.cn/pkg/drone_plugin/config"
|
|
|
|
|
2021-12-30 20:06:10 +08:00
|
|
|
"git.icechen.cn/pkg/drone_plugin/go_handler/go_handler_template"
|
2021-12-30 00:00:25 +08:00
|
|
|
|
2021-12-30 20:06:10 +08:00
|
|
|
"git.icechen.cn/pkg/drone_plugin/consts"
|
|
|
|
)
|
2021-12-30 00:00:25 +08:00
|
|
|
|
2021-12-29 19:40:57 +08:00
|
|
|
type GoServiceHandler struct {
|
2022-01-10 17:51:52 +08:00
|
|
|
NameSpace string
|
|
|
|
Name string
|
|
|
|
AliasName string
|
|
|
|
Root string
|
|
|
|
Port string
|
|
|
|
DeployEnv consts.Env
|
|
|
|
|
|
|
|
Reg config.Registry
|
|
|
|
Kube config.KubeConfig
|
2021-12-29 19:40:57 +08:00
|
|
|
}
|
|
|
|
|
2021-12-30 00:00:25 +08:00
|
|
|
func (gsh GoServiceHandler) ToDestinationConfig() (string, error) {
|
|
|
|
var err error
|
|
|
|
t := template.New(gsh.Name)
|
2022-01-10 17:51:52 +08:00
|
|
|
gsh.Reg = config.GetRegistryConfig()
|
2021-12-30 20:06:10 +08:00
|
|
|
|
|
|
|
servicePipeline := go_handler_template.ServiceTestPipeline
|
2022-01-10 17:51:52 +08:00
|
|
|
gsh.Kube = config.GetTestKubeConfigByNamespace(gsh.NameSpace)
|
2021-12-30 20:06:10 +08:00
|
|
|
if gsh.DeployEnv == consts.EnvProduction {
|
|
|
|
servicePipeline = go_handler_template.ServiceProductionPipeline
|
2022-01-10 17:51:52 +08:00
|
|
|
gsh.Kube = config.GetOnlKubeConfigByNamespace(gsh.NameSpace)
|
2021-12-30 20:06:10 +08:00
|
|
|
}
|
|
|
|
|
2021-12-30 00:05:19 +08:00
|
|
|
t, err = t.Parse(servicePipeline)
|
2021-12-30 00:00:25 +08:00
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
b := bytes.Buffer{}
|
|
|
|
err = t.Execute(&b, gsh)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
return b.String(), nil
|
2021-12-29 19:40:57 +08:00
|
|
|
}
|