feat: 增加namespace
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
112ae73203
commit
e38bf7e1af
|
@ -0,0 +1,24 @@
|
|||
reg:
|
||||
registry: reg.icechen.cn
|
||||
username: ananta
|
||||
password: ananta01
|
||||
|
||||
kube:
|
||||
zeus:
|
||||
onl:
|
||||
kube_api_server: https://paw.show:6443
|
||||
kube_certificate: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUM1ekNDQWMrZ0F3SUJBZ0lCQURBTkJna3Foa2lHOXcwQkFRc0ZBREFWTVJNd0VRWURWUVFERXdwcmRXSmwKY201bGRHVnpNQjRYRFRJeE1USXlNakU0TVRNME1sb1hEVE14TVRJeU1ERTRNVE0wTWxvd0ZURVRNQkVHQTFVRQpBeE1LYTNWaVpYSnVaWFJsY3pDQ0FTSXdEUVlKS29aSWh2Y05BUUVCQlFBRGdnRVBBRENDQVFvQ2dnRUJBTE0zCjNDSGRweGRmMDMvR2xEME1Gb1VrYmJFR2VuRHl3U1pINERnbzZ6NzJZUGVyNi9WR3M2enVzTlRic0VKKzNHOUoKSlJteDVYUlVmZDhCVFVUblUzYVJQUFdtK0NEbDNDZERHUUdpYWNySldrMnZVaHQzdXBSbDhUOXdJL0YwejB0RgpWQW5qVmlWVmZndmIvNjliZnNQSjJtV3JPWWY3M25CVWs5VjFyRjRQRSs2cXFEUG1pTm1zb1F0SFdBNjBpclh2CkFtd3ZuMFo0S2RudFdWUlNVU3VXU21QaUlIQzVSdlZUa3QrR0hQcW5WRUl1YXlNcjlxTVI3eWRjdDJBNmptNTIKcnZ6NGlKdEV2blhFbGx3VS9QUkRoeEZjaldOTFM1akEyNEpZOVRjOE90Z2syM2FlY2NHSUZOeW9HcnRPTXVIZgpJVkQxdyt2TWVaQ0ZKMzVvdFhjQ0F3RUFBYU5DTUVBd0RnWURWUjBQQVFIL0JBUURBZ0trTUE4R0ExVWRFd0VCCi93UUZNQU1CQWY4d0hRWURWUjBPQkJ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ImtpZCI6ImNpSTl3LWZ5SFlZcklEbzlldlY1NnYtWGR2MjFIUm9neFpzWEgxblBQTWsifQ.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJicmFobWEiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlY3JldC5uYW1lIjoiZHJvbmUtdG9rZW4teHJoczIiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC5uYW1lIjoiZHJvbmUiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC51aWQiOiIxNWMwOWFhYi1jNzc1LTRiNTUtOTFiNy1hYjM3ZmQ3NmQxZDMiLCJzdWIiOiJzeXN0ZW06c2VydmljZWFjY291bnQ6YnJhaG1hOmRyb25lIn0.dUB76nLlzOqJtylHA4k34GMQVxVNBO440iUibcA817SODS6ZExL6HPrVhLXjrrcUyEpp7zSsojeh-BBX8L23AtX--tFHq9tUoo-0MrjT_s9BnmSvDSrLHOyk0-5CyXuYaCW_Bf8kqE-zt4yg3isyV2W8tO0nFX3fILbLRU7vWvP0wd_n_KLrn1QENF-iQQoDEaoO-Cfy6DQSoHMcwuUcgbAJYUGVP92DteyXgpwArzsACtbuEq1uCXezy_5ZLHEy_wqKmVndSQoaUgU7Z4Fir6VdKXa6p0yi7WfYALp4j1tKTDLbEixraUqDoHSTZKMD46DhY1Jr8SSjF76pMYojbQ
|
|
@ -0,0 +1,58 @@
|
|||
package config
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
//go:embed "config.yaml"
|
||||
var configData []byte
|
||||
|
||||
type Config struct {
|
||||
Reg Registry `json:"reg" yaml:"reg"`
|
||||
Kube map[string]Kube `json:"kube" yaml:"kube"`
|
||||
}
|
||||
|
||||
// Registry 镜像仓库信息
|
||||
type Registry struct {
|
||||
Registry string `json:"registry" yaml:"registry"`
|
||||
Username string `json:"username" yaml:"username"`
|
||||
Password string `json:"password" yaml:"password"`
|
||||
}
|
||||
|
||||
// Kube kube信息
|
||||
type Kube struct {
|
||||
Onl KubeConfig `json:"onl" yaml:"onl"`
|
||||
Test KubeConfig `json:"test" yaml:"test"`
|
||||
}
|
||||
|
||||
type KubeConfig struct {
|
||||
KubeApiServer string `json:"kube_api_server" yaml:"kube_api_server"`
|
||||
KubeCertificate string `json:"kube_certificate" yaml:"kube_certificate"`
|
||||
KubeToken string `json:"kube_token" yaml:"kube_token"`
|
||||
}
|
||||
|
||||
var config Config
|
||||
|
||||
func init() {
|
||||
err := yaml.Unmarshal(configData, &config)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// GetOnlKubeConfigByNamespace 获取namespace的线上kube配置
|
||||
func GetOnlKubeConfigByNamespace(namespace string) KubeConfig {
|
||||
return config.Kube[namespace].Onl
|
||||
}
|
||||
|
||||
// GetTestKubeConfigByNamespace 获取namespace的测试kube配置
|
||||
func GetTestKubeConfigByNamespace(namespace string) KubeConfig {
|
||||
return config.Kube[namespace].Onl
|
||||
}
|
||||
|
||||
// GetRegistryConfig 获取镜像仓库配置
|
||||
func GetRegistryConfig() Registry {
|
||||
return config.Reg
|
||||
}
|
|
@ -5,10 +5,10 @@ import (
|
|||
"git.icechen.cn/pkg/drone_plugin/go_handler"
|
||||
)
|
||||
|
||||
func (al ApiList) toDestinationConfig(nameSpace string, deployEnv consts.Env, serviceEnv map[string]string) (string, error) {
|
||||
func (al ApiList) toDestinationConfig(deployEnv consts.Env) (string, error) {
|
||||
retConfig := ""
|
||||
for _, api := range al {
|
||||
config, err := api.toDestinationConfig(nameSpace, deployEnv, serviceEnv)
|
||||
config, err := api.toDestinationConfig(deployEnv)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
@ -17,19 +17,18 @@ func (al ApiList) toDestinationConfig(nameSpace string, deployEnv consts.Env, se
|
|||
return retConfig, nil
|
||||
}
|
||||
|
||||
func (a Api) toDestinationConfig(nameSpace string, deployEnv consts.Env, serviceEnv map[string]string) (string, error) {
|
||||
func (a Api) toDestinationConfig(deployEnv consts.Env) (string, error) {
|
||||
var handler Handler
|
||||
switch a.Type {
|
||||
case go_handler.TypeGolang:
|
||||
handler = go_handler.GoApiHandler{
|
||||
NameSpace: nameSpace,
|
||||
NameSpace: a.Namespace,
|
||||
Name: a.Name,
|
||||
AliasName: a.AliasName,
|
||||
Root: a.Root,
|
||||
Port: a.Port,
|
||||
Host: a.Host,
|
||||
Path: a.Path,
|
||||
ServiceEnv: serviceEnv,
|
||||
DeployEnv: deployEnv,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -62,7 +62,7 @@ func (p *plugin) Find(ctx context.Context, req *config.Request) (*drone.Config,
|
|||
// 4. 根据文件树以及原始配置文件的信息,组装需要构建的服务的ci信息
|
||||
// 4.1 api
|
||||
modifiedApiList := getModifiedApi(cfg.Api, modifiedFileList, foundAppByMessage(req.Build.Message), foundAppByParams(req.Build.Params))
|
||||
destinationApi, err := modifiedApiList.toDestinationConfig(cfg.Name, getDeployEnv(req), cfg.toServiceEnv())
|
||||
destinationApi, err := modifiedApiList.toDestinationConfig(getDeployEnv(req))
|
||||
if err != nil {
|
||||
logrus.Error(err)
|
||||
return nil, err
|
||||
|
@ -70,7 +70,7 @@ func (p *plugin) Find(ctx context.Context, req *config.Request) (*drone.Config,
|
|||
|
||||
// 4.2 service
|
||||
modifiedServiceList := getModifiedService(cfg.Service, modifiedFileList, foundAppByMessage(req.Build.Message), foundAppByParams(req.Build.Params))
|
||||
destinationService, err := modifiedServiceList.toDestinationConfig(cfg.Name, getDeployEnv(req), cfg.toServiceEnv())
|
||||
destinationService, err := modifiedServiceList.toDestinationConfig(getDeployEnv(req))
|
||||
if err != nil {
|
||||
logrus.Error(err)
|
||||
return nil, err
|
||||
|
@ -136,11 +136,16 @@ func getDeployApiByAppSlice(api ApiList, appSlice []string) ApiList {
|
|||
ret := make(ApiList, 0)
|
||||
for _, app := range appSlice {
|
||||
for _, a := range api {
|
||||
if "api-"+a.Name == strings.TrimSpace(app) {
|
||||
appWithNamespace := strings.Split(app, ".")
|
||||
if len(appWithNamespace) == 2 {
|
||||
name := appWithNamespace[0]
|
||||
namespace := appWithNamespace[1]
|
||||
if a.Namespace == strings.TrimSpace(namespace) && "api-"+a.Name == strings.TrimSpace(name) {
|
||||
ret = append(ret, a)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
|
@ -166,11 +171,16 @@ func getDeployServiceByAppSlice(service ServiceList, appSlice []string) ServiceL
|
|||
ret := make(ServiceList, 0)
|
||||
for _, app := range appSlice {
|
||||
for _, s := range service {
|
||||
if "service-"+s.Name == strings.TrimSpace(app) {
|
||||
appWithNamespace := strings.Split(app, ".")
|
||||
if len(appWithNamespace) == 2 {
|
||||
name := appWithNamespace[0]
|
||||
namespace := appWithNamespace[1]
|
||||
if s.Namespace == strings.TrimSpace(namespace) && "service-"+s.Name == strings.TrimSpace(name) {
|
||||
ret = append(ret, s)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,6 @@ package config_handler
|
|||
import (
|
||||
"git.icechen.cn/pkg/drone_plugin/git"
|
||||
"gopkg.in/yaml.v3"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const TypeMonorepo = "monorepo" // 单库类型
|
||||
|
@ -16,18 +15,10 @@ type Config struct {
|
|||
Service ServiceList `json:"service" yaml:"service"`
|
||||
}
|
||||
|
||||
func (c Config) toServiceEnv() map[string]string {
|
||||
sl := c.Service
|
||||
retMap := make(map[string]string)
|
||||
for _, service := range sl {
|
||||
retMap[strings.ToUpper("SERVICE_"+service.Name)] = c.Name + "-" + service.Name + ":" + service.Port
|
||||
}
|
||||
return retMap
|
||||
}
|
||||
|
||||
type (
|
||||
ApiList []Api
|
||||
Api struct {
|
||||
Namespace string `json:"namespace" yaml:"namespace"`
|
||||
Name string `json:"name" yaml:"name"`
|
||||
AliasName string `json:"alias_name" yaml:"aliasName"`
|
||||
Root string `json:"root" yaml:"root"`
|
||||
|
@ -37,9 +28,11 @@ type (
|
|||
Path string `json:"path" yaml:"path"`
|
||||
}
|
||||
)
|
||||
|
||||
type (
|
||||
ServiceList []Service
|
||||
Service struct {
|
||||
Namespace string `json:"namespace" yaml:"namespace"`
|
||||
Name string `json:"name" yaml:"name"`
|
||||
AliasName string `json:"alias_name" yaml:"aliasName"`
|
||||
Root string `json:"root" yaml:"root"`
|
||||
|
|
|
@ -5,10 +5,10 @@ import (
|
|||
"git.icechen.cn/pkg/drone_plugin/go_handler"
|
||||
)
|
||||
|
||||
func (sl ServiceList) toDestinationConfig(nameSpace string, deployEnv consts.Env, serviceEnv map[string]string) (string, error) {
|
||||
func (sl ServiceList) toDestinationConfig(deployEnv consts.Env) (string, error) {
|
||||
retConfig := ""
|
||||
for _, service := range sl {
|
||||
config, err := service.toDestinationConfig(nameSpace, deployEnv, serviceEnv)
|
||||
config, err := service.toDestinationConfig(deployEnv)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
@ -17,17 +17,16 @@ func (sl ServiceList) toDestinationConfig(nameSpace string, deployEnv consts.Env
|
|||
return retConfig, nil
|
||||
}
|
||||
|
||||
func (s Service) toDestinationConfig(nameSpace string, deployEnv consts.Env, serviceEnv map[string]string) (string, error) {
|
||||
func (s Service) toDestinationConfig(deployEnv consts.Env) (string, error) {
|
||||
var handler Handler
|
||||
switch s.Type {
|
||||
case go_handler.TypeGolang:
|
||||
handler = go_handler.GoServiceHandler{
|
||||
NameSpace: nameSpace,
|
||||
NameSpace: s.Namespace,
|
||||
Name: s.Name,
|
||||
AliasName: s.AliasName,
|
||||
Root: s.Root,
|
||||
Port: s.Port,
|
||||
ServiceEnv: serviceEnv,
|
||||
DeployEnv: deployEnv,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,8 @@ import (
|
|||
"bytes"
|
||||
"text/template"
|
||||
|
||||
"git.icechen.cn/pkg/drone_plugin/config"
|
||||
|
||||
"git.icechen.cn/pkg/drone_plugin/go_handler/go_handler_template"
|
||||
|
||||
"git.icechen.cn/pkg/drone_plugin/consts"
|
||||
|
@ -19,17 +21,22 @@ type GoApiHandler struct {
|
|||
Port string
|
||||
Host string
|
||||
Path string
|
||||
ServiceEnv map[string]string
|
||||
DeployEnv consts.Env
|
||||
|
||||
Reg config.Registry
|
||||
Kube config.KubeConfig
|
||||
}
|
||||
|
||||
func (gah GoApiHandler) ToDestinationConfig() (string, error) {
|
||||
var err error
|
||||
t := template.New(gah.Name)
|
||||
gah.Reg = config.GetRegistryConfig()
|
||||
|
||||
apiPipeline := go_handler_template.ApiTestPipeline
|
||||
gah.Kube = config.GetTestKubeConfigByNamespace(gah.NameSpace)
|
||||
if gah.DeployEnv == consts.EnvProduction {
|
||||
apiPipeline = go_handler_template.ApiProductionPipeline
|
||||
gah.Kube = config.GetOnlKubeConfigByNamespace(gah.NameSpace)
|
||||
}
|
||||
|
||||
t, err = t.Parse(apiPipeline)
|
||||
|
|
|
@ -3,7 +3,7 @@ package go_handler_template
|
|||
const ApiProductionPipeline = `
|
||||
kind: pipeline
|
||||
type: docker
|
||||
name: 部署production-api-{{ .Name }}
|
||||
name: 部署production-api-{{ .Name }}.{{ .NameSpace }}
|
||||
|
||||
steps:
|
||||
- name: build
|
||||
|
@ -12,12 +12,10 @@ steps:
|
|||
- name: docker
|
||||
path: /var/run/docker.sock
|
||||
settings:
|
||||
username:
|
||||
from_secret: reg_username
|
||||
password:
|
||||
from_secret: reg_password
|
||||
repo: reg.icechen.cn/{{ .NameSpace }}/api-{{ .Name }}
|
||||
registry: reg.icechen.cn
|
||||
username: {{ .Reg.Password }}
|
||||
password: {{ .Reg.Registry }}
|
||||
repo: {{ .Reg.Registry }}/{{ .NameSpace }}/api-{{ .Name }}
|
||||
registry: {{ .Reg.Registry }}
|
||||
tags:
|
||||
- ${DRONE_TAG}
|
||||
- latest
|
||||
|
@ -27,12 +25,9 @@ steps:
|
|||
- name: deploy
|
||||
image: bitsbeats/drone-helm3
|
||||
settings:
|
||||
kube_api_server:
|
||||
from_secret: kubernetes_server
|
||||
kube_token:
|
||||
from_secret: kubernetes_token
|
||||
kube_certificate:
|
||||
from_secret: kubernetes_cert
|
||||
kube_api_server: {{ .Kube.KubeApiServer }}
|
||||
kube_token: {{ .Kube.KubeToken }}
|
||||
kube_certificate: {{ .Kube.KubeCertificate }}
|
||||
chart: ./{{ .Root }}/deploy
|
||||
release: api-{{ .Name }}
|
||||
wait: true
|
||||
|
@ -40,7 +35,7 @@ steps:
|
|||
values:
|
||||
- nameSpace={{ .NameSpace }}
|
||||
- aliasName={{ .AliasName }}
|
||||
- image=reg.icechen.cn/{{ .NameSpace }}/api-{{ .Name }}
|
||||
- image={{ .Reg.Registry }}/{{ .NameSpace }}/api-{{ .Name }}
|
||||
- imageTag=${DRONE_TAG}
|
||||
- port={{ .Port }}
|
||||
{{ if .Host }}
|
||||
|
|
|
@ -3,7 +3,7 @@ package go_handler_template
|
|||
const ApiTestPipeline = `
|
||||
kind: pipeline
|
||||
type: docker
|
||||
name: 部署test-api-{{ .Name }}
|
||||
name: 部署test-api-{{ .Name }}.{{ .NameSpace }}
|
||||
|
||||
steps:
|
||||
- name: build
|
||||
|
@ -12,12 +12,10 @@ steps:
|
|||
- name: docker
|
||||
path: /var/run/docker.sock
|
||||
settings:
|
||||
username:
|
||||
from_secret: reg_username
|
||||
password:
|
||||
from_secret: reg_password
|
||||
repo: reg.icechen.cn/{{ .NameSpace }}/api-{{ .Name }}
|
||||
registry: reg.icechen.cn
|
||||
username: {{ .Reg.Password }}
|
||||
password: {{ .Reg.Registry }}
|
||||
repo: {{ .Reg.Registry }}/{{ .NameSpace }}/api-{{ .Name }}
|
||||
registry: {{ .Reg.Registry }}
|
||||
tags:
|
||||
- ${DRONE_COMMIT:0:8}
|
||||
- latest
|
||||
|
@ -27,12 +25,9 @@ steps:
|
|||
- name: deploy
|
||||
image: bitsbeats/drone-helm3
|
||||
settings:
|
||||
kube_api_server:
|
||||
from_secret: kubernetes_server_test
|
||||
kube_token:
|
||||
from_secret: kubernetes_token_test
|
||||
kube_certificate:
|
||||
from_secret: kubernetes_cert_test
|
||||
kube_api_server: {{ .Kube.KubeApiServer }}
|
||||
kube_token: {{ .Kube.KubeToken }}
|
||||
kube_certificate: {{ .Kube.KubeCertificate }}
|
||||
chart: ./{{ .Root }}/deploy
|
||||
release: api-{{ .Name }}-test
|
||||
wait: true
|
||||
|
@ -40,7 +35,7 @@ steps:
|
|||
values:
|
||||
- nameSpace={{ .NameSpace }}
|
||||
- aliasName={{ .AliasName }}
|
||||
- image=reg.icechen.cn/{{ .NameSpace }}/api-{{ .Name }}
|
||||
- image={{ .Reg.Registry }}/{{ .NameSpace }}/api-{{ .Name }}
|
||||
- imageTag=${DRONE_COMMIT:0:8}
|
||||
- port={{ .Port }}
|
||||
{{ if .Host }}
|
||||
|
|
|
@ -3,7 +3,7 @@ package go_handler_template
|
|||
const ServiceProductionPipeline = `
|
||||
kind: pipeline
|
||||
type: docker
|
||||
name: 部署production-service-{{ .Name }}
|
||||
name: 部署production-service-{{ .Name }}.{{ .NameSpace }}
|
||||
|
||||
steps:
|
||||
- name: build
|
||||
|
@ -12,12 +12,10 @@ steps:
|
|||
- name: docker
|
||||
path: /var/run/docker.sock
|
||||
settings:
|
||||
username:
|
||||
from_secret: reg_username
|
||||
password:
|
||||
from_secret: reg_password
|
||||
repo: reg.icechen.cn/{{ .NameSpace }}/service-{{ .Name }}
|
||||
registry: reg.icechen.cn
|
||||
username: {{ .Reg.Password }}
|
||||
password: {{ .Reg.Registry }}
|
||||
repo: {{ .Reg.Registry }}/{{ .NameSpace }}/service-{{ .Name }}
|
||||
registry: {{ .Reg.Registry }}
|
||||
tags:
|
||||
- "${DRONE_TAG}"
|
||||
- latest
|
||||
|
@ -27,12 +25,9 @@ steps:
|
|||
- name: deploy
|
||||
image: bitsbeats/drone-helm3
|
||||
settings:
|
||||
kube_api_server:
|
||||
from_secret: kubernetes_server
|
||||
kube_token:
|
||||
from_secret: kubernetes_token
|
||||
kube_certificate:
|
||||
from_secret: kubernetes_cert
|
||||
kube_api_server: {{ .Kube.KubeApiServer }}
|
||||
kube_token: {{ .Kube.KubeToken }}
|
||||
kube_certificate: {{ .Kube.KubeCertificate }}
|
||||
chart: ./{{ .Root }}/deploy
|
||||
release: service-{{ .Name }}
|
||||
wait: true
|
||||
|
@ -40,7 +35,7 @@ steps:
|
|||
values:
|
||||
- nameSpace={{ .NameSpace }}
|
||||
- aliasName={{ .AliasName }}
|
||||
- image=reg.icechen.cn/{{ .NameSpace }}/service-{{ .Name }}
|
||||
- image={{ .Reg.Registry }}/{{ .NameSpace }}/service-{{ .Name }}
|
||||
- imageTag=${DRONE_TAG}
|
||||
- port={{ .Port }}
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ package go_handler_template
|
|||
const ServiceTestPipeline = `
|
||||
kind: pipeline
|
||||
type: docker
|
||||
name: 部署test-service-{{ .Name }}
|
||||
name: 部署test-service-{{ .Name }}.{{ .NameSpace }}
|
||||
|
||||
steps:
|
||||
- name: build
|
||||
|
@ -12,12 +12,10 @@ steps:
|
|||
- name: docker
|
||||
path: /var/run/docker.sock
|
||||
settings:
|
||||
username:
|
||||
from_secret: reg_username
|
||||
password:
|
||||
from_secret: reg_password
|
||||
repo: reg.icechen.cn/{{ .NameSpace }}/service-{{ .Name }}
|
||||
registry: reg.icechen.cn
|
||||
username: {{ .Reg.Password }}
|
||||
password: {{ .Reg.Registry }}
|
||||
repo: {{ .Reg.Registry }}/{{ .NameSpace }}/service-{{ .Name }}
|
||||
registry: {{ .Reg.Registry }}
|
||||
tags:
|
||||
- ${DRONE_COMMIT:0:8}
|
||||
- latest
|
||||
|
@ -27,12 +25,9 @@ steps:
|
|||
- name: deploy
|
||||
image: bitsbeats/drone-helm3
|
||||
settings:
|
||||
kube_api_server:
|
||||
from_secret: kubernetes_server_test
|
||||
kube_token:
|
||||
from_secret: kubernetes_token_test
|
||||
kube_certificate:
|
||||
from_secret: kubernetes_cert_test
|
||||
kube_api_server: {{ .Kube.KubeApiServer }}
|
||||
kube_token: {{ .Kube.KubeToken }}
|
||||
kube_certificate: {{ .Kube.KubeCertificate }}
|
||||
chart: ./{{ .Root }}/deploy
|
||||
release: service-{{ .Name }}-test
|
||||
wait: true
|
||||
|
@ -40,7 +35,7 @@ steps:
|
|||
values:
|
||||
- nameSpace={{ .NameSpace }}
|
||||
- aliasName={{ .AliasName }}
|
||||
- image=reg.icechen.cn/{{ .NameSpace }}/service-{{ .Name }}
|
||||
- image={{ .Reg.Registry }}/{{ .NameSpace }}/service-{{ .Name }}
|
||||
- imageTag=${DRONE_COMMIT:0:8}
|
||||
- port={{ .Port }}
|
||||
|
||||
|
|
|
@ -4,6 +4,8 @@ import (
|
|||
"bytes"
|
||||
"text/template"
|
||||
|
||||
"git.icechen.cn/pkg/drone_plugin/config"
|
||||
|
||||
"git.icechen.cn/pkg/drone_plugin/go_handler/go_handler_template"
|
||||
|
||||
"git.icechen.cn/pkg/drone_plugin/consts"
|
||||
|
@ -15,17 +17,22 @@ type GoServiceHandler struct {
|
|||
AliasName string
|
||||
Root string
|
||||
Port string
|
||||
ServiceEnv map[string]string
|
||||
DeployEnv consts.Env
|
||||
|
||||
Reg config.Registry
|
||||
Kube config.KubeConfig
|
||||
}
|
||||
|
||||
func (gsh GoServiceHandler) ToDestinationConfig() (string, error) {
|
||||
var err error
|
||||
t := template.New(gsh.Name)
|
||||
gsh.Reg = config.GetRegistryConfig()
|
||||
|
||||
servicePipeline := go_handler_template.ServiceTestPipeline
|
||||
gsh.Kube = config.GetTestKubeConfigByNamespace(gsh.NameSpace)
|
||||
if gsh.DeployEnv == consts.EnvProduction {
|
||||
servicePipeline = go_handler_template.ServiceProductionPipeline
|
||||
gsh.Kube = config.GetOnlKubeConfigByNamespace(gsh.NameSpace)
|
||||
}
|
||||
|
||||
t, err = t.Parse(servicePipeline)
|
||||
|
|
Loading…
Reference in New Issue