update
continuous-integration/drone/push Build is passing Details

master
icechen 2021-12-30 00:00:25 +08:00
parent c12435eb7f
commit 36357cdd13
2 changed files with 68 additions and 12 deletions

View File

@ -16,7 +16,7 @@ func (sl ServiceList) toServiceEnv() map[string]string {
func (sl ServiceList) toDestinationConfig(nameSpace string) (string, error) {
retConfig := ""
for _, service := range sl {
config, err := service.toDestinationConfig(nameSpace)
config, err := service.toDestinationConfig(nameSpace, sl.toServiceEnv())
if err != nil {
return "", err
}
@ -25,7 +25,7 @@ func (sl ServiceList) toDestinationConfig(nameSpace string) (string, error) {
return retConfig, nil
}
func (s Service) toDestinationConfig(nameSpace string) (string, error) {
func (s Service) toDestinationConfig(nameSpace string, serviceEnv map[string]string) (string, error) {
var handler Handler
switch s.Type {
case go_handler.TypeGolang:
@ -34,6 +34,7 @@ func (s Service) toDestinationConfig(nameSpace string) (string, error) {
Name: s.Name,
Root: s.Root,
Port: s.Port,
ServiceEnv: serviceEnv,
}
}

View File

@ -1,12 +1,67 @@
package go_handler
import (
"bytes"
"text/template"
)
const servicePipeline = `
kind: pipeline
type: docker
name: {{ .Name }}
steps:
- name: build
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}
dockerfile: ./app/api/{{ .Name }}/Dockerfile
- name: run
image: docker
volumes:
- name: docker
path: /var/run/docker.sock
commands:
- docker rm -f {{ .NameSpace }}-{{ .Name }}
- 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
host:
path: /var/run/docker.sock
`
type GoServiceHandler struct {
NameSpace string
Name string
Root string
Port string
ServiceEnv map[string]string
}
func (GoServiceHandler) ToDestinationConfig() (string, error) {
return "", nil
func (gsh GoServiceHandler) ToDestinationConfig() (string, error) {
var err error
t := template.New(gsh.Name)
t, err = t.Parse(apiPipeline)
if err != nil {
return "", err
}
b := bytes.Buffer{}
err = t.Execute(&b, gsh)
if err != nil {
return "", err
}
return b.String(), nil
}