mirror of
https://github.com/hanzoai/deploy.git
synced 2026-10-07 08:44:50 +00:00
go.mod still declared `module github.com/hanzoai/deploy` after the repo was renamed. A Go module path is not cosmetic — it is the resolvable location. So `go get github.com/hanzoai/cd` could not work, and anything importing this module had to spell a name that no longer exists at that address. The build log of v3.6.0 is where it surfaced: the compiler was still emitting github.com/hanzoai/deploy/cmd/cd/commands. 3541 import paths across 690 .go, 19 .proto, 4 .yaml, 3 .sh, 2 .mod, Procfile and Makefile. Plus the 62 ghcr.io/hanzoai/deploy image references, moved to ghcr.io/hanzoai/cd to match hanzo.yml's build target — a distinct string from the module path, replaced separately so neither could clobber the other. go mod tidy clean, CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build ./... clean. Co-authored-by: Hanzo Dev <[email protected]>
132 lines
3.7 KiB
Go
132 lines
3.7 KiB
Go
package commands
|
|
|
|
import (
|
|
"context"
|
|
"log"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
generator "github.com/hanzoai/cd/hack/gen-resources/generators"
|
|
"github.com/hanzoai/cd/util/db"
|
|
"github.com/hanzoai/cd/util/settings"
|
|
|
|
cmdutil "github.com/hanzoai/cd/cmd/util"
|
|
"github.com/hanzoai/cd/hack/gen-resources/util"
|
|
"github.com/hanzoai/cd/util/cli"
|
|
)
|
|
|
|
const (
|
|
cliName = "cd-generator"
|
|
)
|
|
|
|
func init() {
|
|
cobra.OnInitialize(initConfig)
|
|
}
|
|
|
|
func initConfig() {
|
|
cli.SetLogFormat(cmdutil.LogFormat)
|
|
cli.SetLogLevel(cmdutil.LogLevel)
|
|
}
|
|
|
|
// NewCommand returns a new instance of an cd command
|
|
func NewCommand() *cobra.Command {
|
|
var generateOpts util.GenerateOpts
|
|
|
|
command := &cobra.Command{
|
|
Use: cliName,
|
|
Short: "Generator for cd resources",
|
|
Run: func(c *cobra.Command, args []string) {
|
|
c.HelpFunc()(c, args)
|
|
},
|
|
DisableAutoGenTag: true,
|
|
}
|
|
|
|
command.AddCommand(NewGenerateCommand(&generateOpts))
|
|
command.AddCommand(NewCleanCommand(&generateOpts))
|
|
|
|
return command
|
|
}
|
|
|
|
func NewGenerateCommand(opts *util.GenerateOpts) *cobra.Command {
|
|
var file string
|
|
command := &cobra.Command{
|
|
Use: "generate [-f file]",
|
|
Short: "Generate entities",
|
|
Long: "Generate entities",
|
|
Run: func(_ *cobra.Command, _ []string) {
|
|
log.Printf("Retrieve configuration from %s", file)
|
|
err := util.Parse(opts, file)
|
|
if err != nil {
|
|
log.Fatalf("Failed to retrieve configuration, %v", err.Error())
|
|
}
|
|
argoClientSet := util.ConnectToK8sArgoClientSet()
|
|
clientSet := util.ConnectToK8sClientSet()
|
|
|
|
settingsMgr := settings.NewSettingsManager(context.TODO(), clientSet, opts.Namespace)
|
|
argoDB := db.NewDB(opts.Namespace, settingsMgr, clientSet)
|
|
|
|
pg := generator.NewProjectGenerator(argoClientSet)
|
|
ag := generator.NewApplicationGenerator(argoClientSet, clientSet)
|
|
rg := generator.NewRepoGenerator(util.ConnectToK8sClientSet())
|
|
cg := generator.NewClusterGenerator(argoDB, util.ConnectToK8sClientSet(), util.ConnectToK8sConfig())
|
|
|
|
err = pg.Generate(opts)
|
|
if err != nil {
|
|
log.Fatalf("Failed to generate projects, %v", err.Error())
|
|
}
|
|
err = rg.Generate(opts)
|
|
if err != nil {
|
|
log.Fatalf("Failed to generate repositories, %v", err.Error())
|
|
}
|
|
err = cg.Generate(opts)
|
|
if err != nil {
|
|
log.Fatalf("Failed to generate clusters, %v", err.Error())
|
|
}
|
|
err = ag.Generate(opts)
|
|
if err != nil {
|
|
log.Fatalf("Failed to generate applications, %v", err.Error())
|
|
}
|
|
},
|
|
}
|
|
command.Flags().StringVarP(&file, "file", "f", "", "")
|
|
return command
|
|
}
|
|
|
|
func NewCleanCommand(opts *util.GenerateOpts) *cobra.Command {
|
|
command := &cobra.Command{
|
|
Use: "clean",
|
|
Short: "Clean entities",
|
|
Long: "Clean entities",
|
|
Run: func(_ *cobra.Command, _ []string) {
|
|
argoClientSet := util.ConnectToK8sArgoClientSet()
|
|
clientSet := util.ConnectToK8sClientSet()
|
|
settingsMgr := settings.NewSettingsManager(context.TODO(), clientSet, opts.Namespace)
|
|
argoDB := db.NewDB(opts.Namespace, settingsMgr, clientSet)
|
|
|
|
pg := generator.NewProjectGenerator(argoClientSet)
|
|
ag := generator.NewApplicationGenerator(argoClientSet, clientSet)
|
|
cg := generator.NewClusterGenerator(argoDB, clientSet, util.ConnectToK8sConfig())
|
|
rg := generator.NewRepoGenerator(clientSet)
|
|
|
|
err := pg.Clean(opts)
|
|
if err != nil {
|
|
log.Fatalf("Failed to clean projects, %v", err.Error())
|
|
}
|
|
err = ag.Clean(opts)
|
|
if err != nil {
|
|
log.Fatalf("Failed to clean applications, %v", err.Error())
|
|
}
|
|
err = cg.Clean(opts)
|
|
if err != nil {
|
|
log.Fatalf("Failed to clean clusters, %v", err.Error())
|
|
}
|
|
err = rg.Clean(opts)
|
|
if err != nil {
|
|
log.Fatalf("Failed to clean repositores, %v", err.Error())
|
|
}
|
|
},
|
|
}
|
|
command.PersistentFlags().StringVar(&opts.Namespace, "kube-namespace", "cd", "Name of the namespace where cd is running [$KUBE_NAMESPACE]")
|
|
return command
|
|
}
|