feat:
1. diff 2. namespace
This commit is contained in:
@@ -4,10 +4,9 @@ import (
|
||||
"embed"
|
||||
_ "embed"
|
||||
"fmt"
|
||||
"git.icechen.cn/pkg/wujian_develop_tool/config"
|
||||
"github.com/sergi/go-diff/diffmatchpatch"
|
||||
"os"
|
||||
|
||||
"git.icechen.cn/pkg/wujian_develop_tool/config"
|
||||
"github.com/fatih/color"
|
||||
|
||||
"git.icechen.cn/pkg/wujian_develop_tool/util"
|
||||
@@ -16,7 +15,7 @@ import (
|
||||
//go:embed "*"
|
||||
var deployDir embed.FS
|
||||
|
||||
func GenDeploy(namespace string, api config.Api) error {
|
||||
func GenDeploy(api config.Api) error {
|
||||
color.Green("正在生成deploy...")
|
||||
|
||||
// deploy 文件夹
|
||||
@@ -33,16 +32,17 @@ func GenDeploy(namespace string, api config.Api) error {
|
||||
|
||||
path := api.Path
|
||||
if path == "" {
|
||||
path = fmt.Sprintf("/%s/%s/?(.*)", namespace, api.Name)
|
||||
path = fmt.Sprintf("/%s/%s/?(.*)", api.NameSpace, api.Name)
|
||||
}
|
||||
|
||||
data := map[string]string{
|
||||
"NameSpace": namespace,
|
||||
"NameSpace": api.NameSpace,
|
||||
"AppName": api.Name,
|
||||
"AliasName": api.AliasName,
|
||||
"Port": api.Port,
|
||||
"Host": host,
|
||||
"Path": path}
|
||||
"Path": path,
|
||||
}
|
||||
|
||||
// value.yaml
|
||||
valuesTemplate, err := deployDir.ReadFile("values.tpl")
|
||||
@@ -121,24 +121,5 @@ func copyTo(fileName string, toPath string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
toFileContent, err := os.ReadFile(toPath)
|
||||
if err == nil {
|
||||
dmp := diffmatchpatch.New()
|
||||
diffContent := dmp.DiffMain(string(fileContent), string(toFileContent), true)
|
||||
diffString := dmp.DiffToDelta(diffContent)
|
||||
if diffString == "" || util.ReadBoolWithMessage(diffString) {
|
||||
color.Red("跳过文件: %s", fileName)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
return util.WriteFile(toPath, fileContent)
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ 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 api_{{ .Name }} ./app/api/{{ .Name }}
|
||||
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" -o api_{{ .Name }} ./{{ .Root }}
|
||||
|
||||
FROM reg.icechen.cn/alpine as {{ .Name }}
|
||||
WORKDIR /go/src
|
||||
|
||||
@@ -3,6 +3,8 @@ package golang
|
||||
import (
|
||||
_ "embed"
|
||||
|
||||
"git.icechen.cn/pkg/wujian_develop_tool/config"
|
||||
|
||||
"github.com/fatih/color"
|
||||
|
||||
"git.icechen.cn/pkg/wujian_develop_tool/util"
|
||||
@@ -14,11 +16,11 @@ var dockerfileTemplate string
|
||||
//go:embed "main.tpl"
|
||||
var mainGoTemplate string
|
||||
|
||||
func GenDockerfile(name string) error {
|
||||
func GenDockerfile(api config.Api) error {
|
||||
color.Green("正在生成dockerfile...")
|
||||
err := util.TemplateToFile("app/api/"+name+"/Dockerfile", dockerfileTemplate, map[string]string{"Name": name})
|
||||
err := util.TemplateToFile(api.Root+"/Dockerfile", dockerfileTemplate, api)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return util.TemplateToFile("app/api/"+name+"/main.go", mainGoTemplate, nil)
|
||||
return util.TemplateToFile(api.Root+"/main.go", mainGoTemplate, nil)
|
||||
}
|
||||
|
||||
@@ -3,9 +3,10 @@ package deploy
|
||||
import (
|
||||
"embed"
|
||||
_ "embed"
|
||||
"git.icechen.cn/pkg/wujian_develop_tool/config"
|
||||
"os"
|
||||
|
||||
"git.icechen.cn/pkg/wujian_develop_tool/config"
|
||||
|
||||
"github.com/fatih/color"
|
||||
|
||||
"git.icechen.cn/pkg/wujian_develop_tool/util"
|
||||
@@ -14,7 +15,7 @@ import (
|
||||
//go:embed "*"
|
||||
var deployDir embed.FS
|
||||
|
||||
func GenDeploy(namespace string, service config.Service) error {
|
||||
func GenDeploy(service config.Service) error {
|
||||
color.Green("正在生成deploy...")
|
||||
|
||||
// deploy 文件夹
|
||||
@@ -25,10 +26,11 @@ func GenDeploy(namespace string, service config.Service) error {
|
||||
}
|
||||
|
||||
data := map[string]string{
|
||||
"NameSpace": namespace,
|
||||
"NameSpace": service.NameSpace,
|
||||
"AppName": service.Name,
|
||||
"AliasName": service.AliasName,
|
||||
"Port": service.Port}
|
||||
"Port": service.Port,
|
||||
}
|
||||
|
||||
// value.yaml
|
||||
valuesTemplate, err := deployDir.ReadFile("values.tpl")
|
||||
@@ -101,13 +103,5 @@ func copyTo(fileName string, toPath string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
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
|
||||
return util.WriteFile(toPath, fileContent)
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
nameSpace: {{ .NameSpace }}
|
||||
aliasName: {{ .AliasName }}
|
||||
image: reg.icechen.cn/{{ .NameSpace }}/api-{{ .AppName }}
|
||||
image: reg.icechen.cn/{{ .NameSpace }}/service-{{ .AppName }}
|
||||
imageTag: latest
|
||||
port: {{ .Port }}
|
||||
@@ -8,7 +8,7 @@ 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 }} ./app/service/{{ .Name }}
|
||||
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
|
||||
|
||||
@@ -3,6 +3,8 @@ package golang
|
||||
import (
|
||||
_ "embed"
|
||||
|
||||
"git.icechen.cn/pkg/wujian_develop_tool/config"
|
||||
|
||||
"github.com/fatih/color"
|
||||
|
||||
"git.icechen.cn/pkg/wujian_develop_tool/util"
|
||||
@@ -14,11 +16,11 @@ var dockerfileTemplate string
|
||||
//go:embed "main.tpl"
|
||||
var mainGoTemplate string
|
||||
|
||||
func GenDockerfile(name string) error {
|
||||
func GenDockerfile(service config.Service) error {
|
||||
color.Green("正在生成dockerfile...")
|
||||
err := util.TemplateToFile("app/service/"+name+"/Dockerfile", dockerfileTemplate, map[string]string{"Name": name})
|
||||
err := util.TemplateToFile(service.Root+"/Dockerfile", dockerfileTemplate, service)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return util.TemplateToFile("app/service/"+name+"/main.go", mainGoTemplate, nil)
|
||||
return util.TemplateToFile(service.Root+"/main.go", mainGoTemplate, nil)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user