forked from harness/gitness
/
node_root.go
148 lines (130 loc) · 2.82 KB
/
node_root.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
package parse
// RootNode is the root node in the parsed Yaml file.
type RootNode struct {
NodeType
Platform string
Base string
Path string
Image string
Pod Node
Build Node
Cache Node
Clone Node
Script []Node
Volumes []Node
Networks []Node
Services []Node
}
// NewRootNode returns a new root node.
func NewRootNode() *RootNode {
return &RootNode{
NodeType: NodeRoot,
}
}
// Root returns the root node.
func (n *RootNode) Root() *RootNode { return n }
// Returns a new Volume Node.
func (n *RootNode) NewVolumeNode(name string) *VolumeNode {
return &VolumeNode{
NodeType: NodeVolume,
Name: name,
root: n,
}
}
// Returns a new Network Node.
func (n *RootNode) NewNetworkNode(name string) *NetworkNode {
return &NetworkNode{
NodeType: NodeNetwork,
Name: name,
root: n,
}
}
// Returns a new Network Node.
func (n *RootNode) NewBuildNode(context string) *BuildNode {
return &BuildNode{
NodeType: NodeBuild,
Context: context,
root: n,
}
}
// Returns a new Container Plugin Node.
func (n *RootNode) NewPluginNode() *ContainerNode {
return &ContainerNode{
NodeType: NodePlugin,
root: n,
}
}
// Returns a new Container Shell Node.
func (n *RootNode) NewShellNode() *ContainerNode {
return &ContainerNode{
NodeType: NodeShell,
root: n,
}
}
// Returns a new Container Service Node.
func (n *RootNode) NewServiceNode() *ContainerNode {
return &ContainerNode{
NodeType: NodeService,
root: n,
}
}
// Returns a new Container Clone Node.
func (n *RootNode) NewCloneNode() *ContainerNode {
return &ContainerNode{
NodeType: NodeClone,
root: n,
}
}
// Returns a new Container Cache Node.
func (n *RootNode) NewCacheNode() *ContainerNode {
return &ContainerNode{
NodeType: NodeCache,
root: n,
}
}
// Returns a new Container Node.
func (n *RootNode) NewContainerNode() *ContainerNode {
return &ContainerNode{
NodeType: NodeContainer,
root: n,
}
}
// Walk is a function that walk through all child nodes of the RootNode
// and invokes the Walk callback function for each Node.
func (n *RootNode) Walk(fn WalkFunc) (err error) {
var nodes []Node
nodes = append(nodes, n)
nodes = append(nodes, n.Build)
nodes = append(nodes, n.Cache)
nodes = append(nodes, n.Clone)
nodes = append(nodes, n.Script...)
nodes = append(nodes, n.Volumes...)
nodes = append(nodes, n.Networks...)
nodes = append(nodes, n.Services...)
for _, node := range nodes {
err = fn(node)
if err != nil {
return
}
}
return
}
type WalkFunc func(Node) error
//
// intermediate types for yaml decoding.
//
type root struct {
Workspace struct {
Path string
Base string
}
Image string
Platform string
Volumes volumeList
Networks networkList
Services containerList
Script containerList
Cache container
Clone container
Build build
}