-
Notifications
You must be signed in to change notification settings - Fork 1
/
hx.go
64 lines (50 loc) · 1.51 KB
/
hx.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package cmd
import (
"os"
"github.com/bryant-rh/cm/cmd/client/cmd/hx"
"github.com/bryant-rh/cm/cmd/client/global"
"github.com/bryant-rh/cm/pkg/hxctx"
"github.com/spf13/cobra"
)
var ctx = &hxctx.Context{}
var aliases = map[string]string{
"CI_SERVER_HOST": "GITLAB_HOST",
"CI_JOB_TOKEN": "GITLAB_CI_TOKEN",
}
func NewCmdHx() *cobra.Command {
hxCmd := &cobra.Command{
Use: "hx",
//Version: version.Version,
Short: "用于初始化项目,部署服务",
PersistentPreRun: func(cmd *cobra.Command, args []string) {
if global.ImagePullSecret == "" {
global.ImagePullSecret = "sensorsdata-registry://harbor.example.com/"
}
ctx.Init()
},
}
for k, alias := range aliases {
if v, ok := os.LookupEnv(k); ok {
_ = os.Setenv(alias, v)
}
}
if ref := os.Getenv("CI_COMMIT_SHA"); ref != "" && len(ref) > 7 {
_ = os.Setenv("COMMIT_SHA", ref[0:7])
}
flags := hxCmd.PersistentFlags()
flags.StringVarP(&ctx.Workspace, "workspace", "W", "", "workspace")
flags.StringVarP(&ctx.DeployEnv, "env", "", os.Getenv("CI_ENVIRONMENT_NAME"), "deploy env")
flags.StringVarP(&ctx.Feature, "feature", "", os.Getenv("PROJECT_FEATURE"), "project feature")
workingDir := os.Getenv("WORKING_DIR")
if workingDir != "" {
if err := os.Chdir(workingDir); err != nil {
panic(err)
}
}
hxCmd.AddCommand(hx.NewCmdHxBuildXCISetup())
hxCmd.AddCommand(hx.NewCmdHxBuildX(ctx))
hxCmd.AddCommand(hx.NewCmdHxInit(ctx))
hxCmd.AddCommand(hx.NewCmdHxConfig(ctx))
hxCmd.AddCommand(hx.NewCmdHxApply(ctx))
return hxCmd
}