update
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
9c508d61bf
commit
c12435eb7f
|
@ -0,0 +1,31 @@
|
|||
package config_handler
|
||||
|
||||
import "git.icechen.cn/pkg/drone_plugin/go_handler"
|
||||
|
||||
func (al ApiList) toDestinationConfig(nameSpace string, serviceEnv map[string]string) (string, error) {
|
||||
retConfig := ""
|
||||
for _, api := range al {
|
||||
config, err := api.toDestinationConfig(nameSpace, serviceEnv)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
retConfig += config + "\n\n---\n\n"
|
||||
}
|
||||
return retConfig, nil
|
||||
}
|
||||
|
||||
func (a Api) toDestinationConfig(nameSpace string, serviceEnv map[string]string) (string, error) {
|
||||
var handler Handler
|
||||
switch a.Type {
|
||||
case go_handler.TypeGolang:
|
||||
handler = go_handler.GoApiHandler{
|
||||
NameSpace: nameSpace,
|
||||
Name: a.Name,
|
||||
Root: a.Root,
|
||||
Port: a.Port,
|
||||
ServiceEnv: serviceEnv,
|
||||
}
|
||||
}
|
||||
|
||||
return handler.ToDestinationConfig()
|
||||
}
|
|
@ -19,6 +19,10 @@ func New() config.Plugin {
|
|||
|
||||
type plugin struct{}
|
||||
|
||||
type Handler interface {
|
||||
ToDestinationConfig() (string, error)
|
||||
}
|
||||
|
||||
func (p *plugin) Find(ctx context.Context, req *config.Request) (*drone.Config, error) {
|
||||
resp, err := json.Marshal(req)
|
||||
if err != nil {
|
||||
|
@ -50,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)
|
||||
destinationApi, err := modifiedApiList.toDestinationConfig(cfg.Name, cfg.Service.toServiceEnv())
|
||||
if err != nil {
|
||||
logrus.Error(err)
|
||||
return nil, err
|
||||
|
|
|
@ -1,61 +0,0 @@
|
|||
package config_handler
|
||||
|
||||
import "git.icechen.cn/pkg/drone_plugin/go_handler"
|
||||
|
||||
type Handler interface {
|
||||
ToDestinationConfig() (string, error)
|
||||
}
|
||||
|
||||
func (al ApiList) toDestinationConfig(nameSpace string) (string, error) {
|
||||
retConfig := ""
|
||||
for _, api := range al {
|
||||
config, err := api.toDestinationConfig(nameSpace)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
retConfig += config + "\n\n---\n\n"
|
||||
}
|
||||
return retConfig, nil
|
||||
}
|
||||
|
||||
func (a Api) toDestinationConfig(nameSpace string) (string, error) {
|
||||
var handler Handler
|
||||
switch a.Type {
|
||||
case go_handler.TypeGolang:
|
||||
handler = go_handler.GoApiHandler{
|
||||
NameSpace: nameSpace,
|
||||
Name: a.Name,
|
||||
Root: a.Root,
|
||||
Port: a.Port,
|
||||
}
|
||||
}
|
||||
|
||||
return handler.ToDestinationConfig()
|
||||
}
|
||||
|
||||
func (sl ServiceList) toDestinationConfig(nameSpace string) (string, error) {
|
||||
retConfig := ""
|
||||
for _, service := range sl {
|
||||
config, err := service.toDestinationConfig(nameSpace)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
retConfig += config + "\n\n---\n\n"
|
||||
}
|
||||
return retConfig, nil
|
||||
}
|
||||
|
||||
func (s Service) toDestinationConfig(nameSpace string) (string, error) {
|
||||
var handler Handler
|
||||
switch s.Type {
|
||||
case go_handler.TypeGolang:
|
||||
handler = go_handler.GoServiceHandler{
|
||||
NameSpace: nameSpace,
|
||||
Name: s.Name,
|
||||
Root: s.Root,
|
||||
Port: s.Port,
|
||||
}
|
||||
}
|
||||
|
||||
return handler.ToDestinationConfig()
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
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) {
|
||||
retConfig := ""
|
||||
for _, service := range sl {
|
||||
config, err := service.toDestinationConfig(nameSpace)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
retConfig += config + "\n\n---\n\n"
|
||||
}
|
||||
return retConfig, nil
|
||||
}
|
||||
|
||||
func (s Service) toDestinationConfig(nameSpace string) (string, error) {
|
||||
var handler Handler
|
||||
switch s.Type {
|
||||
case go_handler.TypeGolang:
|
||||
handler = go_handler.GoServiceHandler{
|
||||
NameSpace: nameSpace,
|
||||
Name: s.Name,
|
||||
Root: s.Root,
|
||||
Port: s.Port,
|
||||
}
|
||||
}
|
||||
|
||||
return handler.ToDestinationConfig()
|
||||
}
|
|
@ -35,7 +35,7 @@ steps:
|
|||
path: /var/run/docker.sock
|
||||
commands:
|
||||
- docker rm -f {{ .NameSpace }}-{{ .Name }}
|
||||
- docker run -d --name="{{ .NameSpace }}-{{ .Name }}" --network="nginx-net" reg.icechen.cn/{{ .NameSpace }}/{{ .Name }}:${DRONE_COMMIT:0:8}
|
||||
- docker run -d --name="{{ .NameSpace }}-{{ .Name }}" --network="nginx-net"{{ range $key, $value := .ServiceEnv }} --env {{ $key }}={{ $value }} {{ end }}reg.icechen.cn/{{ .NameSpace }}/{{ .Name }}:${DRONE_COMMIT:0:8}
|
||||
|
||||
volumes:
|
||||
- name: docker
|
||||
|
@ -48,6 +48,7 @@ type GoApiHandler struct {
|
|||
Name string
|
||||
Root string
|
||||
Port string
|
||||
ServiceEnv map[string]string
|
||||
}
|
||||
|
||||
func (gah GoApiHandler) ToDestinationConfig() (string, error) {
|
||||
|
|
Loading…
Reference in New Issue