feat: api部分基本完成
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
apiVersion: v2
|
||||
name: lark
|
||||
description: A Helm chart for Kubernetes
|
||||
name: {{ .AppName }}
|
||||
description: {{ .AliasName }}
|
||||
|
||||
# A chart can be either an 'application' or a 'library' chart.
|
||||
#
|
||||
@@ -15,10 +15,10 @@ 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.1.0
|
||||
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.1.0"
|
||||
appVersion: "0.0.1"
|
||||
@@ -0,0 +1,110 @@
|
||||
package deploy
|
||||
|
||||
import (
|
||||
"embed"
|
||||
_ "embed"
|
||||
"os"
|
||||
|
||||
"github.com/fatih/color"
|
||||
|
||||
"git.icechen.cn/pkg/wdt/util"
|
||||
)
|
||||
|
||||
//go:embed "*"
|
||||
var deployDir embed.FS
|
||||
|
||||
func GenDeploy(namespace string, name string, aliasName string) error {
|
||||
color.Green("正在生成deploy...")
|
||||
|
||||
// deploy 文件夹
|
||||
deployDirPath := "app/api/" + name + "/deploy"
|
||||
err := os.MkdirAll(deployDirPath, os.ModePerm)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// value.yaml
|
||||
valuesTemplate, err := deployDir.ReadFile("values.tpl")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = util.TemplateToFile(deployDirPath+"/values.yaml",
|
||||
string(valuesTemplate),
|
||||
map[string]string{"NameSpace": namespace, "AppName": name, "AliasName": aliasName})
|
||||
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),
|
||||
map[string]string{"NameSpace": namespace, "AppName": name, "AliasName": aliasName})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// templates 文件夹
|
||||
templatesDirPath := "app/api/" + name + "/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
|
||||
}
|
||||
|
||||
// deployment.yaml 文件
|
||||
err = copyTo("templates/deployment.yaml", templatesDirPath+"/deployment.yaml")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// ingress.yaml 文件
|
||||
err = copyTo("templates/ingress.yaml", templatesDirPath+"/ingress.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
|
||||
}
|
||||
|
||||
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,6 +1,6 @@
|
||||
nameSpace: {{ .NameSpace }}
|
||||
aliasName: 请输入应用的简介
|
||||
image: reg.icechen.cn/{{ .NameSpace }}/{{ .AppName }}
|
||||
aliasName: {{ .AliasName }}
|
||||
image: reg.icechen.cn/{{ .NameSpace }}/api-{{ .AppName }}
|
||||
imageTag: latest
|
||||
port: 8080
|
||||
host: api.seamlesser.com
|
||||
@@ -8,13 +8,13 @@ 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_lark ./app/api/lark
|
||||
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" -o api_{{ .Name }} ./app/api/{{ .Name }}
|
||||
|
||||
FROM reg.icechen.cn/alpine as lark
|
||||
FROM reg.icechen.cn/alpine as {{ .Name }}
|
||||
WORKDIR /go/src
|
||||
COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo
|
||||
COPY --from=builder /go/src/api_lark ./
|
||||
COPY --from=builder /go/src/api_{{ .Name }} ./
|
||||
ENV TZ=Asia/Shanghai
|
||||
RUN chmod +x ./api_lark
|
||||
RUN chmod +x ./api_{{ .Name }}
|
||||
EXPOSE 8080
|
||||
CMD ["./api_lark"]
|
||||
CMD ["./api_{{ .Name }}"]
|
||||
@@ -0,0 +1,17 @@
|
||||
package golang
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
|
||||
"github.com/fatih/color"
|
||||
|
||||
"git.icechen.cn/pkg/wdt/util"
|
||||
)
|
||||
|
||||
//go:embed "Dockerfile.tpl"
|
||||
var dockerfileTemplate string
|
||||
|
||||
func GenDockerfile(name string) error {
|
||||
color.Green("正在生成dockerfile...")
|
||||
return util.TemplateToFile("app/api/"+name+"/Dockerfile", dockerfileTemplate, map[string]string{"Name": name})
|
||||
}
|
||||
Reference in New Issue
Block a user