Compare commits
No commits in common. "master" and "v0.0.1" have entirely different histories.
41
api.go
41
api.go
|
@ -2,14 +2,12 @@ package main
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"git.icechen.cn/pkg/wdt/util"
|
||||
"os"
|
||||
|
||||
"git.icechen.cn/pkg/wujian_develop_tool/config"
|
||||
"git.icechen.cn/pkg/wujian_develop_tool/util"
|
||||
"git.icechen.cn/pkg/wdt/template/api/deploy"
|
||||
|
||||
"git.icechen.cn/pkg/wujian_develop_tool/template/api/deploy"
|
||||
|
||||
"git.icechen.cn/pkg/wujian_develop_tool/template/api/docker/golang"
|
||||
"git.icechen.cn/pkg/wdt/template/api/docker/golang"
|
||||
|
||||
"github.com/fatih/color"
|
||||
|
||||
|
@ -19,12 +17,12 @@ import (
|
|||
|
||||
// ActionListApi API应用列表
|
||||
func ActionListApi(c *cli.Context) error {
|
||||
if err := config.Init(c); err != nil {
|
||||
if err := Init(c); err != nil {
|
||||
return err
|
||||
}
|
||||
color.Green("API应用列表:")
|
||||
for _, api := range config.Config.HasApi {
|
||||
color.Green("\t%s.%s", api.Name, api.Namespace)
|
||||
for _, api := range config.HasApi {
|
||||
color.Green("\t%s", api.Name)
|
||||
color.Green("\t\t路径:\t%s", api.Root)
|
||||
color.Green("\t\t类型:\t%s", api.Type)
|
||||
color.Green("\t\t端口:\t%s", api.Port)
|
||||
|
@ -42,7 +40,7 @@ func ActionListApi(c *cli.Context) error {
|
|||
|
||||
// ActionNewApi 创建API应用
|
||||
func ActionNewApi(c *cli.Context) error {
|
||||
if err := config.Init(c); err != nil {
|
||||
if err := Init(c); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -60,21 +58,11 @@ func ActionNewApi(c *cli.Context) error {
|
|||
appList = append(appList, appName)
|
||||
}
|
||||
for _, newApp := range appList {
|
||||
namespace := ""
|
||||
for {
|
||||
namespace = util.ReadLineWithMessage(fmt.Sprintf("请输入%s所属的项目(namespace): ", newApp))
|
||||
if namespace != "" {
|
||||
break
|
||||
} else {
|
||||
color.Red("项目名称不能为空!")
|
||||
}
|
||||
}
|
||||
color.Green("正在创建[%s]API应用...", newApp)
|
||||
app := config.Config.Api.GetApp(namespace, newApp)
|
||||
app = config.Api{
|
||||
Namespace: namespace,
|
||||
Name: newApp,
|
||||
Root: fmt.Sprintf("app/%s/api/%s", namespace, newApp),
|
||||
app := config.Api.GetApp(newApp)
|
||||
app = Api{
|
||||
Name: newApp,
|
||||
Root: "app/api/" + newApp,
|
||||
}
|
||||
|
||||
if util.ExistDir(app.Root) && !util.ReadBoolWithMessage(app.Root+"目录已存在,是否要覆盖app文件目录(y/n): ") {
|
||||
|
@ -107,17 +95,17 @@ func ActionNewApi(c *cli.Context) error {
|
|||
app.Host = util.ReadLineWithMessage("请输入API应用请求的域名(host,如:api.seamlesser.com,建议为空): ")
|
||||
app.Path = util.ReadLineWithMessage("请输入API应用请求的路由(path,如:/uwe/core/?(.*),建议为空): ")
|
||||
|
||||
err = deploy.GenDeploy(app)
|
||||
err = deploy.GenDeploy(config.Name, newApp, app.AliasName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = golang.GenDockerfile(app)
|
||||
err = golang.GenDockerfile(newApp)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = config.Config.AppendAPI(app)
|
||||
err = config.AppendAPI(app)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -129,6 +117,5 @@ func ActionNewApi(c *cli.Context) error {
|
|||
|
||||
// ActionFixApi 修复API应用
|
||||
func ActionFixApi(c *cli.Context) error {
|
||||
color.Red("开发中...")
|
||||
return nil
|
||||
}
|
||||
|
|
14
ci.go
14
ci.go
|
@ -2,7 +2,6 @@ package main
|
|||
|
||||
import (
|
||||
"context"
|
||||
"git.icechen.cn/pkg/wujian_develop_tool/config"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
|
@ -14,13 +13,14 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
ciHost = "https://ci.icechen.cn"
|
||||
ciToken = "b3e73c2e2f405e65de484d37ea48bb26"
|
||||
ciHost = "https://ci.icechen.cn"
|
||||
// ciToken = "b3e73c2e2f405e65de484d37ea48bb26"
|
||||
ciToken = "XRFPl4YgUk8ZT3q5D2dLzqNDUNhPuwCf"
|
||||
)
|
||||
|
||||
// ActionBuildCI ci创建新构建
|
||||
func ActionBuildCI(c *cli.Context) error {
|
||||
if err := config.Init(c); err != nil {
|
||||
if err := Init(c); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -43,15 +43,15 @@ func ActionBuildCI(c *cli.Context) error {
|
|||
temp := strings.Split(fInfo, string(os.PathSeparator))
|
||||
name := temp[len(temp)-1]
|
||||
|
||||
color.Red("创建构建的仓库: %s/%s@master", config.Config.Name, name)
|
||||
color.Red("创建构建的仓库: %s/%s@master", config.Name, name)
|
||||
if len(app) > 0 {
|
||||
color.Red("强制构建的应用(除了最后一次提交或指定的commit提交本应构建的应用): %+v\n\n", app)
|
||||
}
|
||||
b, err := client.BuildCreate(config.Config.Name, name, commit, "master", map[string]string{"app": app})
|
||||
b, err := client.BuildCreate(config.Name, name, commit, "master", map[string]string{"app": app})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
color.Green("构建成功!\n构建ID: %d\n去看看: %s/%s/%s/%d", b.Number, ciHost, config.Config.Name, name, b.Number)
|
||||
color.Green("构建成功!\n构建ID: %d\n去看看: %s/%s/%s/%d", b.Number, ciHost, config.Name, name, b.Number)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
package config
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/urfave/cli/v2"
|
||||
"gopkg.in/yaml.v3"
|
||||
"git.icechen.cn/pkg/wdt/util"
|
||||
"io/ioutil"
|
||||
|
||||
"git.icechen.cn/pkg/wujian_develop_tool/util"
|
||||
"github.com/urfave/cli/v2"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
var DefaultConfigFile = ".drone.yml"
|
||||
|
@ -21,13 +22,13 @@ func Init(c *cli.Context) error {
|
|||
}
|
||||
|
||||
appList := c.Args().Slice()
|
||||
Config.HasApi = Config.Api.HasApp(appList)
|
||||
Config.HasService = Config.Service.HasApp(appList)
|
||||
config.HasApi = config.Api.HasApp(appList)
|
||||
config.HasService = config.Service.HasApp(appList)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type ConfigFile struct {
|
||||
type Config struct {
|
||||
Kind string `json:"kind" yaml:"kind"`
|
||||
Type string `json:"type" yaml:"type"`
|
||||
Name string `json:"name" yaml:"name"`
|
||||
|
@ -41,9 +42,8 @@ type ConfigFile struct {
|
|||
type (
|
||||
ApiList []Api
|
||||
Api struct {
|
||||
Namespace string `json:"namespace" yaml:"namespace"`
|
||||
Name string `json:"name" yaml:"name"`
|
||||
AliasName string `json:"alias_name" yaml:"alias_name"`
|
||||
AliasName string `json:"alias_name" yaml:"aliasName"`
|
||||
Root string `json:"root" yaml:"root"`
|
||||
Type string `json:"type" yaml:"type"`
|
||||
Port string `json:"port" yaml:"port"`
|
||||
|
@ -55,33 +55,32 @@ type (
|
|||
type (
|
||||
ServiceList []Service
|
||||
Service struct {
|
||||
Namespace string `json:"namespace" yaml:"namespace"`
|
||||
Name string `json:"name" yaml:"name"`
|
||||
AliasName string `json:"alias_name" yaml:"alias_name"`
|
||||
AliasName string `json:"alias_name" yaml:"aliasName"`
|
||||
Root string `json:"root" yaml:"root"`
|
||||
Type string `json:"type" yaml:"type"`
|
||||
Port string `json:"port" yaml:"port"`
|
||||
}
|
||||
)
|
||||
|
||||
var Config ConfigFile
|
||||
var config Config
|
||||
|
||||
func ReadConfig() error {
|
||||
configFile, err := ioutil.ReadFile(DefaultConfigFile)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = yaml.Unmarshal(configFile, &Config)
|
||||
err = yaml.Unmarshal(configFile, &config)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *ConfigFile) AppendAPI(api Api) error {
|
||||
func (c *Config) AppendAPI(api Api) error {
|
||||
has := false
|
||||
for i, a := range c.Api {
|
||||
if a.Name == api.Name && a.Namespace == api.Namespace {
|
||||
if a.Name == api.Name {
|
||||
c.Api[i] = api
|
||||
has = true
|
||||
break
|
||||
|
@ -100,10 +99,10 @@ func (c *ConfigFile) AppendAPI(api Api) error {
|
|||
return util.WriteFileWithNotEdit(DefaultConfigFile, out)
|
||||
}
|
||||
|
||||
func (c *ConfigFile) AppendService(service Service) error {
|
||||
func (c *Config) AppendService(service Service) error {
|
||||
has := false
|
||||
for i, s := range c.Service {
|
||||
if s.Name == service.Name && s.Namespace == service.Namespace {
|
||||
if s.Name == service.Name {
|
||||
c.Service[i] = service
|
||||
has = true
|
||||
break
|
||||
|
@ -141,9 +140,9 @@ al:
|
|||
return hasApp
|
||||
}
|
||||
|
||||
func (sl ApiList) GetApp(namespace, appName string) Api {
|
||||
func (sl ApiList) GetApp(appName string) Api {
|
||||
for _, api := range sl {
|
||||
if api.Name == appName && api.Namespace == namespace {
|
||||
if api.Name == appName {
|
||||
return api
|
||||
}
|
||||
}
|
||||
|
@ -169,9 +168,9 @@ sl:
|
|||
return hasApp
|
||||
}
|
||||
|
||||
func (sl ServiceList) GetApp(namespace, appName string) Service {
|
||||
func (sl ServiceList) GetApp(appName string) Service {
|
||||
for _, service := range sl {
|
||||
if service.Name == appName && service.Namespace == namespace {
|
||||
if service.Name == appName {
|
||||
return service
|
||||
}
|
||||
}
|
6
go.mod
6
go.mod
|
@ -1,11 +1,10 @@
|
|||
module git.icechen.cn/pkg/wujian_develop_tool
|
||||
module git.icechen.cn/pkg/wdt
|
||||
|
||||
go 1.17
|
||||
|
||||
require (
|
||||
github.com/drone/drone-go v1.7.1
|
||||
github.com/fatih/color v1.13.0
|
||||
github.com/sergi/go-diff v1.2.0
|
||||
github.com/urfave/cli/v2 v2.3.0
|
||||
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8
|
||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
|
||||
|
@ -17,9 +16,8 @@ require (
|
|||
github.com/mattn/go-colorable v0.1.12 // indirect
|
||||
github.com/mattn/go-isatty v0.0.14 // indirect
|
||||
github.com/russross/blackfriday/v2 v2.1.0 // indirect
|
||||
golang.org/x/net v0.0.0-20220107192237-5cfca573fb4d // indirect
|
||||
golang.org/x/net v0.0.0-20220105145211-5b0dc2dfae98 // indirect
|
||||
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e // indirect
|
||||
google.golang.org/appengine v1.6.7 // indirect
|
||||
google.golang.org/protobuf v1.27.1 // indirect
|
||||
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||
)
|
||||
|
|
16
go.sum
16
go.sum
|
@ -44,8 +44,6 @@ github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:ma
|
|||
github.com/cpuguy83/go-md2man/v2 v2.0.1 h1:r/myEWzV9lfsM1tFLgDyu0atFtJ1fXn261LKYj/3DxU=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/drone/drone-go v1.7.1 h1:ZX+3Rs8YHUSUQ5mkuMLmm1zr1ttiiE2YGNxF3AnyDKw=
|
||||
github.com/drone/drone-go v1.7.1/go.mod h1:fxCf9jAnXDZV1yDr0ckTuWd1intvcQwfJmTRpTZ1mXg=
|
||||
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
||||
|
@ -124,18 +122,14 @@ github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb
|
|||
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
|
||||
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
|
||||
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
||||
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
|
||||
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
|
||||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||
github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ=
|
||||
github.com/sergi/go-diff v1.2.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
|
||||
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
|
||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||
github.com/urfave/cli/v2 v2.3.0 h1:qph92Y649prgesehzOrQjdWyxFOp/QVM+6imKHad91M=
|
||||
github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI=
|
||||
|
@ -208,8 +202,8 @@ golang.org/x/net v0.0.0-20200520182314-0ba52f642ac2/go.mod h1:qpuaurCH72eLCgpAm/
|
|||
golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
|
||||
golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
|
||||
golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
|
||||
golang.org/x/net v0.0.0-20220107192237-5cfca573fb4d h1:62NvYBuaanGXR2ZOfwDFkhhl6X1DUgf8qg3GuQvxZsE=
|
||||
golang.org/x/net v0.0.0-20220107192237-5cfca573fb4d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/net v0.0.0-20220105145211-5b0dc2dfae98 h1:+6WJMRLHlD7X7frgp7TUZ36RnQzSf9wVVTNakEp+nqY=
|
||||
golang.org/x/net v0.0.0-20220105145211-5b0dc2dfae98/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||
|
@ -392,15 +386,11 @@ google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQ
|
|||
google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ=
|
||||
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
|
||||
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
|
||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
|
|
30
health.go
30
health.go
|
@ -2,8 +2,7 @@ package main
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"git.icechen.cn/pkg/wujian_develop_tool/config"
|
||||
"git.icechen.cn/pkg/wujian_develop_tool/util"
|
||||
"git.icechen.cn/pkg/wdt/util"
|
||||
)
|
||||
|
||||
type healthResp struct {
|
||||
|
@ -34,7 +33,7 @@ func (hr healthResp) String() string {
|
|||
return b.String()
|
||||
}
|
||||
|
||||
func healthApi(api config.Api) healthResp {
|
||||
func healthApi(api Api) healthResp {
|
||||
ret := healthResp{
|
||||
Dir: false,
|
||||
Deploy: false,
|
||||
|
@ -58,28 +57,3 @@ func healthApi(api config.Api) healthResp {
|
|||
|
||||
return ret
|
||||
}
|
||||
|
||||
func healthService(service config.Service) healthResp {
|
||||
ret := healthResp{
|
||||
Dir: false,
|
||||
Deploy: false,
|
||||
Dockerfile: false,
|
||||
}
|
||||
|
||||
// Dir 健康度
|
||||
if util.ExistDir(service.Root) {
|
||||
ret.Dir = true
|
||||
}
|
||||
|
||||
// Deploy 健康度
|
||||
if util.ExistDir(service.Root + "/deploy") {
|
||||
ret.Deploy = true
|
||||
}
|
||||
|
||||
// Dockerfile 健康度
|
||||
if util.ExistFile(service.Root + "/Dockerfile") {
|
||||
ret.Dockerfile = true
|
||||
}
|
||||
|
||||
return ret
|
||||
}
|
||||
|
|
8
main.go
8
main.go
|
@ -30,7 +30,7 @@ func main() {
|
|||
app = &cli.App{
|
||||
Name: "wdt",
|
||||
Usage: "无间开发者工具箱",
|
||||
Version: "v1.0.0",
|
||||
Version: "v0.0.1",
|
||||
EnableBashCompletion: true,
|
||||
Flags: flags,
|
||||
Commands: cli.Commands{
|
||||
|
@ -67,17 +67,17 @@ func main() {
|
|||
{
|
||||
Name: "new",
|
||||
Usage: "创建一个service应用",
|
||||
Action: ActionNewService,
|
||||
Action: ActionNewApi,
|
||||
},
|
||||
{
|
||||
Name: "list",
|
||||
Usage: "service应用列表",
|
||||
Action: ActionListService,
|
||||
Action: ActionListApi,
|
||||
},
|
||||
{
|
||||
Name: "fix",
|
||||
Usage: "service应用修复",
|
||||
Action: ActionFixService,
|
||||
Action: ActionFixApi,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
132
service.go
132
service.go
|
@ -1,132 +0,0 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"git.icechen.cn/pkg/wujian_develop_tool/config"
|
||||
"git.icechen.cn/pkg/wujian_develop_tool/util"
|
||||
|
||||
"git.icechen.cn/pkg/wujian_develop_tool/template/service/deploy"
|
||||
|
||||
"git.icechen.cn/pkg/wujian_develop_tool/template/service/docker/golang"
|
||||
|
||||
"github.com/fatih/color"
|
||||
|
||||
_ "embed"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
// ActionListService Service应用列表
|
||||
func ActionListService(c *cli.Context) error {
|
||||
if err := config.Init(c); err != nil {
|
||||
return err
|
||||
}
|
||||
color.Green("Service应用列表:")
|
||||
for _, service := range config.Config.HasService {
|
||||
color.Green("\t%s.%s", service.Name, service.Namespace)
|
||||
color.Green("\t\t路径:\t%s", service.Root)
|
||||
color.Green("\t\t类型:\t%s", service.Type)
|
||||
color.Green("\t\t端口:\t%s", service.Port)
|
||||
c := color.New(color.Bold, color.FgRed)
|
||||
c.EnableColor()
|
||||
_, err := c.Println(healthService(service))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Print("\n")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ActionNewService 创建Service应用
|
||||
func ActionNewService(c *cli.Context) error {
|
||||
if err := config.Init(c); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
appList := c.Args().Slice()
|
||||
if len(appList) == 0 {
|
||||
appName := ""
|
||||
for {
|
||||
appName = util.ReadLineWithMessage("请输入要创建的service名称: ")
|
||||
if appName != "" {
|
||||
break
|
||||
} else {
|
||||
color.Red("应用名称不能为空!")
|
||||
}
|
||||
}
|
||||
appList = append(appList, appName)
|
||||
}
|
||||
for _, newApp := range appList {
|
||||
namespace := ""
|
||||
for {
|
||||
namespace = util.ReadLineWithMessage(fmt.Sprintf("请输入%s所属的项目(namespace): ", newApp))
|
||||
if namespace != "" {
|
||||
break
|
||||
} else {
|
||||
color.Red("项目名称不能为空!")
|
||||
}
|
||||
}
|
||||
color.Green("正在创建[%s]Service应用...", newApp)
|
||||
app := config.Config.Service.GetApp(namespace, newApp)
|
||||
app = config.Service{
|
||||
Namespace: namespace,
|
||||
Name: newApp,
|
||||
Root: fmt.Sprintf("app/%s/service/%s", namespace, newApp),
|
||||
}
|
||||
|
||||
if util.ExistDir(app.Root) && !util.ReadBoolWithMessage(app.Root+"目录已存在,是否要覆盖app文件目录(y/n): ") {
|
||||
return nil
|
||||
}
|
||||
|
||||
err := os.MkdirAll(app.Root, os.ModePerm)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
app.AliasName = util.ReadLineWithMessage("请输入应用的简短描述(别名): ")
|
||||
for {
|
||||
app.Type = util.ReadLineWithMessage("请输入应用的类型(默认golang): ")
|
||||
if app.Type == "golang" || app.Type == "" {
|
||||
app.Type = "golang"
|
||||
break
|
||||
} else {
|
||||
color.Red("暂不支持: [%s]类型", app.Type)
|
||||
}
|
||||
}
|
||||
for {
|
||||
app.Port = util.ReadLineWithMessage("请输入应用暴露的端口: ")
|
||||
if app.Port != "" {
|
||||
break
|
||||
} else {
|
||||
color.Red("端口号不能为空!")
|
||||
}
|
||||
}
|
||||
|
||||
err = deploy.GenDeploy(app)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = golang.GenDockerfile(app)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = config.Config.AppendService(app)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
color.Green("[%s]Service应用创建成功!!!\n\n", newApp)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ActionFixService 修复Service应用
|
||||
func ActionFixService(c *cli.Context) error {
|
||||
color.Red("开发中...")
|
||||
return nil
|
||||
}
|
|
@ -3,53 +3,34 @@ package deploy
|
|||
import (
|
||||
"embed"
|
||||
_ "embed"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"git.icechen.cn/pkg/wujian_develop_tool/config"
|
||||
"github.com/fatih/color"
|
||||
|
||||
"git.icechen.cn/pkg/wujian_develop_tool/util"
|
||||
"git.icechen.cn/pkg/wdt/util"
|
||||
)
|
||||
|
||||
//go:embed "*"
|
||||
var deployDir embed.FS
|
||||
|
||||
func GenDeploy(api config.Api) error {
|
||||
func GenDeploy(namespace string, name string, aliasName string) error {
|
||||
color.Green("正在生成deploy...")
|
||||
|
||||
// deploy 文件夹
|
||||
deployDirPath := api.Root + "/deploy"
|
||||
deployDirPath := "app/api/" + name + "/deploy"
|
||||
err := os.MkdirAll(deployDirPath, os.ModePerm)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
host := api.Host
|
||||
if host == "" {
|
||||
host = "api.seamlesser.com"
|
||||
}
|
||||
|
||||
path := api.Path
|
||||
if path == "" {
|
||||
path = fmt.Sprintf("/%s/%s/?(.*)", api.Namespace, api.Name)
|
||||
}
|
||||
|
||||
data := map[string]string{
|
||||
"NameSpace": api.Namespace,
|
||||
"AppName": api.Name,
|
||||
"AliasName": api.AliasName,
|
||||
"Port": api.Port,
|
||||
"Host": host,
|
||||
"Path": path,
|
||||
}
|
||||
|
||||
// value.yaml
|
||||
valuesTemplate, err := deployDir.ReadFile("values.tpl")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = util.TemplateToFile(deployDirPath+"/values.yaml", string(valuesTemplate), data)
|
||||
err = util.TemplateToFile(deployDirPath+"/values.yaml",
|
||||
string(valuesTemplate),
|
||||
map[string]string{"NameSpace": namespace, "AppName": name, "AliasName": aliasName})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -59,13 +40,15 @@ func GenDeploy(api config.Api) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = util.TemplateToFile(deployDirPath+"/Chart.yaml", string(chartTemplate), data)
|
||||
err = util.TemplateToFile(deployDirPath+"/Chart.yaml",
|
||||
string(chartTemplate),
|
||||
map[string]string{"NameSpace": namespace, "AppName": name, "AliasName": aliasName})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// templates 文件夹
|
||||
templatesDirPath := api.Root + "/deploy/templates"
|
||||
templatesDirPath := "app/api/" + name + "/deploy/templates"
|
||||
err = os.MkdirAll(templatesDirPath, os.ModePerm)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -83,12 +66,6 @@ func GenDeploy(api config.Api) error {
|
|||
return err
|
||||
}
|
||||
|
||||
// application.yaml 文件
|
||||
err = copyTo("templates/application.yaml", templatesDirPath+"/application.yaml")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// deployment.yaml 文件
|
||||
err = copyTo("templates/deployment.yaml", templatesDirPath+"/deployment.yaml")
|
||||
if err != nil {
|
||||
|
@ -121,5 +98,13 @@ func copyTo(fileName string, toPath string) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return util.WriteFile(toPath, fileContent)
|
||||
|
||||
toFile, err := os.OpenFile(toPath, os.O_WRONLY|os.O_TRUNC|os.O_CREATE, os.ModePerm)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer toFile.Close()
|
||||
|
||||
_, err = toFile.Write(fileContent)
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -1,20 +0,0 @@
|
|||
apiVersion: app.k8s.io/v1beta1
|
||||
kind: Application
|
||||
metadata:
|
||||
name: {{ .Release.Name }}
|
||||
namespace: {{ .Values.nameSpace }}
|
||||
labels:
|
||||
app: {{ .Release.Name }}
|
||||
app.kubernetes.io/version: v1
|
||||
app.kubernetes.io/name: {{ .Release.Name }}
|
||||
version: v1
|
||||
annotations:
|
||||
servicemesh.kubesphere.io/enabled: 'true'
|
||||
spec:
|
||||
selector:
|
||||
matchLabels:
|
||||
app: {{ .Release.Name }}
|
||||
app.kubernetes.io/version: v1
|
||||
app.kubernetes.io/name: {{ .Release.Name }}
|
||||
version: v1
|
||||
addOwnerRef: true
|
|
@ -5,32 +5,18 @@ metadata:
|
|||
namespace: {{ .Values.nameSpace }}
|
||||
labels:
|
||||
app: {{ .Release.Name }}
|
||||
app.kubernetes.io/version: v1
|
||||
app.kubernetes.io/name: {{ .Release.Name }}
|
||||
version: v1
|
||||
app.kubernetes.io/instance: {{ .Release.Name }}
|
||||
annotations:
|
||||
kubesphere.io/alias-name: {{ .Values.aliasName }}
|
||||
kubesphere.io/creator: drone
|
||||
meta.helm.sh/release-name: {{ .Release.Name }}
|
||||
meta.helm.sh/release-namespace: {{ .Values.nameSpace }}
|
||||
spec:
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
app: {{ .Release.Name }}
|
||||
app.kubernetes.io/version: v1
|
||||
app.kubernetes.io/name: {{ .Release.Name }}
|
||||
version: v1
|
||||
app.kubernetes.io/instance: {{ .Release.Name }}
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: {{ .Release.Name }}
|
||||
app.kubernetes.io/version: v1
|
||||
app.kubernetes.io/name: {{ .Release.Name }}
|
||||
version: v1
|
||||
app.kubernetes.io/instance: {{ .Release.Name }}
|
||||
spec:
|
||||
volumes:
|
||||
- name: host-time
|
||||
|
@ -41,17 +27,11 @@ spec:
|
|||
- name: {{ .Release.Name }}
|
||||
image: {{ .Values.image }}:{{ .Values.imageTag }}
|
||||
ports:
|
||||
- containerPort: {{ .Values.port }}
|
||||
protocol: TCP
|
||||
- containerPort: {{ .Values.port }}
|
||||
protocol: TCP
|
||||
env:
|
||||
- name: ENDPOINTS
|
||||
- name: endpoints
|
||||
value: 'etcd:2379'
|
||||
- name: APP_NAME
|
||||
value: {{ .Values.appName }}
|
||||
- name: NAMESPACE
|
||||
value: {{ .Values.nameSpace }}
|
||||
- name: APP_TYPE
|
||||
value: api
|
||||
resources:
|
||||
limits:
|
||||
cpu: 200m
|
||||
|
|
|
@ -4,12 +4,6 @@ apiVersion: networking.k8s.io/v1
|
|||
metadata:
|
||||
name: {{ .Release.Name }}
|
||||
namespace: {{ .Values.nameSpace }}
|
||||
labels:
|
||||
app: {{ .Release.Name }}
|
||||
app.kubernetes.io/version: v1
|
||||
app.kubernetes.io/name: {{ .Release.Name }}
|
||||
version: v1
|
||||
app.kubernetes.io/instance: {{ .Release.Name }}
|
||||
annotations:
|
||||
kubesphere.io/creator: drone
|
||||
nginx.ingress.kubernetes.io/enable-cors: 'true'
|
||||
|
|
|
@ -7,10 +7,6 @@ metadata:
|
|||
kubesphere.io/creator: drone
|
||||
labels:
|
||||
app: {{ .Release.Name }}
|
||||
app.kubernetes.io/version: v1
|
||||
app.kubernetes.io/name: {{ .Release.Name }}
|
||||
version: v1
|
||||
app.kubernetes.io/instance: {{ .Release.Name }}
|
||||
spec:
|
||||
ports:
|
||||
- name: http-{{ .Release.Name }}
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
nameSpace: {{ .NameSpace }}
|
||||
appName: {{ .AppName }}
|
||||
aliasName: {{ .AliasName }}
|
||||
image: reg.icechen.cn/{{ .NameSpace }}/api-{{ .AppName }}
|
||||
imageTag: latest
|
||||
port: {{ .Port }}
|
||||
host: {{ .Host }}
|
||||
path: {{ .Path }}
|
||||
port: 8080
|
||||
host: api.seamlesser.com
|
||||
path: /{{ .NameSpace }}/{{ .AppName }}/?(.*)
|
|
@ -4,11 +4,11 @@ ENV GOPROXY https://goproxy.io,direct
|
|||
WORKDIR /go/cache
|
||||
ADD go.mod .
|
||||
ADD go.sum .
|
||||
RUN go mod download -x
|
||||
RUN go mod download
|
||||
WORKDIR /go/src
|
||||
ADD . .
|
||||
RUN go mod tidy
|
||||
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" -o api_{{ .Name }} ./{{ .Root }}
|
||||
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" -o api_{{ .Name }} ./app/api/{{ .Name }}
|
||||
|
||||
FROM reg.icechen.cn/alpine as {{ .Name }}
|
||||
WORKDIR /go/src
|
||||
|
|
|
@ -3,11 +3,9 @@ package golang
|
|||
import (
|
||||
_ "embed"
|
||||
|
||||
"git.icechen.cn/pkg/wujian_develop_tool/config"
|
||||
|
||||
"github.com/fatih/color"
|
||||
|
||||
"git.icechen.cn/pkg/wujian_develop_tool/util"
|
||||
"git.icechen.cn/pkg/wdt/util"
|
||||
)
|
||||
|
||||
//go:embed "Dockerfile.tpl"
|
||||
|
@ -16,11 +14,11 @@ var dockerfileTemplate string
|
|||
//go:embed "main.tpl"
|
||||
var mainGoTemplate string
|
||||
|
||||
func GenDockerfile(api config.Api) error {
|
||||
func GenDockerfile(name string) error {
|
||||
color.Green("正在生成dockerfile...")
|
||||
err := util.TemplateToFile(api.Root+"/Dockerfile", dockerfileTemplate, api)
|
||||
err := util.TemplateToFile("app/api/"+name+"/Dockerfile", dockerfileTemplate, map[string]string{"Name": name})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return util.TemplateToFile(api.Root+"/main.go", mainGoTemplate, nil)
|
||||
return util.TemplateToFile("app/api/"+name+"/main.go", mainGoTemplate, nil)
|
||||
}
|
||||
|
|
|
@ -1,23 +0,0 @@
|
|||
# Patterns to ignore when building packages.
|
||||
# This supports shell glob matching, relative path matching, and
|
||||
# negation (prefixed with !). Only one pattern per line.
|
||||
.DS_Store
|
||||
# Common VCS dirs
|
||||
.git/
|
||||
.gitignore
|
||||
.bzr/
|
||||
.bzrignore
|
||||
.hg/
|
||||
.hgignore
|
||||
.svn/
|
||||
# Common backup files
|
||||
*.swp
|
||||
*.bak
|
||||
*.tmp
|
||||
*.orig
|
||||
*~
|
||||
# Various IDEs
|
||||
.project
|
||||
.idea/
|
||||
*.tmproj
|
||||
.vscode/
|
|
@ -1,24 +0,0 @@
|
|||
apiVersion: v2
|
||||
name: {{ .AppName }}
|
||||
description: {{ .AliasName }}
|
||||
|
||||
# A chart can be either an 'application' or a 'library' chart.
|
||||
#
|
||||
# Application charts are a collection of templates that can be packaged into versioned archives
|
||||
# to be deployed.
|
||||
#
|
||||
# Library charts provide useful utilities or functions for the chart developer. They're included as
|
||||
# a dependency of application charts to inject those utilities and functions into the rendering
|
||||
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
|
||||
type: application
|
||||
|
||||
# This is the chart version. This version number should be incremented each time you make changes
|
||||
# to the chart and its templates, including the app version.
|
||||
# Versions are expected to follow Semantic Versioning (https://semver.org/)
|
||||
version: 0.0.1
|
||||
|
||||
# This is the version number of the application being deployed. This version number should be
|
||||
# incremented each time you make changes to the application. Versions are not expected to
|
||||
# follow Semantic Versioning. They should reflect the version the application is using.
|
||||
# It is recommended to use it with quotes.
|
||||
appVersion: "0.0.1"
|
|
@ -1,107 +0,0 @@
|
|||
package deploy
|
||||
|
||||
import (
|
||||
"embed"
|
||||
_ "embed"
|
||||
"os"
|
||||
|
||||
"git.icechen.cn/pkg/wujian_develop_tool/config"
|
||||
|
||||
"github.com/fatih/color"
|
||||
|
||||
"git.icechen.cn/pkg/wujian_develop_tool/util"
|
||||
)
|
||||
|
||||
//go:embed "*"
|
||||
var deployDir embed.FS
|
||||
|
||||
func GenDeploy(service config.Service) error {
|
||||
color.Green("正在生成deploy...")
|
||||
|
||||
// deploy 文件夹
|
||||
deployDirPath := service.Root + "/deploy"
|
||||
err := os.MkdirAll(deployDirPath, os.ModePerm)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
data := map[string]string{
|
||||
"NameSpace": service.Namespace,
|
||||
"AppName": service.Name,
|
||||
"AliasName": service.AliasName,
|
||||
"Port": service.Port,
|
||||
}
|
||||
|
||||
// value.yaml
|
||||
valuesTemplate, err := deployDir.ReadFile("values.tpl")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = util.TemplateToFile(deployDirPath+"/values.yaml", string(valuesTemplate), data)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Chart.yaml
|
||||
chartTemplate, err := deployDir.ReadFile("Chart.tpl")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = util.TemplateToFile(deployDirPath+"/Chart.yaml", string(chartTemplate), data)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// templates 文件夹
|
||||
templatesDirPath := service.Root + "/deploy/templates"
|
||||
err = os.MkdirAll(templatesDirPath, os.ModePerm)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// .helmignore 文件
|
||||
err = copyTo(".helmignore", deployDirPath+"/.helmignore")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// _helpers.tpl 文件
|
||||
err = copyTo("templates/helpers.tpl", templatesDirPath+"/_helpers.tpl")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// application.yaml 文件
|
||||
err = copyTo("templates/application.yaml", templatesDirPath+"/application.yaml")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// deployment.yaml 文件
|
||||
err = copyTo("templates/deployment.yaml", templatesDirPath+"/deployment.yaml")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// NOTES.txt 文件
|
||||
err = copyTo("templates/NOTES.txt", templatesDirPath+"/NOTES.txt")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// service.yaml 文件
|
||||
err = copyTo("templates/service.yaml", templatesDirPath+"/service.yaml")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func copyTo(fileName string, toPath string) error {
|
||||
fileContent, err := deployDir.ReadFile(fileName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return util.WriteFile(toPath, fileContent)
|
||||
}
|
|
@ -1 +0,0 @@
|
|||
notes
|
|
@ -1,20 +0,0 @@
|
|||
apiVersion: app.k8s.io/v1beta1
|
||||
kind: Application
|
||||
metadata:
|
||||
name: {{ .Release.Name }}
|
||||
namespace: {{ .Values.nameSpace }}
|
||||
labels:
|
||||
app: {{ .Release.Name }}
|
||||
app.kubernetes.io/version: v1
|
||||
app.kubernetes.io/name: {{ .Release.Name }}
|
||||
version: v1
|
||||
annotations:
|
||||
servicemesh.kubesphere.io/enabled: 'true'
|
||||
spec:
|
||||
selector:
|
||||
matchLabels:
|
||||
app: {{ .Release.Name }}
|
||||
app.kubernetes.io/version: v1
|
||||
app.kubernetes.io/name: {{ .Release.Name }}
|
||||
version: v1
|
||||
addOwnerRef: true
|
|
@ -1,82 +0,0 @@
|
|||
kind: Deployment
|
||||
apiVersion: apps/v1
|
||||
metadata:
|
||||
name: {{ .Release.Name }}
|
||||
namespace: {{ .Values.nameSpace }}
|
||||
labels:
|
||||
app: {{ .Release.Name }}
|
||||
app.kubernetes.io/version: v1
|
||||
app.kubernetes.io/name: {{ .Release.Name }}
|
||||
version: v1
|
||||
app.kubernetes.io/instance: {{ .Release.Name }}
|
||||
annotations:
|
||||
kubesphere.io/alias-name: {{ .Values.aliasName }}
|
||||
kubesphere.io/creator: drone
|
||||
meta.helm.sh/release-name: {{ .Release.Name }}
|
||||
meta.helm.sh/release-namespace: {{ .Values.nameSpace }}
|
||||
spec:
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
app: {{ .Release.Name }}
|
||||
app.kubernetes.io/version: v1
|
||||
app.kubernetes.io/name: {{ .Release.Name }}
|
||||
version: v1
|
||||
app.kubernetes.io/instance: {{ .Release.Name }}
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: {{ .Release.Name }}
|
||||
app.kubernetes.io/version: v1
|
||||
app.kubernetes.io/name: {{ .Release.Name }}
|
||||
version: v1
|
||||
app.kubernetes.io/instance: {{ .Release.Name }}
|
||||
spec:
|
||||
volumes:
|
||||
- name: host-time
|
||||
hostPath:
|
||||
path: /etc/localtime
|
||||
type: ''
|
||||
containers:
|
||||
- name: {{ .Release.Name }}
|
||||
image: {{ .Values.image }}:{{ .Values.imageTag }}
|
||||
ports:
|
||||
- containerPort: {{ .Values.port }}
|
||||
protocol: TCP
|
||||
env:
|
||||
- name: ENDPOINTS
|
||||
value: 'etcd:2379'
|
||||
- name: APP_NAME
|
||||
value: {{ .Values.appName }}
|
||||
- name: NAMESPACE
|
||||
value: {{ .Values.nameSpace }}
|
||||
- name: APP_TYPE
|
||||
value: service
|
||||
resources:
|
||||
limits:
|
||||
cpu: 200m
|
||||
memory: 1000Mi
|
||||
requests:
|
||||
cpu: 10m
|
||||
memory: 200Mi
|
||||
volumeMounts:
|
||||
- name: host-time
|
||||
readOnly: true
|
||||
mountPath: /etc/localtime
|
||||
terminationMessagePath: /dev/termination-log
|
||||
terminationMessagePolicy: File
|
||||
imagePullPolicy: IfNotPresent
|
||||
restartPolicy: Always
|
||||
terminationGracePeriodSeconds: 30
|
||||
dnsPolicy: ClusterFirst
|
||||
securityContext: {}
|
||||
imagePullSecrets:
|
||||
- name: registry-secret
|
||||
schedulerName: default-scheduler
|
||||
strategy:
|
||||
type: RollingUpdate
|
||||
rollingUpdate:
|
||||
maxUnavailable: 25%
|
||||
maxSurge: 25%
|
||||
revisionHistoryLimit: 10
|
||||
progressDeadlineSeconds: 600
|
|
@ -1,26 +0,0 @@
|
|||
kind: Service
|
||||
apiVersion: v1
|
||||
metadata:
|
||||
name: {{ .Release.Name }}
|
||||
namespace: {{ .Values.nameSpace }}
|
||||
annotations:
|
||||
kubesphere.io/creator: drone
|
||||
labels:
|
||||
app: {{ .Release.Name }}
|
||||
app.kubernetes.io/version: v1
|
||||
app.kubernetes.io/name: {{ .Release.Name }}
|
||||
version: v1
|
||||
app.kubernetes.io/instance: {{ .Release.Name }}
|
||||
spec:
|
||||
ports:
|
||||
- name: http-{{ .Release.Name }}
|
||||
protocol: TCP
|
||||
port: 80
|
||||
targetPort: {{ .Values.port }}
|
||||
selector:
|
||||
app: {{ .Release.Name }}
|
||||
type: ClusterIP
|
||||
sessionAffinity: None
|
||||
ipFamilies:
|
||||
- IPv4
|
||||
ipFamilyPolicy: SingleStack
|
|
@ -1,6 +0,0 @@
|
|||
nameSpace: {{ .NameSpace }}
|
||||
appName: {{ .AppName }}
|
||||
aliasName: {{ .AliasName }}
|
||||
image: reg.icechen.cn/{{ .NameSpace }}/service-{{ .AppName }}
|
||||
imageTag: latest
|
||||
port: {{ .Port }}
|
|
@ -1,20 +0,0 @@
|
|||
FROM golang:1.17 as builder
|
||||
ENV GO111MODULE on
|
||||
ENV GOPROXY https://goproxy.io,direct
|
||||
WORKDIR /go/cache
|
||||
ADD go.mod .
|
||||
ADD go.sum .
|
||||
RUN go mod download -x
|
||||
WORKDIR /go/src
|
||||
ADD . .
|
||||
RUN go mod tidy
|
||||
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" -o service_{{ .Name }} ./{{ .Root }}
|
||||
|
||||
FROM reg.icechen.cn/alpine as {{ .Name }}
|
||||
WORKDIR /go/src
|
||||
COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo
|
||||
COPY --from=builder /go/src/service_{{ .Name }} ./
|
||||
ENV TZ=Asia/Shanghai
|
||||
RUN chmod +x ./service_{{ .Name }}
|
||||
EXPOSE 8080
|
||||
CMD ["./service_{{ .Name }}"]
|
|
@ -1,26 +0,0 @@
|
|||
package golang
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
|
||||
"git.icechen.cn/pkg/wujian_develop_tool/config"
|
||||
|
||||
"github.com/fatih/color"
|
||||
|
||||
"git.icechen.cn/pkg/wujian_develop_tool/util"
|
||||
)
|
||||
|
||||
//go:embed "Dockerfile.tpl"
|
||||
var dockerfileTemplate string
|
||||
|
||||
//go:embed "main.tpl"
|
||||
var mainGoTemplate string
|
||||
|
||||
func GenDockerfile(service config.Service) error {
|
||||
color.Green("正在生成dockerfile...")
|
||||
err := util.TemplateToFile(service.Root+"/Dockerfile", dockerfileTemplate, service)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return util.TemplateToFile(service.Root+"/main.go", mainGoTemplate, nil)
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
fmt.Println("我是个示例")
|
||||
}
|
|
@ -3,14 +3,12 @@ package util
|
|||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"github.com/fatih/color"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/fatih/color"
|
||||
)
|
||||
|
||||
func ReadBool() bool {
|
||||
retry:
|
||||
read := bufio.NewReader(os.Stdin)
|
||||
ret, _ := read.ReadByte()
|
||||
switch ret {
|
||||
|
@ -22,10 +20,8 @@ retry:
|
|||
fallthrough
|
||||
case 'N':
|
||||
return false
|
||||
default:
|
||||
NoNewLinePrint(color.HiRedString, "请输入(y,Y,n,N)其中之一: ")
|
||||
goto retry
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func ReadBoolWithMessage(message string) bool {
|
||||
|
|
68
util/file.go
68
util/file.go
|
@ -2,18 +2,19 @@ package util
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
"text/template"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/sergi/go-diff/diffmatchpatch"
|
||||
)
|
||||
|
||||
func TemplateToFile(desFile string, templateContent string, data interface{}) error {
|
||||
file, err := os.OpenFile(desFile, os.O_WRONLY|os.O_TRUNC|os.O_CREATE, os.ModePerm)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
tpl := template.New("template")
|
||||
tpl, err := tpl.Parse(templateContent)
|
||||
tpl, err = tpl.Parse(templateContent)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -24,66 +25,14 @@ func TemplateToFile(desFile string, templateContent string, data interface{}) er
|
|||
return err
|
||||
}
|
||||
|
||||
err = WriteFile(desFile, b.Bytes())
|
||||
_, err = file.Write(b.Bytes())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
var defaultPrintDiff = color.WhiteString
|
||||
|
||||
func IsChange(diff []diffmatchpatch.Diff) bool {
|
||||
for _, d := range diff {
|
||||
if d.Type != diffmatchpatch.DiffEqual {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// AddLine 增加行号 TODO: 颜色不完美
|
||||
func AddLine(s string) string {
|
||||
lines := strings.Split(s, "\n")
|
||||
for i, line := range lines {
|
||||
// lines[i] = fmt.Sprintf("%s %s", defaultPrintDiff("%4d.", i+1), line)
|
||||
lines[i] = fmt.Sprintf("%4d. %s", i+1, line)
|
||||
}
|
||||
return strings.Join(lines, "\n")
|
||||
}
|
||||
|
||||
func WriteFile(filePath string, data []byte) error {
|
||||
color.Green("写入[%s]文件...", filePath)
|
||||
toFileContent, err := os.ReadFile(filePath)
|
||||
if err == nil {
|
||||
dmp := diffmatchpatch.New()
|
||||
diffContent := dmp.DiffMain(string(toFileContent), string(data), true)
|
||||
|
||||
if IsChange(diffContent) {
|
||||
color.Red("文件[%s]已存在:", filePath)
|
||||
b := bytes.Buffer{}
|
||||
diffContent = dmp.DiffCleanupSemanticLossless(diffContent)
|
||||
for _, diff := range diffContent {
|
||||
switch diff.Type {
|
||||
case diffmatchpatch.DiffDelete:
|
||||
b.WriteString(color.RedString(diff.Text))
|
||||
case diffmatchpatch.DiffInsert:
|
||||
b.WriteString(color.GreenString(diff.Text))
|
||||
case diffmatchpatch.DiffEqual:
|
||||
b.WriteString(diff.Text)
|
||||
}
|
||||
}
|
||||
fmt.Println(AddLine(b.String()))
|
||||
if !ReadBoolWithMessage("是否确认此次修改(y修改/n跳过): ") {
|
||||
color.Red("跳过文件: %s\n\n", filePath)
|
||||
return nil
|
||||
}
|
||||
} else {
|
||||
color.Red("文件已存在且无变动,跳过文件: %s\n\n", filePath)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
file, err := os.OpenFile(filePath, os.O_WRONLY|os.O_TRUNC|os.O_CREATE, os.ModePerm)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -91,7 +40,6 @@ func WriteFile(filePath string, data []byte) error {
|
|||
defer file.Close()
|
||||
|
||||
_, err = file.Write(data)
|
||||
color.Red("写入文件完成: %s\n\n", filePath)
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue