forked from vela-ssoc/vela-kit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.go
106 lines (89 loc) · 1.94 KB
/
deploy.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package vkit
import (
"fmt"
"github.com/vela-ssoc/vela-kit/agent"
"github.com/vela-ssoc/vela-kit/env"
"github.com/vela-ssoc/vela-kit/hashmap"
"github.com/vela-ssoc/vela-kit/mime"
"github.com/vela-ssoc/vela-kit/node"
"github.com/vela-ssoc/vela-kit/plugin"
"github.com/vela-ssoc/vela-kit/shared"
"github.com/vela-ssoc/vela-kit/tasktree"
"github.com/vela-ssoc/vela-kit/thread"
"github.com/vela-ssoc/vela-kit/vela"
"os"
)
type Deploy struct {
name string
all bool
use func(env vela.Environment)
doc string
}
type EngineFunc func(*Deploy)
func All() EngineFunc {
return func(e *Deploy) {
e.all = true
}
}
func Doc(doc string) EngineFunc {
return func(dly *Deploy) {
dly.doc = doc
}
}
func Use(fn func(vela.Environment)) EngineFunc {
return func(e *Deploy) {
e.use = fn
}
}
func New(name string, options ...EngineFunc) *Deploy {
e := &Deploy{name: name}
for _, fn := range options {
fn(e)
}
return e
}
func (dly *Deploy) with(xEnv vela.Environment) {
if dly.use == nil {
return
}
dly.use(xEnv)
}
func (dly *Deploy) base(xEnv vela.Environment) {
mime.Constructor(xEnv)
tasktree.Constructor(xEnv)
plugin.Constructor(xEnv)
node.Constructor(xEnv)
shared.Constructor(xEnv)
hashmap.Constructor(xEnv)
thread.Constructor(xEnv)
}
func (dly *Deploy) define() func(vela.Environment) {
return func(xEnv vela.Environment) {
//default inject module
vela.WithEnv(xEnv)
//base
dly.base(xEnv)
//all
dly.withAll(xEnv)
//custom injection
dly.with(xEnv)
}
}
func (dly *Deploy) Agent() {
if os.Args[1] == "version" {
fmt.Println(dly.doc)
return
}
agent.By(dly.name, dly.define())
}
func (dly *Deploy) Debug(hide Hide) {
xEnv := env.Create("debug", dly.name, hide.Protect)
dly.define()(xEnv)
xEnv.Error("ssc sensor debug start")
xEnv.Spawn(0, func() {
xEnv.Dev(hide.Lan[0], hide.Vip[0], hide.Edition, hide.Hostname)
})
xEnv.Error("ssc sensor debug succeed")
xEnv.Notify()
xEnv.Error("ssc sensor exit succeed")
}