refactor: 整理结构和 maker 构建方式

This commit is contained in:
zhaoyupeng
2025-11-27 11:06:38 +08:00
parent 11523e3e48
commit fdad0eb36c
63 changed files with 137 additions and 153 deletions

View File

@@ -1,47 +0,0 @@
# AGENTS.md
This file provides guidance to Qoder (qoder.com) when working with code in this repository.
## Project Overview
This is a Go project (`yizhisec.com/hsv2/forge`) using Go 1.25.2.
## Development Commands
### Build
```bash
go build ./...
```
### Run Tests
```bash
go test ./...
```
### Run Single Test
```bash
go test -run TestName ./path/to/package
```
### Lint
```bash
go vet ./...
```
### Format Code
```bash
go fmt ./...
```
### Tidy Dependencies
```bash
go mod tidy
```
## Architecture
The codebase structure has not yet been established. As the project grows, update this section with:
- Main package organization
- Key architectural patterns
- Important design decisions
- Module relationships

View File

@@ -35,7 +35,7 @@ func makeCmd() *cobra.Command {
return nil return nil
} }
mk := maker.NewMaker() mk := maker.NewMaker(opt.Cfg.Make.Dir)
if err = mk.DependencyCheck(cmd.Context()); err != nil { if err = mk.DependencyCheck(cmd.Context()); err != nil {
return err return err
} }

View File

@@ -0,0 +1 @@
package cmd

View File

@@ -0,0 +1 @@
package cmd

View File

@@ -0,0 +1 @@
package cmd

View File

@@ -3,6 +3,7 @@ package makecmd
import ( import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"yizhisec.com/hsv2/forge/internal/controller/maker" "yizhisec.com/hsv2/forge/internal/controller/maker"
"yizhisec.com/hsv2/forge/internal/opt"
) )
func App() *cobra.Command { func App() *cobra.Command {
@@ -32,7 +33,7 @@ func appUser() *cobra.Command {
Use: "user", Use: "user",
Short: "Make User App", Short: "Make User App",
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
mk := maker.NewMaker() mk := maker.NewMaker(opt.Cfg.Make.Dir)
return mk.AppUser(cmd.Context(), replica) return mk.AppUser(cmd.Context(), replica)
}, },
} }
@@ -51,7 +52,7 @@ func appClient() *cobra.Command {
Use: "client", Use: "client",
Short: "Make Client App", Short: "Make Client App",
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
mk := maker.NewMaker() mk := maker.NewMaker(opt.Cfg.Make.Dir)
return mk.AppClient(cmd.Context(), replica) return mk.AppClient(cmd.Context(), replica)
}, },
} }
@@ -70,7 +71,7 @@ func appGateway() *cobra.Command {
Use: "gateway", Use: "gateway",
Short: "Make Gateway App", Short: "Make Gateway App",
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
mk := maker.NewMaker() mk := maker.NewMaker(opt.Cfg.Make.Dir)
return mk.AppGateway(cmd.Context(), replica) return mk.AppGateway(cmd.Context(), replica)
}, },
} }
@@ -89,7 +90,7 @@ func appMie() *cobra.Command {
Use: "mie", Use: "mie",
Short: "Make Mie App", Short: "Make Mie App",
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
mk := maker.NewMaker() mk := maker.NewMaker(opt.Cfg.Make.Dir)
return mk.AppMie(cmd.Context(), replica) return mk.AppMie(cmd.Context(), replica)
}, },
} }
@@ -109,7 +110,7 @@ func appOEM() *cobra.Command {
Use: "oem", Use: "oem",
Short: "Make OEM App", Short: "Make OEM App",
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
mk := maker.NewMaker() mk := maker.NewMaker(opt.Cfg.Make.Dir)
return mk.AppOEM(cmd.Context(), replica, vendor) return mk.AppOEM(cmd.Context(), replica, vendor)
}, },
} }
@@ -136,7 +137,7 @@ func appNginx() *cobra.Command {
if disableSeafile { if disableSeafile {
opts = append(opts, maker.WithoutNginxSeafile()) opts = append(opts, maker.WithoutNginxSeafile())
} }
mk := maker.NewMaker() mk := maker.NewMaker(opt.Cfg.Make.Dir)
return mk.AppNginx(cmd.Context(), opts...) return mk.AppNginx(cmd.Context(), opts...)
}, },
} }

View File

@@ -3,6 +3,7 @@ package makecmd
import ( import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"yizhisec.com/hsv2/forge/internal/controller/maker" "yizhisec.com/hsv2/forge/internal/controller/maker"
"yizhisec.com/hsv2/forge/internal/opt"
) )
func Binaries() *cobra.Command { func Binaries() *cobra.Command {
@@ -12,7 +13,7 @@ func Binaries() *cobra.Command {
Short: "Build binary files", Short: "Build binary files",
Long: `Build all required binary files for the project.`, Long: `Build all required binary files for the project.`,
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
mk := maker.NewMaker() mk := maker.NewMaker(opt.Cfg.Make.Dir)
return mk.Binary(cmd.Context()) return mk.Binary(cmd.Context())
}, },
} }

View File

@@ -3,6 +3,7 @@ package makecmd
import ( import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"yizhisec.com/hsv2/forge/internal/controller/maker" "yizhisec.com/hsv2/forge/internal/controller/maker"
"yizhisec.com/hsv2/forge/internal/opt"
) )
func ConfigMap() *cobra.Command { func ConfigMap() *cobra.Command {
@@ -11,7 +12,7 @@ func ConfigMap() *cobra.Command {
Aliases: []string{"cm"}, Aliases: []string{"cm"},
Short: "构建 ConfigMap", Short: "构建 ConfigMap",
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
mk := maker.NewMaker() mk := maker.NewMaker(opt.Cfg.Make.Dir)
return mk.ConfigMap(cmd.Context()) return mk.ConfigMap(cmd.Context())
}, },
} }

View File

@@ -3,6 +3,7 @@ package makecmd
import ( import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"yizhisec.com/hsv2/forge/internal/controller/maker" "yizhisec.com/hsv2/forge/internal/controller/maker"
"yizhisec.com/hsv2/forge/internal/opt"
) )
func EMQX() *cobra.Command { func EMQX() *cobra.Command {
@@ -10,7 +11,7 @@ func EMQX() *cobra.Command {
Use: "emqx", Use: "emqx",
Short: "Make EMQX", Short: "Make EMQX",
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
mk := maker.NewMaker() mk := maker.NewMaker(opt.Cfg.Make.Dir)
return mk.EMQX(cmd.Context()) return mk.EMQX(cmd.Context())
}, },
} }

View File

@@ -5,6 +5,7 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"yizhisec.com/hsv2/forge/internal/controller/maker" "yizhisec.com/hsv2/forge/internal/controller/maker"
"yizhisec.com/hsv2/forge/internal/opt"
) )
func ES() *cobra.Command { func ES() *cobra.Command {
@@ -18,7 +19,7 @@ func ES() *cobra.Command {
Use: "es", Use: "es",
Aliases: []string{"elastic", "elasticsearch"}, Aliases: []string{"elastic", "elasticsearch"},
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
mk := maker.NewMaker() mk := maker.NewMaker(opt.Cfg.Make.Dir)
return mk.Elastic( return mk.Elastic(
cmd.Context(), cmd.Context(),
maker.WithElasticMakeHelper(makeHelper), maker.WithElasticMakeHelper(makeHelper),

View File

@@ -3,6 +3,7 @@ package makecmd
import ( import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"yizhisec.com/hsv2/forge/internal/controller/maker" "yizhisec.com/hsv2/forge/internal/controller/maker"
"yizhisec.com/hsv2/forge/internal/opt"
) )
func Flannel() *cobra.Command { func Flannel() *cobra.Command {
@@ -15,7 +16,7 @@ func Flannel() *cobra.Command {
Short: "Build Flannel resources", Short: "Build Flannel resources",
Long: `Build and prepare Flannel network resources.`, Long: `Build and prepare Flannel network resources.`,
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
mk := maker.NewMaker() mk := maker.NewMaker(opt.Cfg.Make.Dir)
return mk.Flannel(cmd.Context(), _mode) return mk.Flannel(cmd.Context(), _mode)
}, },
} }

View File

@@ -3,6 +3,7 @@ package makecmd
import ( import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"yizhisec.com/hsv2/forge/internal/controller/maker" "yizhisec.com/hsv2/forge/internal/controller/maker"
"yizhisec.com/hsv2/forge/internal/opt"
) )
func HSNet() *cobra.Command { func HSNet() *cobra.Command {
@@ -11,7 +12,7 @@ func HSNet() *cobra.Command {
Short: "Build hs-net", Short: "Build hs-net",
Long: `Build hs-net`, Long: `Build hs-net`,
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
mk := maker.NewMaker() mk := maker.NewMaker(opt.Cfg.Make.Dir)
return mk.HSNet(cmd.Context()) return mk.HSNet(cmd.Context())
}, },
} }

View File

@@ -21,7 +21,7 @@ func Images() *cobra.Command {
return err return err
} }
mk := maker.NewMaker() mk := maker.NewMaker(opt.Cfg.Make.Dir)
return mk.Images(cmd.Context()) return mk.Images(cmd.Context())
}, },

View File

@@ -3,6 +3,7 @@ package makecmd
import ( import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"yizhisec.com/hsv2/forge/internal/controller/maker" "yizhisec.com/hsv2/forge/internal/controller/maker"
"yizhisec.com/hsv2/forge/internal/opt"
) )
func LessDNS() *cobra.Command { func LessDNS() *cobra.Command {
@@ -11,7 +12,7 @@ func LessDNS() *cobra.Command {
Short: "Build lessdns", Short: "Build lessdns",
Long: `Build lessdns`, Long: `Build lessdns`,
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
mk := maker.NewMaker() mk := maker.NewMaker(opt.Cfg.Make.Dir)
return mk.LessDNS(cmd.Context()) return mk.LessDNS(cmd.Context())
}, },
} }

View File

@@ -3,6 +3,7 @@ package makecmd
import ( import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"yizhisec.com/hsv2/forge/internal/controller/maker" "yizhisec.com/hsv2/forge/internal/controller/maker"
"yizhisec.com/hsv2/forge/internal/opt"
) )
func Longhorn() *cobra.Command { func Longhorn() *cobra.Command {
@@ -15,7 +16,7 @@ func Longhorn() *cobra.Command {
Short: "Build Longhorn resources", Short: "Build Longhorn resources",
Long: `Build and prepare Longhorn storage resources.`, Long: `Build and prepare Longhorn storage resources.`,
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
mk := maker.NewMaker() mk := maker.NewMaker(opt.Cfg.Make.Dir)
return mk.Longhorn(cmd.Context(), replicaCount) return mk.Longhorn(cmd.Context(), replicaCount)
}, },
} }

View File

@@ -5,6 +5,7 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"yizhisec.com/hsv2/forge/internal/controller/maker" "yizhisec.com/hsv2/forge/internal/controller/maker"
"yizhisec.com/hsv2/forge/internal/opt"
) )
func Mysql() *cobra.Command { func Mysql() *cobra.Command {
@@ -23,7 +24,7 @@ func Mysql() *cobra.Command {
maker.WithMySQLStorage(fmt.Sprintf("%dGi", storage)), maker.WithMySQLStorage(fmt.Sprintf("%dGi", storage)),
} }
mk := maker.NewMaker() mk := maker.NewMaker(opt.Cfg.Make.Dir)
return mk.MySQL(cmd.Context(), opts...) return mk.MySQL(cmd.Context(), opts...)
}, },
} }

View File

@@ -3,6 +3,7 @@ package makecmd
import ( import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"yizhisec.com/hsv2/forge/internal/controller/maker" "yizhisec.com/hsv2/forge/internal/controller/maker"
"yizhisec.com/hsv2/forge/internal/opt"
) )
func Proxy() *cobra.Command { func Proxy() *cobra.Command {
@@ -10,7 +11,7 @@ func Proxy() *cobra.Command {
Use: "proxy", Use: "proxy",
Short: "Make Proxy(by caddy)", Short: "Make Proxy(by caddy)",
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
mk := maker.NewMaker() mk := maker.NewMaker(opt.Cfg.Make.Dir)
return mk.Proxy(cmd.Context()) return mk.Proxy(cmd.Context())
}, },
} }

View File

@@ -3,6 +3,7 @@ package makecmd
import ( import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"yizhisec.com/hsv2/forge/internal/controller/maker" "yizhisec.com/hsv2/forge/internal/controller/maker"
"yizhisec.com/hsv2/forge/internal/opt"
) )
func Redis() *cobra.Command { func Redis() *cobra.Command {
@@ -17,7 +18,7 @@ func Redis() *cobra.Command {
Short: "Build Redis resources", Short: "Build Redis resources",
Long: `Build and prepare Redis cache resources.`, Long: `Build and prepare Redis cache resources.`,
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
mk := maker.NewMaker() mk := maker.NewMaker(opt.Cfg.Make.Dir)
return mk.Redis( return mk.Redis(
cmd.Context(), cmd.Context(),
maker.WithRedisReplicaCount(replicas), maker.WithRedisReplicaCount(replicas),

View File

@@ -3,6 +3,7 @@ package makecmd
import ( import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"yizhisec.com/hsv2/forge/internal/controller/maker" "yizhisec.com/hsv2/forge/internal/controller/maker"
"yizhisec.com/hsv2/forge/internal/opt"
) )
func Seafile() *cobra.Command { func Seafile() *cobra.Command {
@@ -15,7 +16,7 @@ func Seafile() *cobra.Command {
Use: "seafile", Use: "seafile",
Short: "make seafile dependency", Short: "make seafile dependency",
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
mk := maker.NewMaker() mk := maker.NewMaker(opt.Cfg.Make.Dir)
return mk.Seafile(cmd.Context()) return mk.Seafile(cmd.Context())
}, },
} }

View File

@@ -3,6 +3,7 @@ package makecmd
import ( import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"yizhisec.com/hsv2/forge/internal/controller/maker" "yizhisec.com/hsv2/forge/internal/controller/maker"
"yizhisec.com/hsv2/forge/internal/opt"
) )
func Yosguard() *cobra.Command { func Yosguard() *cobra.Command {
@@ -11,7 +12,7 @@ func Yosguard() *cobra.Command {
Aliases: []string{"YOS"}, Aliases: []string{"YOS"},
Short: "Make Yosguard", Short: "Make Yosguard",
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
mk := maker.NewMaker() mk := maker.NewMaker(opt.Cfg.Make.Dir)
return mk.Yosguard(cmd.Context()) return mk.Yosguard(cmd.Context())
}, },
} }

View File

@@ -9,6 +9,7 @@ import (
) )
type installer struct { type installer struct {
workdir string
target string target string
} }
@@ -34,6 +35,6 @@ func (i *installer) targetOK(ctx context.Context) error {
return nil return nil
} }
func NewInstaller(target string) *installer { func NewInstaller(workdir, target string) *installer {
return &installer{target: target} return &installer{workdir: workdir, target: target}
} }

View File

@@ -7,7 +7,6 @@ import (
"path/filepath" "path/filepath"
"gitea.loveuer.com/yizhisec/pkg3/logger" "gitea.loveuer.com/yizhisec/pkg3/logger"
"yizhisec.com/hsv2/forge/internal/opt"
"yizhisec.com/hsv2/forge/pkg/resource" "yizhisec.com/hsv2/forge/pkg/resource"
) )
@@ -204,7 +203,7 @@ kubectl rollout restart deployment client-deployment -n hsv2`
) )
var ( var (
err error err error
workdir = filepath.Join(opt.Cfg.Make.Dir, "app", "client") workdir = filepath.Join(m.workdir, "app", "client")
) )
logger.Info("☑️ maker.AppClient: 开始构建 client 应用..., dir = %s", workdir) logger.Info("☑️ maker.AppClient: 开始构建 client 应用..., dir = %s", workdir)

View File

@@ -7,7 +7,6 @@ import (
"path/filepath" "path/filepath"
"gitea.loveuer.com/yizhisec/pkg3/logger" "gitea.loveuer.com/yizhisec/pkg3/logger"
"yizhisec.com/hsv2/forge/internal/opt"
"yizhisec.com/hsv2/forge/pkg/resource" "yizhisec.com/hsv2/forge/pkg/resource"
) )
@@ -57,7 +56,7 @@ kubectl rollout restart deployment gateway-deployment -n hsv2`
) )
var ( var (
err error err error
workdir = filepath.Join(opt.Cfg.Make.Dir, "app", "gateway") workdir = filepath.Join(m.workdir, "app", "gateway")
) )
logger.Info("☑️ maker.AppGateway: 开始构建 gateway 应用..., dir = %s", workdir) logger.Info("☑️ maker.AppGateway: 开始构建 gateway 应用..., dir = %s", workdir)

View File

@@ -7,7 +7,6 @@ import (
"path/filepath" "path/filepath"
"gitea.loveuer.com/yizhisec/pkg3/logger" "gitea.loveuer.com/yizhisec/pkg3/logger"
"yizhisec.com/hsv2/forge/internal/opt"
"yizhisec.com/hsv2/forge/pkg/resource" "yizhisec.com/hsv2/forge/pkg/resource"
) )
@@ -134,7 +133,7 @@ kubectl rollout restart deployment api-deployment -n hsv2`
) )
var ( var (
err error err error
workdir = filepath.Join(opt.Cfg.Make.Dir, "app", "mie") workdir = filepath.Join(m.workdir, "app", "mie")
) )
logger.Info("☑️ maker.AppMie: 开始构建 mie ... workdir = %s", workdir) logger.Info("☑️ maker.AppMie: 开始构建 mie ... workdir = %s", workdir)

View File

@@ -8,7 +8,6 @@ import (
"gitea.loveuer.com/yizhisec/pkg3/logger" "gitea.loveuer.com/yizhisec/pkg3/logger"
"github.com/samber/lo" "github.com/samber/lo"
"yizhisec.com/hsv2/forge/internal/opt"
"yizhisec.com/hsv2/forge/pkg/resource" "yizhisec.com/hsv2/forge/pkg/resource"
) )
@@ -65,7 +64,7 @@ kubectl rollout restart deployment nginx-deployment -n hsv2`
) )
var ( var (
err error err error
workdir = filepath.Join(opt.Cfg.Make.Dir, "app", "nginx") workdir = filepath.Join(m.workdir, "app", "nginx")
o = nginxOpt{ o = nginxOpt{
WithoutSeafile: false, WithoutSeafile: false,
Replica: 2, Replica: 2,

View File

@@ -9,7 +9,6 @@ import (
"gitea.loveuer.com/yizhisec/pkg3/logger" "gitea.loveuer.com/yizhisec/pkg3/logger"
"github.com/samber/lo" "github.com/samber/lo"
"yizhisec.com/hsv2/forge/internal/opt"
"yizhisec.com/hsv2/forge/pkg/archiver" "yizhisec.com/hsv2/forge/pkg/archiver"
"yizhisec.com/hsv2/forge/pkg/resource" "yizhisec.com/hsv2/forge/pkg/resource"
) )
@@ -69,7 +68,7 @@ CMD ["nginx", "-g", "daemon off;"]`
err error err error
_vendor *Vendor _vendor *Vendor
ok bool ok bool
workdir = filepath.Join(opt.Cfg.Make.Dir, "app", "oem") workdir = filepath.Join(m.workdir, "app", "oem")
output []byte output []byte
) )
@@ -142,7 +141,19 @@ CMD ["nginx", "-g", "daemon off;"]`
} }
logger.Debug("✅ maker.AppOEM: docker image 构建成功, image = %s", imageName) logger.Debug("✅ maker.AppOEM: docker image 构建成功, image = %s", imageName)
// 6. render oem.yaml // 6. save docker image to image dir
logger.Debug("☑️ maker.AppOEM: 开始保存 docker image = %s 到 %s", imageName, filepath.Join(m.workdir, "image", imageName))
if err = os.MkdirAll(filepath.Join(m.workdir, "dependency", "image"), 0o755); err != nil {
logger.Debug("❌ maker.AppOEM: image 目录创建失败, err = %v", err)
return err
}
if err = exec.CommandContext(ctx, "docker", "save", "-o", filepath.Join(m.workdir, "dependency", "image", "app.oem.tar"), imageName).Run(); err != nil {
logger.Debug("❌ maker.AppOEM: docker image 保存失败, err = %v", err)
return err
}
logger.Debug("✅ maker.AppOEM: docker image 保存成功, image = %s", imageName)
// 7. render oem.yaml
logger.Debug("☑️ maker.AppOEM: 开始渲染 deployment.yaml") logger.Debug("☑️ maker.AppOEM: 开始渲染 deployment.yaml")
oemYAML := fmt.Sprintf(resource.YAMLAppOEM, replica, imageName) oemYAML := fmt.Sprintf(resource.YAMLAppOEM, replica, imageName)
if err = os.WriteFile( if err = os.WriteFile(

View File

@@ -7,7 +7,6 @@ import (
"path/filepath" "path/filepath"
"gitea.loveuer.com/yizhisec/pkg3/logger" "gitea.loveuer.com/yizhisec/pkg3/logger"
"yizhisec.com/hsv2/forge/internal/opt"
"yizhisec.com/hsv2/forge/pkg/resource" "yizhisec.com/hsv2/forge/pkg/resource"
) )
@@ -85,7 +84,7 @@ kubectl rollout restart deployment user-deployment -n hsv2`
) )
var ( var (
err error err error
workdir = filepath.Join(opt.Cfg.Make.Dir, "app", "user") workdir = filepath.Join(m.workdir, "app", "user")
) )
logger.Info("☑️ maker.AppUser: 开始构建 user 应用..., dir = %s", workdir) logger.Info("☑️ maker.AppUser: 开始构建 user 应用..., dir = %s", workdir)

View File

@@ -5,14 +5,13 @@ import (
"path/filepath" "path/filepath"
"gitea.loveuer.com/yizhisec/pkg3/logger" "gitea.loveuer.com/yizhisec/pkg3/logger"
"yizhisec.com/hsv2/forge/internal/opt"
"yizhisec.com/hsv2/forge/pkg/archiver" "yizhisec.com/hsv2/forge/pkg/archiver"
) )
func (m *maker) Binary(ctx context.Context) error { func (m *maker) Binary(ctx context.Context) error {
var ( var (
tarURL = "https://artifactory.yizhisec.com:443/artifactory/filestore/hsv3/k8s-bin.tar" tarURL = "https://artifactory.yizhisec.com:443/artifactory/filestore/hsv3/k8s-bin.tar"
binDir = filepath.Join(opt.Cfg.Make.Dir, "dependency") binDir = filepath.Join(m.workdir, "dependency")
) )
logger.Info("☑️ 开始准备 k8s 二进制文件...") logger.Info("☑️ 开始准备 k8s 二进制文件...")

View File

@@ -9,7 +9,6 @@ import (
"gitea.loveuer.com/yizhisec/pkg3/logger" "gitea.loveuer.com/yizhisec/pkg3/logger"
"github.com/samber/lo" "github.com/samber/lo"
"yizhisec.com/hsv2/forge/internal/opt"
"yizhisec.com/hsv2/forge/pkg/downloader" "yizhisec.com/hsv2/forge/pkg/downloader"
"yizhisec.com/hsv2/forge/pkg/extractor" "yizhisec.com/hsv2/forge/pkg/extractor"
"yizhisec.com/hsv2/forge/pkg/tool/random" "yizhisec.com/hsv2/forge/pkg/tool/random"
@@ -101,7 +100,7 @@ kubectl create configmap ssl-web-crt --namespace hsv2 --from-file=web.server.crt
var ( var (
err error err error
dir = filepath.Join(opt.Cfg.Make.Dir, "configmap") dir = filepath.Join(m.workdir, "configmap")
vendorUrlMap = map[string]string{ vendorUrlMap = map[string]string{
"standard": "https://artifactory.yizhisec.com/artifactory/yizhisec-release/oem/release/2.1.0-std/oem.tar.gz", "standard": "https://artifactory.yizhisec.com/artifactory/yizhisec-release/oem/release/2.1.0-std/oem.tar.gz",
"elink": "https://artifactory.yizhisec.com/artifactory/yizhisec-release/oem/release/2.1.0-std/oem_csgElink.tar.gz", "elink": "https://artifactory.yizhisec.com/artifactory/yizhisec-release/oem/release/2.1.0-std/oem_csgElink.tar.gz",

View File

@@ -65,8 +65,8 @@ RUN chmod +x /data/create_index.sh
var ( var (
err error err error
output []byte output []byte
location = filepath.Join(opt.Cfg.Make.Dir, "dependency", "elastic") location = filepath.Join(m.workdir, "dependency", "elastic")
helperTarLocation = filepath.Join(opt.Cfg.Make.Dir, "dependency", "image", "es-init-helper.alpine-3.22.2.tar") helperTarLocation = filepath.Join(m.workdir, "dependency", "image", "es-init-helper.alpine-3.22.2.tar")
) )
opt := &elasticOpt{ opt := &elasticOpt{

View File

@@ -6,14 +6,13 @@ import (
"path/filepath" "path/filepath"
"gitea.loveuer.com/yizhisec/pkg3/logger" "gitea.loveuer.com/yizhisec/pkg3/logger"
"yizhisec.com/hsv2/forge/internal/opt"
"yizhisec.com/hsv2/forge/pkg/resource" "yizhisec.com/hsv2/forge/pkg/resource"
) )
func (m *maker) EMQX(ctx context.Context) error { func (m *maker) EMQX(ctx context.Context) error {
var ( var (
err error err error
location = filepath.Join(opt.Cfg.Make.Dir, "emqx") location = filepath.Join(m.workdir, "emqx")
) )
logger.Info("☑️ maker.EMQX: 开始构建 emqx(mqtt) 依赖...") logger.Info("☑️ maker.EMQX: 开始构建 emqx(mqtt) 依赖...")

View File

@@ -7,14 +7,13 @@ import (
"path/filepath" "path/filepath"
"gitea.loveuer.com/yizhisec/pkg3/logger" "gitea.loveuer.com/yizhisec/pkg3/logger"
"yizhisec.com/hsv2/forge/internal/opt"
"yizhisec.com/hsv2/forge/pkg/resource" "yizhisec.com/hsv2/forge/pkg/resource"
) )
func (m *maker) Flannel(ctx context.Context, mode string) error { func (m *maker) Flannel(ctx context.Context, mode string) error {
var ( var (
err error err error
location = filepath.Join(opt.Cfg.Make.Dir, "dependency", "flannel") location = filepath.Join(m.workdir, "dependency", "flannel")
) )
logger.Info("☑️ 开始构建 flannel 资源...") logger.Info("☑️ 开始构建 flannel 资源...")

View File

@@ -6,7 +6,6 @@ import (
"path/filepath" "path/filepath"
"gitea.loveuer.com/yizhisec/pkg3/logger" "gitea.loveuer.com/yizhisec/pkg3/logger"
"yizhisec.com/hsv2/forge/internal/opt"
) )
func (m *maker) HSNet(ctx context.Context) error { func (m *maker) HSNet(ctx context.Context) error {
@@ -67,7 +66,7 @@ WantedBy=multi-user.target`
) )
var ( var (
err error err error
location = filepath.Join(opt.Cfg.Make.Dir, "dependency", "hs-net") location = filepath.Join(m.workdir, "dependency", "hs-net")
) )
if err = os.MkdirAll(location, 0755); err != nil { if err = os.MkdirAll(location, 0755); err != nil {

View File

@@ -8,7 +8,6 @@ import (
"gitea.loveuer.com/yizhisec/pkg3/logger" "gitea.loveuer.com/yizhisec/pkg3/logger"
"github.com/samber/lo" "github.com/samber/lo"
"yizhisec.com/hsv2/forge/internal/opt"
"yizhisec.com/hsv2/forge/pkg/model" "yizhisec.com/hsv2/forge/pkg/model"
) )
@@ -160,7 +159,7 @@ func (m *maker) Images(ctx context.Context) error {
} }
for _, image := range images { for _, image := range images {
image.Save = filepath.Join(opt.Cfg.Make.Dir, "dependency", "image", image.Save) image.Save = filepath.Join(m.workdir, "dependency", "image", image.Save)
} }
logger.Info("☑️ 开始获取镜像(s)...") logger.Info("☑️ 开始获取镜像(s)...")

View File

@@ -8,7 +8,7 @@ import (
func TestImage(t *testing.T) { func TestImage(t *testing.T) {
logger.SetLogLevel(logger.LogLevelDebug) logger.SetLogLevel(logger.LogLevelDebug)
m := NewMaker() m := NewMaker("./x-data")
m.Image(t.Context(), "docker.io/nginx:1.29.3-alpine3.22", m.Image(t.Context(), "docker.io/nginx:1.29.3-alpine3.22",
WithImageFallback("swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/nginx:1.29.3-alpine3.22"), WithImageFallback("swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/nginx:1.29.3-alpine3.22"),
WithImageSave("/root/nginx.tar"), WithImageSave("/root/nginx.tar"),

View File

@@ -6,14 +6,13 @@ import (
"path/filepath" "path/filepath"
"gitea.loveuer.com/yizhisec/pkg3/logger" "gitea.loveuer.com/yizhisec/pkg3/logger"
"yizhisec.com/hsv2/forge/internal/opt"
"yizhisec.com/hsv2/forge/pkg/resource" "yizhisec.com/hsv2/forge/pkg/resource"
) )
func (m *maker) LessDNS(ctx context.Context) error { func (m *maker) LessDNS(ctx context.Context) error {
var ( var (
err error err error
location = filepath.Join(opt.Cfg.Make.Dir, "dependency", "less-dns") location = filepath.Join(m.workdir, "dependency", "less-dns")
) )
logger.Info("☑️ maker.LessDNS: 开始构建 less-dns...") logger.Info("☑️ maker.LessDNS: 开始构建 less-dns...")

View File

@@ -7,7 +7,6 @@ import (
"path/filepath" "path/filepath"
"gitea.loveuer.com/yizhisec/pkg3/logger" "gitea.loveuer.com/yizhisec/pkg3/logger"
"yizhisec.com/hsv2/forge/internal/opt"
"yizhisec.com/hsv2/forge/pkg/downloader" "yizhisec.com/hsv2/forge/pkg/downloader"
) )
@@ -26,7 +25,7 @@ persistence:
var ( var (
err error err error
chartURL = "https://artifactory.yizhisec.com:443/artifactory/filestore/hsv3/charts/longhorn-1.10.0.tgz" chartURL = "https://artifactory.yizhisec.com:443/artifactory/filestore/hsv3/charts/longhorn-1.10.0.tgz"
longhornDir = filepath.Join(opt.Cfg.Make.Dir, "dependency", "longhorn") longhornDir = filepath.Join(m.workdir, "dependency", "longhorn")
chartFile = filepath.Join(longhornDir, "longhorn-1.10.0.tgz") chartFile = filepath.Join(longhornDir, "longhorn-1.10.0.tgz")
valuesFile = filepath.Join(longhornDir, "values.yaml") valuesFile = filepath.Join(longhornDir, "values.yaml")
) )
@@ -35,7 +34,7 @@ persistence:
logger.Debug("下载地址: %s", chartURL) logger.Debug("下载地址: %s", chartURL)
logger.Debug("目标目录: %s", longhornDir) logger.Debug("目标目录: %s", longhornDir)
if err = os.MkdirAll(filepath.Join(opt.Cfg.Make.Dir, "dependency", "longhorn"), 0755); err != nil { if err = os.MkdirAll(filepath.Join(m.workdir, "dependency", "longhorn"), 0755); err != nil {
return err return err
} }

View File

@@ -1,7 +1,9 @@
package maker package maker
type maker struct{} type maker struct {
workdir string
func NewMaker() *maker { }
return &maker{}
func NewMaker(workdir string) *maker {
return &maker{workdir: workdir}
} }

View File

@@ -94,7 +94,6 @@ spec:
# values: ["mysql-cluster"] # values: ["mysql-cluster"]
# topologyKey: "kubernetes.io/hostname" # 确保不同节点 # topologyKey: "kubernetes.io/hostname" # 确保不同节点
--- ---
apiVersion: mysql.presslabs.org/v1alpha1 apiVersion: mysql.presslabs.org/v1alpha1
kind: MysqlDatabase kind: MysqlDatabase
metadata: metadata:
@@ -117,7 +116,7 @@ spec:
err error err error
chartURL = "https://artifactory.yizhisec.com:443/artifactory/filestore/hsv3/charts/mysql-operator-0.6.3.tgz" chartURL = "https://artifactory.yizhisec.com:443/artifactory/filestore/hsv3/charts/mysql-operator-0.6.3.tgz"
mysqlDir = filepath.Join(opt.Cfg.Make.Dir, "dependency", "mysql") mysqlDir = filepath.Join(m.workdir, "dependency", "mysql")
chartFile = filepath.Join(mysqlDir, "mysql-operator-0.6.3.tgz") chartFile = filepath.Join(mysqlDir, "mysql-operator-0.6.3.tgz")
clusterFile = filepath.Join(mysqlDir, "cluster.yaml") clusterFile = filepath.Join(mysqlDir, "cluster.yaml")
) )

View File

@@ -6,7 +6,6 @@ import (
"path/filepath" "path/filepath"
"gitea.loveuer.com/yizhisec/pkg3/logger" "gitea.loveuer.com/yizhisec/pkg3/logger"
"yizhisec.com/hsv2/forge/internal/opt"
"yizhisec.com/hsv2/forge/pkg/downloader" "yizhisec.com/hsv2/forge/pkg/downloader"
) )
@@ -46,7 +45,7 @@ RestartSec=5
WantedBy=multi-user.target` WantedBy=multi-user.target`
) )
location := filepath.Join(opt.Cfg.Make.Dir, "dependency", "proxy") location := filepath.Join(m.workdir, "dependency", "proxy")
logger.Info("☑️ maker.Proxy: 开始构建 caddy 反向代理...") logger.Info("☑️ maker.Proxy: 开始构建 caddy 反向代理...")
logger.Debug("☑️ maker.Proxy: 创建目录 %s", location) logger.Debug("☑️ maker.Proxy: 创建目录 %s", location)

View File

@@ -90,7 +90,7 @@ metrics:
fn(o) fn(o)
} }
redisDir := filepath.Join(opt.Cfg.Make.Dir, "dependency", "redis") redisDir := filepath.Join(m.workdir, "dependency", "redis")
chartFile := filepath.Join(redisDir, chartFilename) chartFile := filepath.Join(redisDir, chartFilename)
valuesFile := filepath.Join(redisDir, "values.yaml") valuesFile := filepath.Join(redisDir, "values.yaml")

View File

@@ -123,7 +123,7 @@ kubectl rollout restart deployment backup-seafile-deployment -n seafile`
ServerHostname: "cloud.hybridscope.com", ServerHostname: "cloud.hybridscope.com",
Storage: "50Gi", Storage: "50Gi",
} }
workdir = filepath.Join(opt.Cfg.Make.Dir, "dependency", "seafile") workdir = filepath.Join(m.workdir, "dependency", "seafile")
) )
for _, fn := range opts { for _, fn := range opts {
@@ -187,7 +187,7 @@ kubectl rollout restart deployment backup-seafile-deployment -n seafile`
// 7. prepare images // 7. prepare images
logger.Debug("☑️ make.Seafile: 准备 images") logger.Debug("☑️ make.Seafile: 准备 images")
imgDir := filepath.Join(opt.Cfg.Make.Dir, "dependency", "image") imgDir := filepath.Join(m.workdir, "dependency", "image")
if err = os.MkdirAll(imgDir, 0755); err != nil { if err = os.MkdirAll(imgDir, 0755); err != nil {
logger.Error("❌ make.Seafile: 准备 images 目录: %s 失败, err = %v", imgDir, err) logger.Error("❌ make.Seafile: 准备 images 目录: %s 失败, err = %v", imgDir, err)
return err return err

View File

@@ -6,7 +6,6 @@ import (
"path/filepath" "path/filepath"
"gitea.loveuer.com/yizhisec/pkg3/logger" "gitea.loveuer.com/yizhisec/pkg3/logger"
"yizhisec.com/hsv2/forge/internal/opt"
"yizhisec.com/hsv2/forge/pkg/downloader" "yizhisec.com/hsv2/forge/pkg/downloader"
"yizhisec.com/hsv2/forge/pkg/resource" "yizhisec.com/hsv2/forge/pkg/resource"
) )
@@ -64,7 +63,7 @@ WantedBy=multi-user.target`
binURL = "https://artifactory.yizhisec.com:443/artifactory/filestore/hsv2/bin/yosguard" binURL = "https://artifactory.yizhisec.com:443/artifactory/filestore/hsv2/bin/yosguard"
) )
location := filepath.Join(opt.Cfg.Make.Dir, "dependency", "yosguard") location := filepath.Join(m.workdir, "dependency", "yosguard")
logger.Info("☑️ maker.Yosguard: 开始构建 yosguard...") logger.Info("☑️ maker.Yosguard: 开始构建 yosguard...")
logger.Debug("☑️ maker.Yosguard: 创建目录 %s", location) logger.Debug("☑️ maker.Yosguard: 创建目录 %s", location)

View File

@@ -5,10 +5,15 @@ import (
"os" "os"
"os/signal" "os/signal"
"syscall" "syscall"
"time"
"yizhisec.com/hsv2/forge/internal/cmd" "yizhisec.com/hsv2/forge/internal/cmd"
) )
func init() {
time.Local = time.FixedZone("CST", 8*60*60)
}
func main() { func main() {
ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
defer cancel() defer cancel()

View File

@@ -5,58 +5,58 @@ import (
) )
var ( var (
//go:embed flannel.yaml //go:embed yaml/flannel.yaml
YAMLFlannel string YAMLFlannel string
//go:embed es.yaml //go:embed yaml/es.yaml
YAMLES string YAMLES string
//go:embed kibana.yaml //go:embed yaml/kibana.yaml
YAMLKibana []byte YAMLKibana []byte
//go:embed es.init.sh //go:embed sh/es.init.sh
BashESInit []byte BashESInit []byte
//go:embed emqx.yaml //go:embed yaml/emqx.yaml
YAMLEMQX []byte YAMLEMQX []byte
//go:embed yosguard.create.sql //go:embed sql/yosguard.create.sql
SQLYosguard []byte SQLYosguard []byte
//go:embed less-dns.yaml //go:embed yaml/less-dns.yaml
YAMLLessDNS []byte YAMLLessDNS []byte
//go:embed seafile.yaml //go:embed yaml/seafile.yaml
YAMLSeafile string YAMLSeafile string
//go:embed backup-seafile.yaml //go:embed yaml/backup-seafile.yaml
YAMLBackupSeafile string YAMLBackupSeafile string
//go:embed app.user.yaml //go:embed yaml/app.user.yaml
YAMLAppUser string YAMLAppUser string
//go:embed app.gateway.yaml //go:embed yaml/app.gateway.yaml
YAMLAppGateway string YAMLAppGateway string
//go:embed app.client.yaml //go:embed yaml/app.client.yaml
YAMLAppClient string YAMLAppClient string
//go:embed app.mie.api.yaml //go:embed yaml/app.mie.api.yaml
YAMLAppMieAPI string YAMLAppMieAPI string
//go:embed app.mie.worker.yaml //go:embed yaml/app.mie.worker.yaml
YAMLAppMieWorker []byte YAMLAppMieWorker []byte
//go:embed app.mie.cron.yaml //go:embed yaml/app.mie.cron.yaml
YAMLAppMieCron []byte YAMLAppMieCron []byte
//go:embed app.mie.sweeper.yaml //go:embed yaml/app.mie.sweeper.yaml
YAMLAppMieSweeper []byte YAMLAppMieSweeper []byte
//go:embed app.oem.yaml //go:embed yaml/app.oem.yaml
YAMLAppOEM string YAMLAppOEM string
//go:embed app.nginx.yaml //go:embed yaml/app.nginx.yaml
YAMLAppNGINX string YAMLAppNGINX string
//go:embed ssl/ca.crt //go:embed ssl/ca.crt

View File

@@ -1,3 +1,14 @@
apiVersion: mysql.presslabs.org/v1alpha1
kind: MysqlDatabase
metadata:
name: my-database-backup-server
namespace: db-mysql
spec:
database: backup_server
clusterRef:
name: mysql-cluster
namespace: db-mysql
---
apiVersion: apps/v1 apiVersion: apps/v1
kind: Deployment kind: Deployment
metadata: metadata: