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/service/{{ .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 (gsh GoServiceHandler) ToDestinationConfig() (string, error) { var err error t := template.New(gsh.Name) t, err = t.Parse(servicePipeline) if err != nil { return "", err } b := bytes.Buffer{} err = t.Execute(&b, gsh) if err != nil { return "", err } return b.String(), nil }