update
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
745daedf91
commit
9d2f9d6c32
|
@ -50,7 +50,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()
|
destinationApi, err := modifiedApiList.toDestinationConfig(cfg.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Error(err)
|
logrus.Error(err)
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -58,7 +58,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()
|
destinationService, err := modifiedServiceList.toDestinationConfig(cfg.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Error(err)
|
logrus.Error(err)
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
@ -6,10 +6,10 @@ type Handler interface {
|
||||||
ToDestinationConfig() (string, error)
|
ToDestinationConfig() (string, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (al ApiList) toDestinationConfig() (string, error) {
|
func (al ApiList) toDestinationConfig(nameSpace string) (string, error) {
|
||||||
retConfig := ""
|
retConfig := ""
|
||||||
for _, api := range al {
|
for _, api := range al {
|
||||||
config, err := api.toDestinationConfig()
|
config, err := api.toDestinationConfig(nameSpace)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
@ -18,11 +18,12 @@ func (al ApiList) toDestinationConfig() (string, error) {
|
||||||
return retConfig, nil
|
return retConfig, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a Api) toDestinationConfig() (string, error) {
|
func (a Api) toDestinationConfig(nameSpace string) (string, error) {
|
||||||
var handler Handler
|
var handler Handler
|
||||||
switch a.Type {
|
switch a.Type {
|
||||||
case go_handler.TypeGolang:
|
case go_handler.TypeGolang:
|
||||||
handler = go_handler.GoApiHandler{
|
handler = go_handler.GoApiHandler{
|
||||||
|
NameSpace: nameSpace,
|
||||||
Name: a.Name,
|
Name: a.Name,
|
||||||
Root: a.Root,
|
Root: a.Root,
|
||||||
Port: a.Port,
|
Port: a.Port,
|
||||||
|
@ -32,10 +33,10 @@ func (a Api) toDestinationConfig() (string, error) {
|
||||||
return handler.ToDestinationConfig()
|
return handler.ToDestinationConfig()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sl ServiceList) toDestinationConfig() (string, error) {
|
func (sl ServiceList) toDestinationConfig(nameSpace string) (string, error) {
|
||||||
retConfig := ""
|
retConfig := ""
|
||||||
for _, service := range sl {
|
for _, service := range sl {
|
||||||
config, err := service.toDestinationConfig()
|
config, err := service.toDestinationConfig(nameSpace)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
@ -44,11 +45,12 @@ func (sl ServiceList) toDestinationConfig() (string, error) {
|
||||||
return retConfig, nil
|
return retConfig, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s Service) toDestinationConfig() (string, error) {
|
func (s Service) toDestinationConfig(nameSpace string) (string, error) {
|
||||||
var handler Handler
|
var handler Handler
|
||||||
switch s.Type {
|
switch s.Type {
|
||||||
case go_handler.TypeGolang:
|
case go_handler.TypeGolang:
|
||||||
handler = go_handler.GoApiHandler{
|
handler = go_handler.GoApiHandler{
|
||||||
|
NameSpace: nameSpace,
|
||||||
Name: s.Name,
|
Name: s.Name,
|
||||||
Root: s.Root,
|
Root: s.Root,
|
||||||
Port: s.Port,
|
Port: s.Port,
|
||||||
|
|
|
@ -12,7 +12,7 @@ var cli *gitea.Client
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
var err error
|
var err error
|
||||||
cli, err = gitea.NewClient("https://git.icechen.cn/", gitea.SetToken("4322b0d361004db5dcea1741417f9e014a0f428f"))
|
cli, err = gitea.NewClient("http://gitea:3000/", gitea.SetToken("4322b0d361004db5dcea1741417f9e014a0f428f"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,24 +1,67 @@
|
||||||
package go_handler
|
package go_handler
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"text/template"
|
||||||
|
)
|
||||||
|
|
||||||
const TypeGolang = "golang"
|
const TypeGolang = "golang"
|
||||||
|
|
||||||
const defaultPipeline = `
|
const apiPipeline = `
|
||||||
kind: pipeline
|
kind: pipeline
|
||||||
name: default
|
type: docker
|
||||||
|
name: 部署{{ .Name }}
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: build
|
- name: build
|
||||||
image: golang
|
image: plugins/docker
|
||||||
|
volumes:
|
||||||
|
- name: docker
|
||||||
|
path: /var/run/docker.sock
|
||||||
|
settings:
|
||||||
|
username:
|
||||||
|
from_secret: reg_username
|
||||||
|
password:
|
||||||
|
from_secret: reg_password
|
||||||
|
repo: reg.icechen.cn/{{ .NameSpace }}/{{ .Name }}
|
||||||
|
registry: reg.icechen.cn
|
||||||
|
tags: ${DRONE_COMMIT:0:8}
|
||||||
|
|
||||||
|
- name: run
|
||||||
|
image: docker
|
||||||
|
volumes:
|
||||||
|
- name: docker
|
||||||
|
path: /var/run/docker.sock
|
||||||
commands:
|
commands:
|
||||||
- go build
|
- docker rm -f {{ .NameSpace }}-{{ .Name }}
|
||||||
- go test -v
|
- docker run -d --name="{{ .NameSpace }}-{{ .Name }}" reg.icechen.cn/{{ .NameSpace }}/{{ .Name }}:${DRONE_COMMIT:0:8}
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
- name: docker
|
||||||
|
host:
|
||||||
|
path: /var/run/docker.sock
|
||||||
`
|
`
|
||||||
|
|
||||||
type GoApiHandler struct {
|
type GoApiHandler struct {
|
||||||
|
NameSpace string
|
||||||
Name string
|
Name string
|
||||||
Root string
|
Root string
|
||||||
Port string
|
Port string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (GoApiHandler) ToDestinationConfig() (string, error) {
|
func (gah GoApiHandler) ToDestinationConfig() (string, error) {
|
||||||
return "", nil
|
var err error
|
||||||
|
t := template.New(gah.Name)
|
||||||
|
t, err = t.Parse(apiPipeline)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
b := bytes.Buffer{}
|
||||||
|
err = t.Execute(&b, gah)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
return b.String(), nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package go_handler
|
package go_handler
|
||||||
|
|
||||||
type GoServiceHandler struct {
|
type GoServiceHandler struct {
|
||||||
|
NameSpace string
|
||||||
Name string
|
Name string
|
||||||
Root string
|
Root string
|
||||||
Port string
|
Port string
|
||||||
|
|
Loading…
Reference in New Issue